Changeset 969bc2d for launchers/macosx


Ignore:
Timestamp:
Oct 11, 2018 4:48:10 PM (21 months ago)
Author:
meeh <meeh@…>
Branches:
master
Children:
8b2c3de7
Parents:
7dbf568
Message:

OSX Launcher: String extensions update

File:
1 edited

Legend:

Unmodified
Added
Removed
  • launchers/macosx/I2PLauncher/Utils/StringExtensions.swift

    r7dbf568 r969bc2d  
    3232    return self.split { $0 == ":" }.map(String.init)
    3333  }
     34 
     35  func leftPadding(toLength: Int, withPad character: Character) -> String {
     36    let stringLength = self.count
     37    if stringLength < toLength {
     38      return String(repeatElement(character, count: toLength - stringLength)) + self
     39    } else {
     40      return String(self.suffix(toLength))
     41    }
     42  }
    3443}
    3544
     45
     46extension String {
     47  subscript (i: Int) -> Character {
     48    return self[index(startIndex, offsetBy: i)]
     49  }
     50  subscript (bounds: CountableRange<Int>) -> Substring {
     51    let start = index(startIndex, offsetBy: bounds.lowerBound)
     52    let end = index(startIndex, offsetBy: bounds.upperBound)
     53    return self[start ..< end]
     54  }
     55  subscript (bounds: CountableClosedRange<Int>) -> Substring {
     56    let start = index(startIndex, offsetBy: bounds.lowerBound)
     57    let end = index(startIndex, offsetBy: bounds.upperBound)
     58    return self[start ... end]
     59  }
     60  subscript (bounds: CountablePartialRangeFrom<Int>) -> Substring {
     61    let start = index(startIndex, offsetBy: bounds.lowerBound)
     62    let end = index(endIndex, offsetBy: -1)
     63    return self[start ... end]
     64  }
     65  subscript (bounds: PartialRangeThrough<Int>) -> Substring {
     66    let end = index(startIndex, offsetBy: bounds.upperBound)
     67    return self[startIndex ... end]
     68  }
     69  subscript (bounds: PartialRangeUpTo<Int>) -> Substring {
     70    let end = index(startIndex, offsetBy: bounds.upperBound)
     71    return self[startIndex ..< end]
     72  }
     73}
     74
Note: See TracChangeset for help on using the changeset viewer.