Skip to content

Commit

Permalink
Update String+Extension.swift
Browse files Browse the repository at this point in the history
pharms-eth committed Mar 6, 2023
1 parent 4108edd commit 0847410
Showing 1 changed file with 0 additions and 20 deletions.
20 changes: 0 additions & 20 deletions Sources/Web3Core/Utility/String+Extension.swift
Original file line number Diff line number Diff line change
@@ -32,26 +32,6 @@ extension String {
return output
}

/// Splits a string into groups of `every` n characters, grouping from left-to-right by default. If `backwards` is true, right-to-left.
public func split(every: Int, backwards: Bool = false) -> [String] {
var result = [String]()

for i in stride(from: 0, to: self.count, by: every) {
switch backwards {
case true:
let endIndex = self.index(self.endIndex, offsetBy: -i)
let startIndex = self.index(endIndex, offsetBy: -every, limitedBy: self.startIndex) ?? self.startIndex
result.insert(String(self[startIndex..<endIndex]), at: 0)
case false:
let startIndex = self.index(self.startIndex, offsetBy: i)
let endIndex = self.index(startIndex, offsetBy: every, limitedBy: self.endIndex) ?? self.endIndex
result.append(String(self[startIndex..<endIndex]))
}
}

return result
}

public subscript (bounds: CountableClosedRange<Int>) -> String {
let start = index(self.startIndex, offsetBy: bounds.lowerBound)
let end = index(self.startIndex, offsetBy: bounds.upperBound)

0 comments on commit 0847410

Please sign in to comment.