Merge pull request #51 from jpsim/jp-xcode-9b5

Update for Xcode 9 beta 5
This commit is contained in:
JP Simard 2017-08-10 14:21:25 -07:00 committed by GitHub
commit 351cb7a36b
5 changed files with 40 additions and 4 deletions

View File

@ -87,7 +87,7 @@ matrix:
- docker run -v `pwd`:`pwd` -w `pwd` --rm $DOCKER_IMAGE swift test -Xswiftc -DUSE_UTF8
env:
- JOB=Docker
- DOCKER_IMAGE=norionomura/swift:4020170725a
- DOCKER_IMAGE=norionomura/swift:4020170804a
sudo: required
services: docker
notifications:

View File

@ -120,7 +120,11 @@ extension Date: ScalarConstructible {
if length < 9 {
nanosecond = Int($0 + String(repeating: "0", count: 9 - length))
} else {
#if swift(>=4.0)
nanosecond = Int($0[...$0.index($0.startIndex, offsetBy: 9)])
#else
nanosecond = Int($0.substring(to: $0.index($0.startIndex, offsetBy: 9)))
#endif
}
return nanosecond
}
@ -186,19 +190,35 @@ extension Int: ScalarConstructible {
return 0
}
if scalar.hasPrefix("0x") {
#if swift(>=4.0)
let hexadecimal = scalar[scalar.index(scalar.startIndex, offsetBy: 2)...]
#else
let hexadecimal = scalar.substring(from: scalar.index(scalar.startIndex, offsetBy: 2))
#endif
return Int(hexadecimal, radix: 16)
}
if scalar.hasPrefix("0b") {
#if swift(>=4.0)
let octal = scalar[scalar.index(scalar.startIndex, offsetBy: 2)...]
#else
let octal = scalar.substring(from: scalar.index(scalar.startIndex, offsetBy: 2))
#endif
return Int(octal, radix: 2)
}
if scalar.hasPrefix("0o") {
#if swift(>=4.0)
let octal = scalar[scalar.index(scalar.startIndex, offsetBy: 2)...]
#else
let octal = scalar.substring(from: scalar.index(scalar.startIndex, offsetBy: 2))
#endif
return Int(octal, radix: 8)
}
if scalar.hasPrefix("0") {
#if swift(>=4.0)
let octal = scalar[scalar.index(after: scalar.startIndex)...]
#else
let octal = scalar.substring(from: scalar.index(after: scalar.startIndex))
#endif
return Int(octal, radix: 8)
}
if scalar.contains(":") {
@ -340,7 +360,11 @@ fileprivate extension String {
let upperBound = utf16upperBound.samePosition(in: self) else {
fatalError("unreachable")
}
#if swift(>=4.0)
return String(self[lowerBound..<upperBound])
#else
return substring(with: lowerBound..<upperBound)
#endif
}
}
@ -373,9 +397,17 @@ fileprivate extension String {
var sign: T = 1
if scalar.hasPrefix("-") {
sign = -1
#if swift(>=4.0)
scalar = String(scalar[scalar.index(after: scalar.startIndex)...])
#else
scalar = scalar.substring(from: scalar.index(after: scalar.startIndex))
#endif
} else if scalar.hasPrefix("+") {
#if swift(>=4.0)
scalar = String(scalar[scalar.index(after: scalar.startIndex)...])
#else
scalar = scalar.substring(from: scalar.index(after: scalar.startIndex))
#endif
}
let digits = scalar.components(separatedBy: ":").flatMap({ T($0) }).reversed()
var base: T = 1

View File

@ -65,7 +65,7 @@ extension String {
return (
number,
utf16.distance(from: utf16StartIndex, to: utf16Index),
substring(with: outStartIndex..<outEndIndex)
String(self[outStartIndex..<outEndIndex])
)
}
@ -84,7 +84,7 @@ extension String {
getLineStart(&outStartIndex, end: &outEndIndex, contentsEnd: &outContentsEndIndex,
for: range)
}
return substring(with: outStartIndex..<outEndIndex)
return String(self[outStartIndex..<outEndIndex])
}
/// String appending newline if is not ending with newline.

View File

@ -19,7 +19,7 @@ class StringTests: XCTestCase {
// Confirm behavior of Standard Library API
func testConfirmBehaviorOfStandardLibraryAPI() {
let rangeOfFirstLine = string.lineRange(for: string.startIndex..<string.startIndex)
let firstLine = string.substring(with: rangeOfFirstLine)
let firstLine = string[rangeOfFirstLine]
XCTAssertEqual(firstLine, "LINE1_67あ\n")
}

View File

@ -116,7 +116,11 @@ private func dumped<T>(_ value: T) -> String {
if count == 1 {
// remove `- ` prefix if
let index = firstLine.index(firstLine.startIndex, offsetBy: 2)
#if swift(>=4.0)
return String(firstLine[index...])
#else
return firstLine.substring(from: index)
#endif
} else {
return "[\n" + output + "]"
}