diff options
| author | Ruben Beltran del Rio <jj@r.bdr.sh> | 2025-12-15 11:30:47 +0100 |
|---|---|---|
| committer | Ruben Beltran del Rio <jj@r.bdr.sh> | 2025-12-15 11:51:49 +0100 |
| commit | fabd59b7d1540900bd64590646c73c917706ecd8 (patch) | |
| tree | 6e4e6e56aea797917f0613ed135f4fd1c834a674 | |
| parent | 969b6a6653699b9f8662feb7f42511740f96f84a (diff) | |
| -rw-r--r-- | Makefile | 3 | ||||
| -rw-r--r-- | Sources/WmapParser/ComponentParser.swift | 3 | ||||
| -rw-r--r-- | Sources/WmapParser/DependencyParser.swift | 8 | ||||
| -rw-r--r-- | Sources/WmapParser/Utils.swift | 3 | ||||
| -rw-r--r-- | Tests/WmapParserTests/WmapParserTests.swift | 7 |
5 files changed, 16 insertions, 8 deletions
@@ -16,7 +16,8 @@ coverage: swift test --enable-code-coverage xcrun llvm-cov report \ .build/debug/WmapParserPackageTests.xctest/Contents/MacOS/WmapParserPackageTests \ - -instr-profile=.build/debug/codecov/default.profdata + -instr-profile=.build/debug/codecov/default.profdata \ + --ignore-filename-regex='\.build' benchmark: swift package benchmark --target ParseBenchmarkTarget diff --git a/Sources/WmapParser/ComponentParser.swift b/Sources/WmapParser/ComponentParser.swift index 79f5493..d87abc5 100644 --- a/Sources/WmapParser/ComponentParser.swift +++ b/Sources/WmapParser/ComponentParser.swift @@ -1,6 +1,7 @@ extension WmapParser { - /// Parses a component with its coordinates. + /// Parses a component with its coordinates. Assumes a trimmed line was + /// provided. static func parseComponent<T: Collection>(_ bytes: T, _ start: Int, _ end: Int) -> Component? where T.Element == UInt8, T.Index == Int { guard let (label, parenthesisIndex) = extractComponentLabel(bytes, start, end) else { diff --git a/Sources/WmapParser/DependencyParser.swift b/Sources/WmapParser/DependencyParser.swift index 2567bfe..45408d5 100644 --- a/Sources/WmapParser/DependencyParser.swift +++ b/Sources/WmapParser/DependencyParser.swift @@ -22,9 +22,7 @@ extension WmapParser { ) -> Dependency? where T.Element == UInt8, T.Index == Int { - guard let isDirected = extractIsDirected(bytes, separatorIndex, end) else { - return nil - } + let isDirected = extractIsDirected(bytes, separatorIndex, end) guard let fromComponent = extractTrimmedString(bytes, start, separatorIndex) else { return nil @@ -45,10 +43,10 @@ extension WmapParser { private static func extractIsDirected<T: Collection>( _ bytes: T, _ separatorIndex: Int, _ end: Int ) - -> Bool? + -> Bool where T.Element == UInt8, T.Index == Int { let followingCharacter = separatorIndex + 1 - guard followingCharacter < end else { return nil } + guard followingCharacter < end else { return false } if bytes[followingCharacter] == kGreaterThan { return true } diff --git a/Sources/WmapParser/Utils.swift b/Sources/WmapParser/Utils.swift index 4886eb3..e88b072 100644 --- a/Sources/WmapParser/Utils.swift +++ b/Sources/WmapParser/Utils.swift @@ -96,7 +96,8 @@ extension WmapParser { return index } - /// Given the bytes buffer, finds the next non-empty line. + /// Given the bytes buffer, finds the next non-empty line without leading. + /// or trailing whitespace. @inline(__always) static func extractLine<T: Collection>(_ bytes: T, _ index: inout Int, _ length: Int) -> ( Int, Int diff --git a/Tests/WmapParserTests/WmapParserTests.swift b/Tests/WmapParserTests/WmapParserTests.swift index baf114f..1a61238 100644 --- a/Tests/WmapParserTests/WmapParserTests.swift +++ b/Tests/WmapParserTests/WmapParserTests.swift @@ -169,6 +169,13 @@ import Testing It's OK (0.8, 0.4) [ijole] NO IT ISN'T A-- + --A + not-quite + [Note] (1234) Hello + [Note] (0.1.1,1.1.1) Hello + [i] 1.2.2.3 + Hello (1.22.2, 1.3.3) + (1.1231,12.0) B-> ( Hello -> It's OK |