Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Sources/ArgumentParser/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ add_library(ArgumentParser
Parsing/ParserError.swift
Parsing/SplitArguments.swift

Usage/CommandSearcher.swift
Usage/DumpHelpGenerator.swift
Usage/HelpCommand.swift
Usage/HelpGenerator.swift
Expand All @@ -49,7 +50,7 @@ add_library(ArgumentParser
Utilities/StringExtensions.swift
Utilities/SwiftExtensions.swift
Utilities/Tree.swift

Validators/CodingKeyValidator.swift
Validators/NonsenseFlagsValidator.swift
Validators/ParsableArgumentsValidation.swift
Expand Down
68 changes: 0 additions & 68 deletions Sources/ArgumentParser/Completions/CompletionsGenerator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -152,74 +152,6 @@ extension String {
self.replacing("-", with: "_")
}

func replacing(_ old: Self, with new: Self) -> Self {
guard !old.isEmpty else { return self }

var result = ""
var startIndex = self.startIndex

// Look for occurrences of the old string.
while let matchRange = self.firstMatch(of: old, at: startIndex) {
// Add the substring before the match.
result.append(contentsOf: self[startIndex..<matchRange.start])

// Add the replacement string.
result.append(contentsOf: new)

// Move past the matched portion.
startIndex = matchRange.end
}

// No more matches found, add the rest of the string.
result.append(contentsOf: self[startIndex..<self.endIndex])

return result
}

func firstMatch(
of match: Self,
at startIndex: Self.Index
) -> (start: Self.Index, end: Self.Index)? {
guard !match.isEmpty else { return nil }
guard match.count <= self.count else { return nil }

var startIndex = startIndex
while startIndex < self.endIndex {
// Check if theres a match.
if let endIndex = self.matches(match, at: startIndex) {
// Return the match.
return (startIndex, endIndex)
}

// Move to the next of index.
self.formIndex(after: &startIndex)
}

return nil
}

func matches(
_ match: Self,
at startIndex: Self.Index
) -> Self.Index? {
var selfIndex = startIndex
var matchIndex = match.startIndex

while true {
// Only continue checking if there is more match to check
guard matchIndex < match.endIndex else { return selfIndex }

// Exit early if there is no more "self" to check.
guard selfIndex < self.endIndex else { return nil }

// Check match and self are the the same.
guard self[selfIndex] == match[matchIndex] else { return nil }

// Move to the next pair of indices.
self.formIndex(after: &selfIndex)
match.formIndex(after: &matchIndex)
}
}
}

extension CommandInfoV0 {
Expand Down
Loading