Skip to content
This repository was archived by the owner on Dec 29, 2018. It is now read-only.
Merged
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
10 changes: 6 additions & 4 deletions CommandLine/CommandLine.swift
Original file line number Diff line number Diff line change
Expand Up @@ -155,13 +155,15 @@ public class CommandLine {
/* Swift strings don't have substringFromIndex(). Do a little dance instead. */
var flag = ""
var skipChars =
arg.hasPrefix(LongOptionPrefix) ? countElements(LongOptionPrefix) : countElements(ShortOptionPrefix)
arg.hasPrefix(LongOptionPrefix) ? count(LongOptionPrefix) : count(ShortOptionPrefix)
for c in arg {
if skipChars-- > 0 {
continue
}

flag.append(c)
// Swift 1.2: String.append() doesn't like emoji for some reason, seems
// like a bug. Same workaround in String extension splitByCharacter()
flag = flag + String(c)
}

/* Remove attached argument from flag */
Expand All @@ -183,7 +185,7 @@ public class CommandLine {
/* Flags that do not take any arguments can be concatenated */
if !flagMatched && !arg.hasPrefix(LongOptionPrefix) {
for (i, c) in enumerate(flag) {
var flagLength = countElements(flag)
var flagLength = count(flag)
for option in _options {
if String(c) == option.shortFlag {
/* Values are allowed at the end of the concatenated flags, e.g.
Expand Down Expand Up @@ -218,7 +220,7 @@ public class CommandLine {
var flagWidth = 0
for opt in _options {
flagWidth = max(flagWidth,
countElements(" \(ShortOptionPrefix)\(opt.shortFlag), \(LongOptionPrefix)\(opt.longFlag):"))
count(" \(ShortOptionPrefix)\(opt.shortFlag), \(LongOptionPrefix)\(opt.longFlag):"))
}

println("Usage: \(name) [options]")
Expand Down
2 changes: 1 addition & 1 deletion CommandLine/Option.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public class Option {
}

public init(shortFlag: String, longFlag: String, required: Bool, helpMessage: String) {
assert(countElements(shortFlag) == 1, "Short flag must be a single character")
assert(count(shortFlag) == 1, "Short flag must be a single character")
assert(shortFlag.toInt() == nil && shortFlag.toDouble() == nil, "Short flag cannot be a numeric value")
assert(longFlag.toInt() == nil && longFlag.toDouble() == nil, "Long flag cannot be a numeric value")

Expand Down
10 changes: 5 additions & 5 deletions CommandLine/StringExtensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ internal extension String {
}

return (Double(characteristic.toInt()!) +
Double(mantissa.toInt()!) / pow(Double(10), Double(countElements(mantissa) - 1))) *
Double(mantissa.toInt()!) / pow(Double(10), Double(count(mantissa) - 1))) *
(isNegative ? -1 : 1)
}

Expand All @@ -95,10 +95,10 @@ internal extension String {
continue
}

buf.append(c)
buf = buf + String(c)
}

if countElements(buf) > 0 {
if count(buf) > 0 {
s.append(buf)
}

Expand All @@ -115,7 +115,7 @@ internal extension String {
*/
func paddedToWidth(width: Int, padBy: Character = " ") -> String {
var s = self
var currentLength = countElements(self)
var currentLength = count(self)

while currentLength++ < width {
s.append(padBy)
Expand All @@ -142,7 +142,7 @@ internal extension String {
var currentLineWidth = 0

for word in self.splitByCharacter(splitBy) {
let wordLength = countElements(word)
let wordLength = count(word)

if currentLineWidth + wordLength + 1 > width {
/* Word length is greater than line length, can't wrap */
Expand Down
10 changes: 5 additions & 5 deletions CommandLineTests/StringExtensionTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,9 @@ class StringExtensionTests: XCTestCase {
func testPaddedByCharacter() {
let a = "this is a test"

XCTAssertEqual(countElements(a.paddedToWidth(80)), 80, "Failed to pad to correct width")
XCTAssertEqual(countElements(a.paddedToWidth(5)), countElements(a), "Bad padding when pad width is less than string width")
XCTAssertEqual(countElements(a.paddedToWidth(-2)), countElements(a), "Bad padding with negative pad width")
XCTAssertEqual(count(a.paddedToWidth(80)), 80, "Failed to pad to correct width")
XCTAssertEqual(count(a.paddedToWidth(5)), count(a), "Bad padding when pad width is less than string width")
XCTAssertEqual(count(a.paddedToWidth(-2)), count(a), "Bad padding with negative pad width")

let b = a.paddedToWidth(80)
let lastBCharIndex = advance(b.endIndex, -1)
Expand All @@ -118,15 +118,15 @@ class StringExtensionTests: XCTestCase {
func testWrappedAtWidth() {
let lipsum = "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua."
for line in lipsum.wrappedAtWidth(80).splitByCharacter("\n") {
XCTAssertLessThanOrEqual(countElements(line), 80, "Failed to wrap long line: \(line)")
XCTAssertLessThanOrEqual(count(line), 80, "Failed to wrap long line: \(line)")
}

/* Words longer than the wrap width should not be split */
let longWords = "Lorem ipsum consectetur adipisicing eiusmod tempor incididunt"
let lines = longWords.wrappedAtWidth(3).splitByCharacter("\n")
XCTAssertEqual(lines.count, 8, "Failed to wrap long words")
for line in lines {
XCTAssertGreaterThan(countElements(line), 3, "Bad long word wrapping on line: \(line)")
XCTAssertGreaterThan(count(line), 3, "Bad long word wrapping on line: \(line)")
}
}
}