Skip to content

Commit 102a3a8

Browse files
authored
Merge pull request swiftlang#24198 from troughton/floating-point-parsing-utf8
[stdlib] Use String’s underlying UTF-8 view for Float parsing
2 parents 1ef6a00 + 4c2df28 commit 102a3a8

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

stdlib/public/core/FloatingPointParsing.swift.gyb

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//
33
// This source file is part of the Swift.org open source project
44
//
5-
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
5+
// Copyright (c) 2014 - 2019 Apple Inc. and the Swift project authors
66
// Licensed under Apache License v2.0 with Runtime Library Exception
77
//
88
// See https://swift.org/LICENSE.txt for license information
@@ -126,7 +126,7 @@ extension ${Self} : LosslessStringConvertible {
126126
/// is `nil`.
127127
@inlinable // FIXME(sil-serialize-all)
128128
public init?<S: StringProtocol>(_ text: S) {
129-
let u16 = text.utf16
129+
let u8 = text.utf8
130130

131131
let (result, n) : (${Self}, Int) = text.withCString { chars in
132132
var result: ${Self} = 0
@@ -136,8 +136,12 @@ extension ${Self} : LosslessStringConvertible {
136136
return (result, endPtr == nil ? 0 : endPtr! - chars)
137137
}
138138

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+
}) {
141145
return nil
142146
}
143147
self = result

0 commit comments

Comments
 (0)