File tree Expand file tree Collapse file tree 1 file changed +8
-4
lines changed Expand file tree Collapse file tree 1 file changed +8
-4
lines changed Original file line number Diff line number Diff line change 2
2
//
3
3
// This source file is part of the Swift.org open source project
4
4
//
5
- // Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
5
+ // Copyright (c) 2014 - 2019 Apple Inc. and the Swift project authors
6
6
// Licensed under Apache License v2.0 with Runtime Library Exception
7
7
//
8
8
// See https://swift.org/LICENSE.txt for license information
@@ -126,7 +126,7 @@ extension ${Self} : LosslessStringConvertible {
126
126
/// is `nil`.
127
127
@inlinable // FIXME(sil-serialize-all)
128
128
public init?<S: StringProtocol>(_ text: S) {
129
- let u16 = text.utf16
129
+ let u8 = text.utf8
130
130
131
131
let (result, n) : (${Self}, Int) = text.withCString { chars in
132
132
var result: ${Self} = 0
@@ -136,8 +136,12 @@ extension ${Self} : LosslessStringConvertible {
136
136
return (result, endPtr == nil ? 0 : endPtr! - chars)
137
137
}
138
138
139
- if n == 0 || n != u16.count
140
- || u16.contains(where: { $0 > 127 || _isspace_clocale($0) }) {
139
+ if n == 0 || n != u8.count
140
+ || u8.contains(where: { codeUnit in
141
+ // Check if the code unit is either non-ASCII or if isspace(codeUnit)
142
+ // would return nonzero when the current locale is the C locale.
143
+ codeUnit > 127 || "\t\n\u{b}\u{c}\r ".utf8.contains(codeUnit)
144
+ }) {
141
145
return nil
142
146
}
143
147
self = result
You can’t perform that action at this time.
0 commit comments