diff options
| author | Ruben Beltran del Rio <jj@r.bdr.sh> | 2025-12-14 16:16:22 +0100 |
|---|---|---|
| committer | Ruben Beltran del Rio <jj@r.bdr.sh> | 2025-12-14 16:40:52 +0100 |
| commit | 0b90075f76b6f2df77c01c303322323b1395641a (patch) | |
| tree | 4e13d3ce0b1f4792eab8d04caefda2218565f5a9 /Sources/WmapParser/DependencyParser.swift | |
| parent | 088a941a72c2f3e9b3382eb9c5d2f21203dd401c (diff) | |
Use WmapParser namespace
Diffstat (limited to 'Sources/WmapParser/DependencyParser.swift')
| -rw-r--r-- | Sources/WmapParser/DependencyParser.swift | 88 |
1 files changed, 45 insertions, 43 deletions
diff --git a/Sources/WmapParser/DependencyParser.swift b/Sources/WmapParser/DependencyParser.swift index 9964d5a..891be01 100644 --- a/Sources/WmapParser/DependencyParser.swift +++ b/Sources/WmapParser/DependencyParser.swift @@ -1,50 +1,52 @@ -/// Looks for -- or ->. If found, returns where this arrow starts. -@inline(__always) -func hasDependency<T: Collection>(_ bytes: T, _ start: Int, _ end: Int) -> Int? -where T.Element == UInt8, T.Index == Int { - var index = start - while index < end { - if bytes[index] == kOpenParenthesis { return nil } - if bytes[index] == kDash && index + 1 < end { - let next = bytes[index + 1] - if next == kGreaterThan || next == kDash { return index } +extension WmapParser { + /// Looks for -- or ->. If found, returns where this arrow starts. + @inline(__always) + static func hasDependency<T: Collection>(_ bytes: T, _ start: Int, _ end: Int) -> Int? + where T.Element == UInt8, T.Index == Int { + var index = start + while index < end { + if bytes[index] == kOpenParenthesis { return nil } + if bytes[index] == kDash && index + 1 < end { + let next = bytes[index + 1] + if next == kGreaterThan || next == kDash { return index } + } + index += 1 + } + return nil } - index += 1 - } - return nil -} -/// Finds a dependency and whether it's directed. It assumes we previously -/// checked for the location of our separator to speed things up. -func parseDependency<T: Collection>(_ bytes: T, _ start: Int, _ end: Int, _ separatorIndex: Int) - -> Dependency? -where T.Element == UInt8, T.Index == Int { - guard let isDirected = extractIsDirected(bytes, separatorIndex, end) else { - return nil - } + /// Finds a dependency and whether it's directed. It assumes we previously + /// checked for the location of our separator to speed things up. + static func parseDependency<T: Collection>(_ bytes: T, _ start: Int, _ end: Int, _ separatorIndex: Int) + -> Dependency? + where T.Element == UInt8, T.Index == Int { + guard let isDirected = extractIsDirected(bytes, separatorIndex, end) else { + return nil + } - guard let fromComponent = extractTrimmedString(bytes, start, separatorIndex) else { - return nil - } + guard let fromComponent = extractTrimmedString(bytes, start, separatorIndex) else { + return nil + } - guard let toComponent = extractTrimmedString(bytes, separatorIndex + 2, end) else { - return nil - } + guard let toComponent = extractTrimmedString(bytes, separatorIndex + 2, end) else { + return nil + } - return Dependency(fromComponent: fromComponent, toComponent: toComponent, isDirected: isDirected) -} + return Dependency(fromComponent: fromComponent, toComponent: toComponent, isDirected: isDirected) + } -/// Checks the second character of the separator to see if it's directed. -/// It assumes we already checked for -- or ->, so it only checks for -/// Whether it's greaterThan or not. -@inline(__always) -private func extractIsDirected<T: Collection>(_ bytes: T, _ separatorIndex: Int, _ end: Int) - -> Bool? -where T.Element == UInt8, T.Index == Int { - let followingCharacter = separatorIndex + 1 - guard followingCharacter < end else { return nil } - if bytes[followingCharacter] == kGreaterThan { - return true - } - return false + /// Checks the second character of the separator to see if it's directed. + /// It assumes we already checked for -- or ->, so it only checks for + /// Whether it's greaterThan or not. + @inline(__always) + private static func extractIsDirected<T: Collection>(_ bytes: T, _ separatorIndex: Int, _ end: Int) + -> Bool? + where T.Element == UInt8, T.Index == Int { + let followingCharacter = separatorIndex + 1 + guard followingCharacter < end else { return nil } + if bytes[followingCharacter] == kGreaterThan { + return true + } + return false + } } |