forked from I2P_Developers/i2p.i2p
OSX Launcher: String extensions update
This commit is contained in:
@ -31,5 +31,44 @@ extension String {
|
||||
public func splitByColon() -> [String] {
|
||||
return self.split { $0 == ":" }.map(String.init)
|
||||
}
|
||||
|
||||
func leftPadding(toLength: Int, withPad character: Character) -> String {
|
||||
let stringLength = self.count
|
||||
if stringLength < toLength {
|
||||
return String(repeatElement(character, count: toLength - stringLength)) + self
|
||||
} else {
|
||||
return String(self.suffix(toLength))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
extension String {
|
||||
subscript (i: Int) -> Character {
|
||||
return self[index(startIndex, offsetBy: i)]
|
||||
}
|
||||
subscript (bounds: CountableRange<Int>) -> Substring {
|
||||
let start = index(startIndex, offsetBy: bounds.lowerBound)
|
||||
let end = index(startIndex, offsetBy: bounds.upperBound)
|
||||
return self[start ..< end]
|
||||
}
|
||||
subscript (bounds: CountableClosedRange<Int>) -> Substring {
|
||||
let start = index(startIndex, offsetBy: bounds.lowerBound)
|
||||
let end = index(startIndex, offsetBy: bounds.upperBound)
|
||||
return self[start ... end]
|
||||
}
|
||||
subscript (bounds: CountablePartialRangeFrom<Int>) -> Substring {
|
||||
let start = index(startIndex, offsetBy: bounds.lowerBound)
|
||||
let end = index(endIndex, offsetBy: -1)
|
||||
return self[start ... end]
|
||||
}
|
||||
subscript (bounds: PartialRangeThrough<Int>) -> Substring {
|
||||
let end = index(startIndex, offsetBy: bounds.upperBound)
|
||||
return self[startIndex ... end]
|
||||
}
|
||||
subscript (bounds: PartialRangeUpTo<Int>) -> Substring {
|
||||
let end = index(startIndex, offsetBy: bounds.upperBound)
|
||||
return self[startIndex ..< end]
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user