Skip to content

Commit

Permalink
[Scanner] Rename atEnd to isAtEnd to match the Darwin version
Browse files Browse the repository at this point in the history
  • Loading branch information
ikesyo committed May 21, 2017
1 parent 2e50a38 commit 0e658a5
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion Foundation/NSGeometry.swift
Original file line number Diff line number Diff line change
Expand Up @@ -708,7 +708,7 @@ private func _scanDoublesFromString(_ aString: String, number: Int) -> [Double]
var index = 0

let _ = scanner.scanUpToCharactersFromSet(digitSet)
while !scanner.atEnd && index < number {
while !scanner.isAtEnd && index < number {
if let num = scanner.scanDouble() {
result[index] = num
}
Expand Down
6 changes: 3 additions & 3 deletions Foundation/NSRange.swift
Original file line number Diff line number Diff line change
Expand Up @@ -181,20 +181,20 @@ public func NSRangeFromString(_ aString: String) -> NSRange {
let scanner = Scanner(string: aString)
let digitSet = CharacterSet.decimalDigits
let _ = scanner.scanUpToCharactersFromSet(digitSet)
if scanner.atEnd {
if scanner.isAtEnd {
// fail early if there are no decimal digits
return emptyRange
}
guard let location = scanner.scanInteger() else {
return emptyRange
}
let partialRange = NSMakeRange(location, 0)
if scanner.atEnd {
if scanner.isAtEnd {
// return early if there are no more characters after the first int in the string
return partialRange
}
let _ = scanner.scanUpToCharactersFromSet(digitSet)
if scanner.atEnd {
if scanner.isAtEnd {
// return early if there are no integer characters after the first int in the string
return partialRange
}
Expand Down
2 changes: 1 addition & 1 deletion Foundation/NSScanner.swift
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,7 @@ extension Scanner {
}
}

public var atEnd: Bool {
public var isAtEnd: Bool {
var stringLoc = scanLocation
let stringLen = string.length
if let invSet = invertedSkipSet {
Expand Down
8 changes: 4 additions & 4 deletions TestFoundation/TestNSScanner.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class TestNSScanner : XCTestCase {
var value: Int = 0
XCTAssert(scanner.scanInteger(&value), "An Integer should be found in the string `123`.")
XCTAssertEqual(value, 123, "Scanned Integer value of the string `123` should be `123`.")
XCTAssertTrue(scanner.atEnd)
XCTAssertTrue(scanner.isAtEnd)
}

func test_scanFloat() {
Expand All @@ -54,17 +54,17 @@ class TestNSScanner : XCTestCase {
}

XCTAssertEqual(firstPart, "apple ")
XCTAssertFalse(scanner.atEnd)
XCTAssertFalse(scanner.isAtEnd)

let _ = scanner.scanString(string: "sauce")
XCTAssertTrue(scanner.atEnd)
XCTAssertTrue(scanner.isAtEnd)
}

func test_charactersToBeSkipped() {
let scanner = Scanner(string: "xyz ")
scanner.charactersToBeSkipped = .whitespaces

let _ = scanner.scanString(string: "xyz")
XCTAssertTrue(scanner.atEnd)
XCTAssertTrue(scanner.isAtEnd)
}
}

0 comments on commit 0e658a5

Please sign in to comment.