diff --git a/benchmark/single-source/CharacterProperties.swift b/benchmark/single-source/CharacterProperties.swift index 3a0872c907176..f21b7ef6824e1 100644 --- a/benchmark/single-source/CharacterProperties.swift +++ b/benchmark/single-source/CharacterProperties.swift @@ -2,7 +2,7 @@ // // This source file is part of the Swift.org open source project // -// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors +// Copyright (c) 2014 - 2020 Apple Inc. and the Swift project authors // Licensed under Apache License v2.0 with Runtime Library Exception // // See https://swift.org/LICENSE.txt for license information @@ -48,7 +48,7 @@ public let CharacterPropertiesPrecomputed = BenchmarkInfo( legacyFactor: 10) extension Character { - var firstScalar: UnicodeScalar { return unicodeScalars.first! } + var firstScalar: Unicode.Scalar { return unicodeScalars.first! } } @@ -263,7 +263,7 @@ func precompute(_ charSet: CharacterSet, capacity: Int) -> Set { guard charSet.hasMember(inPlane: UInt8(plane)) else { continue } let offset = plane &* 0x1_0000 for codePoint in 0...0xFFFF { - guard let scalar = UnicodeScalar(codePoint &+ offset) else { continue } + guard let scalar = Unicode.Scalar(codePoint &+ offset) else { continue } if charSet.contains(scalar) { result.insert(scalar.value) } diff --git a/benchmark/single-source/CharacterProperties.swift.gyb b/benchmark/single-source/CharacterProperties.swift.gyb index f6c47b1874db5..0af2f8cb678d4 100644 --- a/benchmark/single-source/CharacterProperties.swift.gyb +++ b/benchmark/single-source/CharacterProperties.swift.gyb @@ -2,7 +2,7 @@ // // This source file is part of the Swift.org open source project // -// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors +// Copyright (c) 2014 - 2020 Apple Inc. and the Swift project authors // Licensed under Apache License v2.0 with Runtime Library Exception // // See https://swift.org/LICENSE.txt for license information @@ -49,7 +49,7 @@ public let CharacterPropertiesPrecomputed = BenchmarkInfo( legacyFactor: 10) extension Character { - var firstScalar: UnicodeScalar { return unicodeScalars.first! } + var firstScalar: Unicode.Scalar { return unicodeScalars.first! } } % Properties = { "Alphanumeric": "alphanumerics", \ @@ -114,7 +114,7 @@ func precompute(_ charSet: CharacterSet, capacity: Int) -> Set { guard charSet.hasMember(inPlane: UInt8(plane)) else { continue } let offset = plane &* 0x1_0000 for codePoint in 0...0xFFFF { - guard let scalar = UnicodeScalar(codePoint &+ offset) else { continue } + guard let scalar = Unicode.Scalar(codePoint &+ offset) else { continue } if charSet.contains(scalar) { result.insert(scalar.value) } diff --git a/benchmark/single-source/DataBenchmarks.swift b/benchmark/single-source/DataBenchmarks.swift index 14467d1404967..2374ecaf66a6f 100644 --- a/benchmark/single-source/DataBenchmarks.swift +++ b/benchmark/single-source/DataBenchmarks.swift @@ -2,7 +2,7 @@ // // This source file is part of the Swift.org open source project // -// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors +// Copyright (c) 2014 - 2020 Apple Inc. and the Swift project authors // Licensed under Apache License v2.0 with Runtime Library Exception // // See https://swift.org/LICENSE.txt for license information @@ -534,7 +534,7 @@ public func setCount(_ N: Int, data: Data, extra: Int) { @inline(never) public func string(_ N: Int, from data: Data) { for _ in 1...N { - blackHole(String(decoding: data, as: UTF8.self)) + blackHole(String(decoding: data, as: Unicode.UTF8.self)) } } diff --git a/benchmark/single-source/UTF8Decode.swift b/benchmark/single-source/UTF8Decode.swift index 6f8bc762e2f0c..00a8dee82c491 100644 --- a/benchmark/single-source/UTF8Decode.swift +++ b/benchmark/single-source/UTF8Decode.swift @@ -2,7 +2,7 @@ // // This source file is part of the Swift.org open source project // -// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors +// Copyright (c) 2014 - 2020 Apple Inc. and the Swift project authors // Licensed under Apache License v2.0 with Runtime Library Exception // // See https://swift.org/LICENSE.txt for license information @@ -115,7 +115,7 @@ public func run_UTF8Decode(_ N: Int) { for _ in 1...200*N { for string in strings { var it = string.makeIterator() - var utf8 = UTF8() + var utf8 = Unicode.UTF8() while !isEmpty(utf8.decode(&it)) { } } } @@ -132,7 +132,7 @@ public func run_UTF8Decode_InitFromData(_ N: Int) { public func run_UTF8Decode_InitDecoding(_ N: Int) { let input = allStringsBytes for _ in 0..<200*N { - blackHole(String(decoding: input, as: UTF8.self)) + blackHole(String(decoding: input, as: Unicode.UTF8.self)) } } @inline(never) @@ -154,7 +154,7 @@ public func run_UTF8Decode_InitFromData_ascii(_ N: Int) { public func run_UTF8Decode_InitDecoding_ascii(_ N: Int) { let input = asciiBytes for _ in 0..<1_000*N { - blackHole(String(decoding: input, as: UTF8.self)) + blackHole(String(decoding: input, as: Unicode.UTF8.self)) } } @inline(never) @@ -232,14 +232,14 @@ let asciiCustomNoncontiguous = CustomNoncontiguousCollection(Array(ascii.utf8)) public func run_UTF8Decode_InitFromCustom_contiguous(_ N: Int) { let input = allStringsCustomContiguous for _ in 0..<200*N { - blackHole(String(decoding: input, as: UTF8.self)) + blackHole(String(decoding: input, as: Unicode.UTF8.self)) } } @inline(never) public func run_UTF8Decode_InitFromCustom_contiguous_ascii(_ N: Int) { let input = asciiCustomContiguous for _ in 0..<1_000*N { - blackHole(String(decoding: input, as: UTF8.self)) + blackHole(String(decoding: input, as: Unicode.UTF8.self)) } } @inline(never) @@ -254,14 +254,14 @@ public func run_UTF8Decode_InitFromCustom_contiguous_ascii_as_ascii(_ N: Int) { public func run_UTF8Decode_InitFromCustom_noncontiguous(_ N: Int) { let input = allStringsCustomNoncontiguous for _ in 0..<200*N { - blackHole(String(decoding: input, as: UTF8.self)) + blackHole(String(decoding: input, as: Unicode.UTF8.self)) } } @inline(never) public func run_UTF8Decode_InitFromCustom_noncontiguous_ascii(_ N: Int) { let input = asciiCustomNoncontiguous for _ in 0..<1_000*N { - blackHole(String(decoding: input, as: UTF8.self)) + blackHole(String(decoding: input, as: Unicode.UTF8.self)) } } @inline(never) diff --git a/stdlib/private/StdlibUnittest/StdlibUnittest.swift b/stdlib/private/StdlibUnittest/StdlibUnittest.swift index f8841795eee92..5a000280eea39 100644 --- a/stdlib/private/StdlibUnittest/StdlibUnittest.swift +++ b/stdlib/private/StdlibUnittest/StdlibUnittest.swift @@ -772,10 +772,10 @@ func _stdlib_getline() -> String? { if result.isEmpty { return nil } - return String(decoding: result, as: UTF8.self) + return String(decoding: result, as: Unicode.UTF8.self) } if c == CInt(Unicode.Scalar("\n").value) { - return String(decoding: result, as: UTF8.self) + return String(decoding: result, as: Unicode.UTF8.self) } result.append(UInt8(c)) } diff --git a/stdlib/private/SwiftPrivate/IO.swift b/stdlib/private/SwiftPrivate/IO.swift index 152ae9a0bc1a8..9c89643772216 100644 --- a/stdlib/private/SwiftPrivate/IO.swift +++ b/stdlib/private/SwiftPrivate/IO.swift @@ -2,7 +2,7 @@ // // This source file is part of the Swift.org open source project // -// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors +// Copyright (c) 2014 - 2020 Apple Inc. and the Swift project authors // Licensed under Apache License v2.0 with Runtime Library Exception // // See https://swift.org/LICENSE.txt for license information @@ -37,13 +37,13 @@ public struct _FDInputStream { // on that and remove the workaround in the test harness if let index = _buffer[0..<_offset].firstIndex(of: UInt8(Unicode.Scalar("\n").value)) { - let result = String(decoding: _buffer[0.. 0 { - let result = String(decoding: _buffer[0..<_offset], as: UTF8.self) + let result = String(decoding: _buffer[0..<_offset], as: Unicode.UTF8.self) _buffer.removeAll() _offset = 0 return result @@ -94,13 +94,13 @@ public struct _FDInputStream { public mutating func getline() -> String? { if let newlineIndex = _buffer[0..<_bufferUsed].firstIndex(of: UInt8(Unicode.Scalar("\n").value)) { - let result = String(decoding: _buffer[0.. 0 { - let result = String(decoding: _buffer[0..<_bufferUsed], as: UTF8.self) + let result = String(decoding: _buffer[0..<_bufferUsed], as: Unicode.UTF8.self) _buffer.removeAll() _bufferUsed = 0 return result diff --git a/stdlib/private/SwiftPrivateLibcExtras/Subprocess.swift b/stdlib/private/SwiftPrivateLibcExtras/Subprocess.swift index 0b9aeb8466b65..8dbe36d1dcf5a 100644 --- a/stdlib/private/SwiftPrivateLibcExtras/Subprocess.swift +++ b/stdlib/private/SwiftPrivateLibcExtras/Subprocess.swift @@ -2,7 +2,7 @@ // // This source file is part of the Swift.org open source project // -// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors +// Copyright (c) 2014 - 2020 Apple Inc. and the Swift project authors // Licensed under Apache License v2.0 with Runtime Library Exception // // See https://swift.org/LICENSE.txt for license information @@ -105,7 +105,7 @@ public func spawnChild(_ args: [String]) // for more details on how to properly quote the command line for Windows. let command: String = ([CommandLine.arguments[0]] + args).joined(separator: " ") - command.withCString(encodedAs: UTF16.self) { cString in + command.withCString(encodedAs: Unicode.UTF16.self) { cString in if !CreateProcessW(nil, UnsafeMutablePointer(mutating: cString), nil, nil, true, 0, nil, nil, &siStartupInfo, &piProcessInfo) { diff --git a/stdlib/public/Darwin/Foundation/NSStringAPI.swift b/stdlib/public/Darwin/Foundation/NSStringAPI.swift index b8c087687aeeb..e80d3f297de92 100644 --- a/stdlib/public/Darwin/Foundation/NSStringAPI.swift +++ b/stdlib/public/Darwin/Foundation/NSStringAPI.swift @@ -2,7 +2,7 @@ // // This source file is part of the Swift.org open source project // -// Copyright (c) 2014 - 2018 Apple Inc. and the Swift project authors +// Copyright (c) 2014 - 2020 Apple Inc. and the Swift project authors // Licensed under Apache License v2.0 with Runtime Library Exception // // See https://swift.org/LICENSE.txt for license information @@ -73,7 +73,7 @@ internal func _persistCString(_ p: UnsafePointer?) -> [CChar]? { guard let cString = p else { return nil } - let bytesToCopy = UTF8._nullCodeUnitOffset(in: cString) + 1 // +1 for the terminating NUL + let bytesToCopy = Unicode.UTF8._nullCodeUnitOffset(in: cString) + 1 // +1 for the terminating NUL let result = [CChar](unsafeUninitializedCapacity: bytesToCopy) { buffer, initializedCount in buffer.baseAddress!.initialize(from: cString, count: bytesToCopy) initializedCount = bytesToCopy diff --git a/stdlib/public/core/ASCII.swift b/stdlib/public/core/ASCII.swift index 6f629936bb055..85c2484571a09 100644 --- a/stdlib/public/core/ASCII.swift +++ b/stdlib/public/core/ASCII.swift @@ -2,7 +2,7 @@ // // This source file is part of the Swift.org open source project // -// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors +// Copyright (c) 2014 - 2020 Apple Inc. and the Swift project authors // Licensed under Apache License v2.0 with Runtime Library Exception // // See https://swift.org/LICENSE.txt for license information @@ -25,7 +25,7 @@ extension Unicode.ASCII: Unicode.Encoding { /// Returns whether the given code unit represents an ASCII scalar @_alwaysEmitIntoClient - public static func isASCII(_ x: CodeUnit) -> Bool { return UTF8.isASCII(x) } + public static func isASCII(_ x: CodeUnit) -> Bool { Unicode.UTF8.isASCII(x) } @inline(__always) @inlinable @@ -54,13 +54,13 @@ extension Unicode.ASCII: Unicode.Encoding { public static func transcode( _ content: FromEncoding.EncodedScalar, from _: FromEncoding.Type ) -> EncodedScalar? { - if _fastPath(FromEncoding.self == UTF16.self) { - let c = _identityCast(content, to: UTF16.EncodedScalar.self) + if _fastPath(FromEncoding.self == Unicode.UTF16.self) { + let c = _identityCast(content, to: Unicode.UTF16.EncodedScalar.self) guard (c._storage & 0xFF80 == 0) else { return nil } return EncodedScalar(CodeUnit(c._storage & 0x7f)) } - else if _fastPath(FromEncoding.self == UTF8.self) { - let c = _identityCast(content, to: UTF8.EncodedScalar.self) + else if _fastPath(FromEncoding.self == Unicode.UTF8.self) { + let c = _identityCast(content, to: Unicode.UTF8.EncodedScalar.self) let first = c.first.unsafelyUnwrapped guard (first < 0x80) else { return nil } return EncodedScalar(CodeUnit(first)) diff --git a/stdlib/public/core/CString.swift b/stdlib/public/core/CString.swift index 930d4cb7b8598..7e10069dd4a83 100644 --- a/stdlib/public/core/CString.swift +++ b/stdlib/public/core/CString.swift @@ -2,7 +2,7 @@ // // This source file is part of the Swift.org open source project // -// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors +// Copyright (c) 2014 - 2020 Apple Inc. and the Swift project authors // Licensed under Apache License v2.0 with Runtime Library Exception // // See https://swift.org/LICENSE.txt for license information @@ -44,7 +44,7 @@ extension String { /// /// - Parameter cString: A pointer to a null-terminated UTF-8 code sequence. public init(cString: UnsafePointer) { - let len = UTF8._nullCodeUnitOffset(in: cString) + let len = Unicode.UTF8._nullCodeUnitOffset(in: cString) self = String._fromUTF8Repairing( UnsafeBufferPointer(start: cString._asUInt8, count: len)).0 } @@ -55,7 +55,7 @@ extension String { /// This is identical to `init(cString: UnsafePointer)` but operates on /// an unsigned sequence of bytes. public init(cString: UnsafePointer) { - let len = UTF8._nullCodeUnitOffset(in: cString) + let len = Unicode.UTF8._nullCodeUnitOffset(in: cString) self = String._fromUTF8Repairing( UnsafeBufferPointer(start: cString, count: len)).0 } @@ -87,7 +87,7 @@ extension String { /// /// - Parameter cString: A pointer to a null-terminated UTF-8 code sequence. public init?(validatingUTF8 cString: UnsafePointer) { - let len = UTF8._nullCodeUnitOffset(in: cString) + let len = Unicode.UTF8._nullCodeUnitOffset(in: cString) guard let str = String._tryFromUTF8( UnsafeBufferPointer(start: cString._asUInt8, count: len)) else { return nil } @@ -110,7 +110,7 @@ extension String { /// let validUTF8: [UInt8] = [67, 97, 102, 195, 169, 0] /// validUTF8.withUnsafeBufferPointer { ptr in /// let s = String.decodeCString(ptr.baseAddress, - /// as: UTF8.self, + /// as: Unicode.UTF8.self, /// repairingInvalidCodeUnits: true) /// print(s) /// } @@ -119,7 +119,7 @@ extension String { /// let invalidUTF8: [UInt8] = [67, 97, 102, 195, 0] /// invalidUTF8.withUnsafeBufferPointer { ptr in /// let s = String.decodeCString(ptr.baseAddress, - /// as: UTF8.self, + /// as: Unicode.UTF8.self, /// repairingInvalidCodeUnits: true) /// print(s) /// } @@ -149,7 +149,7 @@ extension String { if _fastPath(encoding == Unicode.UTF8.self) { let ptr = UnsafeRawPointer(cPtr).assumingMemoryBound(to: UInt8.self) - let len = UTF8._nullCodeUnitOffset(in: ptr) + let len = Unicode.UTF8._nullCodeUnitOffset(in: ptr) let codeUnits = UnsafeBufferPointer(start: ptr, count: len) if isRepairing { return String._fromUTF8Repairing(codeUnits) diff --git a/stdlib/public/core/FloatingPointParsing.swift.gyb b/stdlib/public/core/FloatingPointParsing.swift.gyb index aa58f864ddc42..a95f134e2e485 100644 --- a/stdlib/public/core/FloatingPointParsing.swift.gyb +++ b/stdlib/public/core/FloatingPointParsing.swift.gyb @@ -2,7 +2,7 @@ // // This source file is part of the Swift.org open source project // -// Copyright (c) 2014 - 2019 Apple Inc. and the Swift project authors +// Copyright (c) 2014 - 2020 Apple Inc. and the Swift project authors // Licensed under Apache License v2.0 with Runtime Library Exception // // See https://swift.org/LICENSE.txt for license information @@ -33,7 +33,7 @@ cFuncSuffix2 = {16: 'f16', 32: 'f', 64: 'd', 80: 'ld'} /// Returns `true` iff isspace(u) would return nonzero when the current /// locale is the C locale. @inlinable // FIXME(sil-serialize-all) -internal func _isspace_clocale(_ u: UTF16.CodeUnit) -> Bool { +internal func _isspace_clocale(_ u: Unicode.UTF16.CodeUnit) -> Bool { return "\t\n\u{b}\u{c}\r ".utf16.contains(u) } diff --git a/stdlib/public/core/IntegerParsing.swift b/stdlib/public/core/IntegerParsing.swift index c1b1cfded6f17..3336073cb81b6 100644 --- a/stdlib/public/core/IntegerParsing.swift +++ b/stdlib/public/core/IntegerParsing.swift @@ -2,7 +2,7 @@ // // This source file is part of the Swift.org open source project // -// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors +// Copyright (c) 2014 - 2020 Apple Inc. and the Swift project authors // Licensed under Apache License v2.0 with Runtime Library Exception // // See https://swift.org/LICENSE.txt for license information @@ -10,11 +10,11 @@ // //===----------------------------------------------------------------------===// -/// Returns c as a UTF16.CodeUnit. Meant to be used as _ascii16("x"). +/// Returns c as a Unicode.UTF16.CodeUnit. Meant to be used as _ascii16("x"). @inlinable -internal func _ascii16(_ c: Unicode.Scalar) -> UTF16.CodeUnit { +internal func _ascii16(_ c: Unicode.Scalar) -> Unicode.UTF16.CodeUnit { _internalInvariant(c.value >= 0 && c.value <= 0x7F, "not ASCII") - return UTF16.CodeUnit(c.value) + return Unicode.UTF16.CodeUnit(c.value) } @inlinable diff --git a/stdlib/public/core/LegacyABI.swift b/stdlib/public/core/LegacyABI.swift index 31ec50bab8953..ca38f9e5c6d14 100644 --- a/stdlib/public/core/LegacyABI.swift +++ b/stdlib/public/core/LegacyABI.swift @@ -2,7 +2,7 @@ // // This source file is part of the Swift.org open source project // -// Copyright (c) 2014 - 2019 Apple Inc. and the Swift project authors +// Copyright (c) 2014 - 2020 Apple Inc. and the Swift project authors // Licensed under Apache License v2.0 with Runtime Library Exception // // See https://swift.org/LICENSE.txt for license information @@ -30,7 +30,7 @@ internal func _isASCII(_ x: UInt8) -> Bool { @available(*, unavailable, renamed: "Unicode.UTF8.isContinuation") @inlinable internal func _isContinuation(_ x: UInt8) -> Bool { - return UTF8.isContinuation(x) + return Unicode.UTF8.isContinuation(x) } extension Substring { diff --git a/stdlib/public/core/ReflectionMirror.swift b/stdlib/public/core/ReflectionMirror.swift index 8ed481582570d..02efbcf5a0769 100644 --- a/stdlib/public/core/ReflectionMirror.swift +++ b/stdlib/public/core/ReflectionMirror.swift @@ -169,7 +169,7 @@ extension Mirror { } let rawDisplayStyle = _getDisplayStyle(subject) - switch UnicodeScalar(Int(rawDisplayStyle)) { + switch Unicode.Scalar(Int(rawDisplayStyle)) { case "c": self.displayStyle = .class case "e": self.displayStyle = .enum case "s": self.displayStyle = .struct diff --git a/stdlib/public/core/Runtime.swift b/stdlib/public/core/Runtime.swift index 086588cffc43d..bc992ba733e70 100644 --- a/stdlib/public/core/Runtime.swift +++ b/stdlib/public/core/Runtime.swift @@ -2,7 +2,7 @@ // // This source file is part of the Swift.org open source project // -// Copyright (c) 2014 - 2019 Apple Inc. and the Swift project authors +// Copyright (c) 2014 - 2020 Apple Inc. and the Swift project authors // Licensed under Apache License v2.0 with Runtime Library Exception // // See https://swift.org/LICENSE.txt for license information @@ -297,7 +297,7 @@ internal struct _Buffer72 { // doesn't have _Float16 on all platforms yet. @_silgen_name("swift_float16ToString") internal func _float16ToStringImpl( - _ buffer: UnsafeMutablePointer, + _ buffer: UnsafeMutablePointer, _ bufferLength: UInt, _ value: Float32, _ debug: Bool @@ -324,7 +324,7 @@ internal func _float16ToString( // to any integer type without checks, however. @_silgen_name("swift_float32ToString") internal func _float32ToStringImpl( - _ buffer: UnsafeMutablePointer, + _ buffer: UnsafeMutablePointer, _ bufferLength: UInt, _ value: Float32, _ debug: Bool @@ -348,7 +348,7 @@ internal func _float32ToString( // to any integer type without checks, however. @_silgen_name("swift_float64ToString") internal func _float64ToStringImpl( - _ buffer: UnsafeMutablePointer, + _ buffer: UnsafeMutablePointer, _ bufferLength: UInt, _ value: Float64, _ debug: Bool @@ -375,7 +375,7 @@ internal func _float64ToString( // to any integer type without checks, however. @_silgen_name("swift_float80ToString") internal func _float80ToStringImpl( - _ buffer: UnsafeMutablePointer, + _ buffer: UnsafeMutablePointer, _ bufferLength: UInt, _ value: Float80, _ debug: Bool @@ -400,7 +400,7 @@ internal func _float80ToString( // to any integer type without checks, however. @_silgen_name("swift_int64ToString") internal func _int64ToStringImpl( - _ buffer: UnsafeMutablePointer, + _ buffer: UnsafeMutablePointer, _ bufferLength: UInt, _ value: Int64, _ radix: Int64, @@ -437,7 +437,7 @@ internal func _int64ToString( // to any integer type without checks, however. @_silgen_name("swift_uint64ToString") internal func _uint64ToStringImpl( - _ buffer: UnsafeMutablePointer, + _ buffer: UnsafeMutablePointer, _ bufferLength: UInt, _ value: UInt64, _ radix: Int64, diff --git a/stdlib/public/core/String.swift b/stdlib/public/core/String.swift index cc0c3175e9044..19bd6ca9122a0 100644 --- a/stdlib/public/core/String.swift +++ b/stdlib/public/core/String.swift @@ -417,7 +417,7 @@ extension String { public init( decoding codeUnits: C, as sourceEncoding: Encoding.Type ) where C.Iterator.Element == Encoding.CodeUnit { - guard _fastPath(sourceEncoding == UTF8.self) else { + guard _fastPath(sourceEncoding == Unicode.UTF8.self) else { self = String._fromCodeUnits( codeUnits, encoding: sourceEncoding, repair: true)!.0 return @@ -560,7 +560,7 @@ extension String { encodedAs targetEncoding: TargetEncoding.Type, _ body: (UnsafePointer) throws -> Result ) rethrows -> Result { - if targetEncoding == UTF8.self { + if targetEncoding == Unicode.UTF8.self { return try self.withCString { (cPtr: UnsafePointer) -> Result in _internalInvariant(UInt8.self == TargetEncoding.CodeUnit.self) @@ -584,7 +584,7 @@ extension String { arg.reserveCapacity(1 &+ self._guts.count / 4) let repaired = transcode( utf8.makeIterator(), - from: UTF8.self, + from: Unicode.UTF8.self, to: targetEncoding, stoppingOnError: false, into: { arg.append($0) }) diff --git a/stdlib/public/core/StringBridge.swift b/stdlib/public/core/StringBridge.swift index a24d721d0e630..02a35c0eaed86 100644 --- a/stdlib/public/core/StringBridge.swift +++ b/stdlib/public/core/StringBridge.swift @@ -2,7 +2,7 @@ // // This source file is part of the Swift.org open source project // -// Copyright (c) 2014 - 2018 Apple Inc. and the Swift project authors +// Copyright (c) 2014 - 2020 Apple Inc. and the Swift project authors // Licensed under Apache License v2.0 with Runtime Library Exception // // See https://swift.org/LICENSE.txt for license information @@ -117,7 +117,9 @@ internal func _isNSString(_ str:AnyObject) -> Bool { } @_effects(readonly) -private func _NSStringCharactersPtr(_ str: _StringSelectorHolder) -> UnsafeMutablePointer? { +private func _NSStringCharactersPtr( + _ str: _StringSelectorHolder +) -> UnsafeMutablePointer? { return UnsafeMutablePointer(mutating: str._fastCharacterContents()) } @@ -125,7 +127,7 @@ private func _NSStringCharactersPtr(_ str: _StringSelectorHolder) -> UnsafeMutab @_effects(readonly) internal func _stdlib_binary_CFStringGetCharactersPtr( _ source: _CocoaString -) -> UnsafeMutablePointer? { +) -> UnsafeMutablePointer? { return _NSStringCharactersPtr(_objc(source)) } @@ -133,7 +135,7 @@ internal func _stdlib_binary_CFStringGetCharactersPtr( private func _NSStringGetCharacters( from source: _StringSelectorHolder, range: Range, - into destination: UnsafeMutablePointer + into destination: UnsafeMutablePointer ) { source.getCharacters(destination, range: _SwiftNSRange( location: range.startIndex, @@ -147,7 +149,7 @@ private func _NSStringGetCharacters( internal func _cocoaStringCopyCharacters( from source: _CocoaString, range: Range, - into destination: UnsafeMutablePointer + into destination: UnsafeMutablePointer ) { _NSStringGetCharacters(from: _objc(source), range: range, into: destination) } @@ -155,14 +157,14 @@ internal func _cocoaStringCopyCharacters( @_effects(readonly) private func _NSStringGetCharacter( _ target: _StringSelectorHolder, _ position: Int -) -> UTF16.CodeUnit { +) -> Unicode.UTF16.CodeUnit { return target.character(at: position) } @_effects(readonly) internal func _cocoaStringSubscript( _ target: _CocoaString, _ position: Int -) -> UTF16.CodeUnit { +) -> Unicode.UTF16.CodeUnit { return _NSStringGetCharacter(_objc(target), position) } @@ -676,7 +678,7 @@ internal func _NSStringFromUTF8(_ s: UnsafePointer, _ len: Int) -> AnyObject { return String( decoding: UnsafeBufferPointer(start: s, count: len), - as: UTF8.self + as: Unicode.UTF8.self )._bridgeToObjectiveCImpl() } diff --git a/stdlib/public/core/StringComparison.swift b/stdlib/public/core/StringComparison.swift index fb00567768bff..9084fefee0ed0 100644 --- a/stdlib/public/core/StringComparison.swift +++ b/stdlib/public/core/StringComparison.swift @@ -2,7 +2,7 @@ // // This source file is part of the Swift.org open source project // -// Copyright (c) 2014 - 2018 Apple Inc. and the Swift project authors +// Copyright (c) 2014 - 2020 Apple Inc. and the Swift project authors // Licensed under Apache License v2.0 with Runtime Library Exception // // See https://swift.org/LICENSE.txt for license information @@ -239,7 +239,7 @@ private func _findBoundary( } // Back up to scalar boundary - while UTF8.isContinuation(utf8[_unchecked: idx]) { + while Unicode.UTF8.isContinuation(utf8[_unchecked: idx]) { idx &-= 1 } diff --git a/stdlib/public/core/StringCreate.swift b/stdlib/public/core/StringCreate.swift index d30fd0d52b67d..1b8eb91cb86b0 100644 --- a/stdlib/public/core/StringCreate.swift +++ b/stdlib/public/core/StringCreate.swift @@ -2,7 +2,7 @@ // // This source file is part of the Swift.org open source project // -// Copyright (c) 2014 - 2018 Apple Inc. and the Swift project authors +// Copyright (c) 2014 - 2020 Apple Inc. and the Swift project authors // Licensed under Apache License v2.0 with Runtime Library Exception // // See https://swift.org/LICENSE.txt for license information @@ -173,8 +173,8 @@ extension String { contents.reserveCapacity(input.count) let repaired = transcode( input.makeIterator(), - from: UTF16.self, - to: UTF8.self, + from: Unicode.UTF16.self, + to: Unicode.UTF8.self, stoppingOnError: false, into: { contents.append($0) }) _internalInvariant(!repaired, "Error present") @@ -201,7 +201,7 @@ extension String { let repaired = transcode( input.makeIterator(), from: Encoding.self, - to: UTF8.self, + to: Unicode.UTF8.self, stoppingOnError: false, into: { contents.append($0) }) guard repair || !repaired else { return nil } @@ -266,7 +266,7 @@ extension String { static func _fromInvalidUTF16( _ utf16: UnsafeBufferPointer ) -> String { - return String._fromCodeUnits(utf16, encoding: UTF16.self, repair: true)!.0 + String._fromCodeUnits(utf16, encoding: Unicode.UTF16.self, repair: true)!.0 } @usableFromInline diff --git a/stdlib/public/core/StringGuts.swift b/stdlib/public/core/StringGuts.swift index 038cd5abda1ad..e38b0bc483094 100644 --- a/stdlib/public/core/StringGuts.swift +++ b/stdlib/public/core/StringGuts.swift @@ -2,7 +2,7 @@ // // This source file is part of the Swift.org open source project // -// Copyright (c) 2014 - 2018 Apple Inc. and the Swift project authors +// Copyright (c) 2014 - 2020 Apple Inc. and the Swift project authors // Licensed under Apache License v2.0 with Runtime Library Exception // // See https://swift.org/LICENSE.txt for license information @@ -316,7 +316,7 @@ extension _StringGuts { // FIXME: Remove. Still used by swift-corelibs-foundation @available(*, deprecated) - public var startUTF16: UnsafeMutablePointer { + public var startUTF16: UnsafeMutablePointer { fatalError("Not contiguous UTF-16") } } @@ -325,7 +325,7 @@ extension _StringGuts { public // SPI(corelibs-foundation) func _persistCString(_ p: UnsafePointer?) -> [CChar]? { guard let s = p else { return nil } - let bytesToCopy = UTF8._nullCodeUnitOffset(in: s) + 1 // +1 for the terminating NUL + let bytesToCopy = Unicode.UTF8._nullCodeUnitOffset(in: s) + 1 // +1 for the terminating NUL let result = [CChar](unsafeUninitializedCapacity: bytesToCopy) { buf, initedCount in buf.baseAddress!.assign(from: s, count: bytesToCopy) initedCount = bytesToCopy diff --git a/stdlib/public/core/StringNormalization.swift b/stdlib/public/core/StringNormalization.swift index c9037015aa0af..2fe282ff2ba4e 100644 --- a/stdlib/public/core/StringNormalization.swift +++ b/stdlib/public/core/StringNormalization.swift @@ -2,7 +2,7 @@ // // This source file is part of the Swift.org open source project // -// Copyright (c) 2014 - 2018 Apple Inc. and the Swift project authors +// Copyright (c) 2014 - 2020 Apple Inc. and the Swift project authors // Licensed under Apache License v2.0 with Runtime Library Exception // // See https://swift.org/LICENSE.txt for license information @@ -108,7 +108,7 @@ extension UnsafeBufferPointer where Element == UInt8 { if index == 0 || index == count { return true } - _internalInvariant(!UTF8.isContinuation(self[_unchecked: index])) + _internalInvariant(!Unicode.UTF8.isContinuation(self[_unchecked: index])) // Sub-300 latiny fast-path if self[_unchecked: index] < 0xCC { return true } @@ -165,7 +165,7 @@ extension UnsafeBufferPointer where Element == UInt8 { _internalInvariant(index == count) return true } - return !UTF8.isContinuation(self[index]) + return !Unicode.UTF8.isContinuation(self[index]) } } @@ -235,7 +235,7 @@ private func fastFill( } inputCount &+= len - for cu in UTF8.encode(scalar)._unsafelyUnwrappedUnchecked { + for cu in Unicode.UTF8.encode(scalar)._unsafelyUnwrappedUnchecked { outputBuffer[_unchecked: outputCount] = cu outputCount &+= 1 } @@ -294,7 +294,7 @@ private func transcodeValidUTF16ToUTF8( readIndex += length - for cu in UTF8.encode(scalar)._unsafelyUnwrappedUnchecked { + for cu in Unicode.UTF8.encode(scalar)._unsafelyUnwrappedUnchecked { if writeIndex < outputCount { outputBuffer[writeIndex] = cu writeIndex &+= 1 diff --git a/stdlib/public/core/StringUTF16View.swift b/stdlib/public/core/StringUTF16View.swift index b62b4227682a6..340b22e2cbd81 100644 --- a/stdlib/public/core/StringUTF16View.swift +++ b/stdlib/public/core/StringUTF16View.swift @@ -2,7 +2,7 @@ // // This source file is part of the Swift.org open source project // -// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors +// Copyright (c) 2014 - 2020 Apple Inc. and the Swift project authors // Licensed under Apache License v2.0 with Runtime Library Exception // // See https://swift.org/LICENSE.txt for license information @@ -244,7 +244,7 @@ extension String.UTF16View: BidirectionalCollection { /// - Parameter position: A valid index of the view. `position` must be /// less than the view's end index. @inlinable @inline(__always) - public subscript(idx: Index) -> UTF16.CodeUnit { + public subscript(idx: Index) -> Unicode.UTF16.CodeUnit { String(_guts)._boundsCheck(idx) if _fastPath(_guts.isFastUTF8) { @@ -440,7 +440,7 @@ extension String.UTF16View { @usableFromInline @inline(never) @_effects(releasenone) - internal func _foreignSubscript(position i: Index) -> UTF16.CodeUnit { + internal func _foreignSubscript(position i: Index) -> Unicode.UTF16.CodeUnit { _internalInvariant(_guts.isForeign) return _guts.foreignErrorCorrectedUTF16CodeUnit(at: i.strippingTranscoding) } diff --git a/stdlib/public/core/StringUTF8Validation.swift b/stdlib/public/core/StringUTF8Validation.swift index 17f1519024ebb..126b8c6accc3b 100644 --- a/stdlib/public/core/StringUTF8Validation.swift +++ b/stdlib/public/core/StringUTF8Validation.swift @@ -1,3 +1,15 @@ +//===--- StringUTF8Validation.swift ---------------------------------------===// +// +// This source file is part of the Swift.org open source project +// +// Copyright (c) 2018 - 2020 Apple Inc. and the Swift project authors +// Licensed under Apache License v2.0 with Runtime Library Exception +// +// See https://swift.org/LICENSE.txt for license information +// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors +// +//===----------------------------------------------------------------------===// + private func _isUTF8MultiByteLeading(_ x: UInt8) -> Bool { return (0xC2...0xF4).contains(x) } @@ -7,7 +19,7 @@ private func _isNotOverlong_F0(_ x: UInt8) -> Bool { } private func _isNotOverlong_F4(_ x: UInt8) -> Bool { - return UTF8.isContinuation(x) && x <= 0x8F + return Unicode.UTF8.isContinuation(x) && x <= 0x8F } private func _isNotOverlong_E0(_ x: UInt8) -> Bool { @@ -15,7 +27,7 @@ private func _isNotOverlong_E0(_ x: UInt8) -> Bool { } private func _isNotOverlong_ED(_ x: UInt8) -> Bool { - return UTF8.isContinuation(x) && x <= 0x9F + return Unicode.UTF8.isContinuation(x) && x <= 0x9F } internal struct UTF8ExtraInfo: Equatable { @@ -44,11 +56,11 @@ internal func validateUTF8(_ buf: UnsafeBufferPointer) -> UTF8ValidationR guard f(cu) else { throw UTF8ValidationError() } } @inline(__always) func guaranteeContinuation() throws { - try guaranteeIn(UTF8.isContinuation) + try guaranteeIn(Unicode.UTF8.isContinuation) } func _legacyInvalidLengthCalculation(_ _buffer: (_storage: UInt32, ())) -> Int { - // function body copied from UTF8.ForwardParser._invalidLength + // function body copied from Unicode.UTF8.ForwardParser._invalidLength if _buffer._storage & 0b0__1100_0000__1111_0000 == 0b0__1000_0000__1110_0000 { // 2-byte prefix of 3-byte sequence. The top 5 bits of the decoded result @@ -90,7 +102,7 @@ internal func validateUTF8(_ buf: UnsafeBufferPointer) -> UTF8ValidationR var endIndex = buf.startIndex var iter = buf.makeIterator() _ = iter.next() - while let cu = iter.next(), UTF8.isContinuation(cu) { + while let cu = iter.next(), Unicode.UTF8.isContinuation(cu) { endIndex += 1 } let illegalRange = Range(buf.startIndex...endIndex) @@ -103,7 +115,7 @@ internal func validateUTF8(_ buf: UnsafeBufferPointer) -> UTF8ValidationR do { var isASCII = true while let cu = iter.next() { - if UTF8.isASCII(cu) { lastValidIndex &+= 1; continue } + if Unicode.UTF8.isASCII(cu) { lastValidIndex &+= 1; continue } isASCII = false if _slowPath(!_isUTF8MultiByteLeading(cu)) { throw UTF8ValidationError() diff --git a/stdlib/public/core/StringUTF8View.swift b/stdlib/public/core/StringUTF8View.swift index b5a84bdf3f61e..b60754c365a3f 100644 --- a/stdlib/public/core/StringUTF8View.swift +++ b/stdlib/public/core/StringUTF8View.swift @@ -2,7 +2,7 @@ // // This source file is part of the Swift.org open source project // -// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors +// Copyright (c) 2014 - 2020 Apple Inc. and the Swift project authors // Licensed under Apache License v2.0 with Runtime Library Exception // // See https://swift.org/LICENSE.txt for license information @@ -115,7 +115,7 @@ extension String.UTF8View { extension String.UTF8View: BidirectionalCollection { public typealias Index = String.Index - public typealias Element = UTF8.CodeUnit + public typealias Element = Unicode.UTF8.CodeUnit /// The position of the first code unit if the UTF-8 view is /// nonempty. @@ -206,7 +206,7 @@ extension String.UTF8View: BidirectionalCollection { /// - Parameter position: A valid index of the view. `position` /// must be less than the view's end index. @inlinable @inline(__always) - public subscript(i: Index) -> UTF8.CodeUnit { + public subscript(i: Index) -> Unicode.UTF8.CodeUnit { String(_guts)._boundsCheck(i) if _fastPath(_guts.isFastUTF8) { return _guts.withFastUTF8 { utf8 in utf8[_unchecked: i._encodedOffset] } @@ -419,7 +419,7 @@ extension String.UTF8View { let (scalar, scalarLen) = _guts.foreignErrorCorrectedScalar( startingAt: idx.strippingTranscoding) - let utf8Len = UTF8.width(scalar) + let utf8Len = Unicode.UTF8.width(scalar) if utf8Len == 1 { _internalInvariant(idx.transcodedOffset == 0) @@ -450,7 +450,7 @@ extension String.UTF8View { let (scalar, scalarLen) = _guts.foreignErrorCorrectedScalar( endingAt: idx.strippingTranscoding) - let utf8Len = UTF8.width(scalar) + let utf8Len = Unicode.UTF8.width(scalar) return idx.encoded( offsetBy: -scalarLen ).transcoded(withOffset: utf8Len &- 1) @@ -458,7 +458,7 @@ extension String.UTF8View { @usableFromInline @inline(never) @_effects(releasenone) - internal func _foreignSubscript(position idx: Index) -> UTF8.CodeUnit { + internal func _foreignSubscript(position idx: Index) -> Unicode.UTF8.CodeUnit { _internalInvariant(_guts.isForeign) let idx = _utf8AlignForeignIndex(idx) diff --git a/stdlib/public/core/StringUnicodeScalarView.swift b/stdlib/public/core/StringUnicodeScalarView.swift index a8a7c05357347..d3e370e1be3ca 100644 --- a/stdlib/public/core/StringUnicodeScalarView.swift +++ b/stdlib/public/core/StringUnicodeScalarView.swift @@ -2,7 +2,7 @@ // // This source file is part of the Swift.org open source project // -// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors +// Copyright (c) 2014 - 2020 Apple Inc. and the Swift project authors // Licensed under Apache License v2.0 with Runtime Library Exception // // See https://swift.org/LICENSE.txt for license information @@ -284,7 +284,10 @@ extension String.UnicodeScalarView: RangeReplaceableCollection { public mutating func append(contentsOf newElements: S) where S.Element == Unicode.Scalar { // TODO(String performance): Skip extra String allocation - let scalars = String(decoding: newElements.map { $0.value }, as: UTF32.self) + let scalars = String( + decoding: newElements.map { $0.value }, + as: Unicode.UTF32.self + ) self = (String(self._guts) + scalars).unicodeScalars } @@ -417,7 +420,7 @@ extension String.UnicodeScalarView { internal func _foreignIndex(after i: Index) -> Index { _internalInvariant(_guts.isForeign) let cu = _guts.foreignErrorCorrectedUTF16CodeUnit(at: i) - let len = UTF16.isLeadSurrogate(cu) ? 2 : 1 + let len = Unicode.UTF16.isLeadSurrogate(cu) ? 2 : 1 return i.encoded(offsetBy: len)._scalarAligned } @@ -428,7 +431,7 @@ extension String.UnicodeScalarView { _internalInvariant(_guts.isForeign) let priorIdx = i.priorEncoded let cu = _guts.foreignErrorCorrectedUTF16CodeUnit(at: priorIdx) - let len = UTF16.isTrailSurrogate(cu) ? 2 : 1 + let len = Unicode.UTF16.isTrailSurrogate(cu) ? 2 : 1 return i.encoded(offsetBy: -len)._scalarAligned } diff --git a/stdlib/public/core/ThreadLocalStorage.swift b/stdlib/public/core/ThreadLocalStorage.swift index 7860c0909392c..690a5b344c8e1 100644 --- a/stdlib/public/core/ThreadLocalStorage.swift +++ b/stdlib/public/core/ThreadLocalStorage.swift @@ -2,7 +2,7 @@ // // This source file is part of the Swift.org open source project // -// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors +// Copyright (c) 2014 - 2020 Apple Inc. and the Swift project authors // Licensed under Apache License v2.0 with Runtime Library Exception // // See https://swift.org/LICENSE.txt for license information @@ -96,7 +96,7 @@ internal struct _ThreadLocalStorage { } internal static func getUBreakIterator( - _ bufPtr: UnsafeBufferPointer + _ bufPtr: UnsafeBufferPointer ) -> OpaquePointer { let tlsPtr = getPointer() let brkIter = tlsPtr[0].uBreakIterator @@ -116,7 +116,7 @@ internal struct _ThreadLocalStorage { } internal static func getUBreakIterator( - _ bufPtr: UnsafeBufferPointer + _ bufPtr: UnsafeBufferPointer ) -> OpaquePointer { let tlsPtr = getPointer() let brkIter = tlsPtr[0].uBreakIterator diff --git a/stdlib/public/core/UTF16.swift b/stdlib/public/core/UTF16.swift index 5b6a538d9bd9a..a042e74056bc0 100644 --- a/stdlib/public/core/UTF16.swift +++ b/stdlib/public/core/UTF16.swift @@ -2,7 +2,7 @@ // // This source file is part of the Swift.org open source project // -// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors +// Copyright (c) 2014 - 2020 Apple Inc. and the Swift project authors // Licensed under Apache License v2.0 with Runtime Library Exception // // See https://swift.org/LICENSE.txt for license information @@ -29,13 +29,13 @@ extension Unicode.UTF16 { /// let anA: Unicode.Scalar = "A" /// print(anA.value) /// // Prints "65" - /// print(UTF16.width(anA)) + /// print(Unicode.UTF16.width(anA)) /// // Prints "1" /// /// let anApple: Unicode.Scalar = "🍎" /// print(anApple.value) /// // Prints "127822" - /// print(UTF16.width(anApple)) + /// print(Unicode.UTF16.width(anApple)) /// // Prints "2" /// /// - Parameter x: A Unicode scalar value. @@ -55,17 +55,19 @@ extension Unicode.UTF16 { /// pair*. /// /// let apple: Unicode.Scalar = "🍎" - /// print(UTF16.leadSurrogate(apple)) + /// print(Unicode.UTF16.leadSurrogate(apple)) /// // Prints "55356" /// /// - Parameter x: A Unicode scalar value. `x` must be represented by a /// surrogate pair when encoded in UTF-16. To check whether `x` is - /// represented by a surrogate pair, use `UTF16.width(x) == 2`. + /// represented by a surrogate pair, use `Unicode.UTF16.width(x) == 2`. /// - Returns: The leading surrogate code unit of `x` when encoded in UTF-16. @inlinable - public static func leadSurrogate(_ x: Unicode.Scalar) -> UTF16.CodeUnit { + public static func leadSurrogate( + _ x: Unicode.Scalar + ) -> Unicode.UTF16.CodeUnit { _precondition(width(x) == 2) - return 0xD800 + UTF16.CodeUnit(truncatingIfNeeded: + return 0xD800 + Unicode.UTF16.CodeUnit(truncatingIfNeeded: (x.value - 0x1_0000) &>> (10 as UInt32)) } @@ -79,17 +81,19 @@ extension Unicode.UTF16 { /// pair*. /// /// let apple: Unicode.Scalar = "🍎" - /// print(UTF16.trailSurrogate(apple)) + /// print(Unicode.UTF16.trailSurrogate(apple)) /// // Prints "57166" /// /// - Parameter x: A Unicode scalar value. `x` must be represented by a /// surrogate pair when encoded in UTF-16. To check whether `x` is - /// represented by a surrogate pair, use `UTF16.width(x) == 2`. + /// represented by a surrogate pair, use `Unicode.UTF16.width(x) == 2`. /// - Returns: The trailing surrogate code unit of `x` when encoded in UTF-16. @inlinable - public static func trailSurrogate(_ x: Unicode.Scalar) -> UTF16.CodeUnit { + public static func trailSurrogate( + _ x: Unicode.Scalar + ) -> Unicode.UTF16.CodeUnit { _precondition(width(x) == 2) - return 0xDC00 + UTF16.CodeUnit(truncatingIfNeeded: + return 0xDC00 + Unicode.UTF16.CodeUnit(truncatingIfNeeded: (x.value - 0x1_0000) & (((1 as UInt32) &<< 10) - 1)) } @@ -102,7 +106,7 @@ extension Unicode.UTF16 { /// /// let apple = "🍎" /// for unit in apple.utf16 { - /// print(UTF16.isLeadSurrogate(unit)) + /// print(Unicode.UTF16.isLeadSurrogate(unit)) /// } /// // Prints "true" /// // Prints "false" @@ -129,7 +133,7 @@ extension Unicode.UTF16 { /// /// let apple = "🍎" /// for unit in apple.utf16 { - /// print(UTF16.isTrailSurrogate(unit)) + /// print(Unicode.UTF16.isTrailSurrogate(unit)) /// } /// // Prints "false" /// // Prints "true" @@ -186,9 +190,10 @@ extension Unicode.UTF16 { /// print(Array(bytes)) /// // Prints "[70, 101, 114, 109, 97, 116, 97, 32, 240, 157, 132, 144]" /// - /// let result = UTF16.transcodedLength(of: bytes.makeIterator(), - /// decodedAs: UTF8.self, - /// repairingIllFormedSequences: false) + /// let result = Unicode.UTF16.transcodedLength( + /// of: bytes.makeIterator(), + /// decodedAs: Unicode.UTF8.self, + /// repairingIllFormedSequences: false) /// print(result) /// // Prints "Optional((count: 10, isASCII: false))" /// @@ -233,7 +238,7 @@ extension Unicode.UTF16 { } if _fastPath(peek < 0x80) { return (utf16Count, true) } - var d1 = UTF8.ForwardParser() + var d1 = Unicode.UTF8.ForwardParser() d1._buffer.append(numericCast(peek)) d = _identityCast(d1, to: Encoding.ForwardParser.self) } @@ -250,7 +255,7 @@ extension Unicode.UTF16 { else if let _ = s._error { guard _fastPath(repairingIllFormedSequences) else { return nil } utf16Count += 1 - utf16BitUnion |= UTF16._replacementCodeUnit + utf16BitUnion |= Unicode.UTF16._replacementCodeUnit } else { return (utf16Count, utf16BitUnion < 0x80) @@ -330,8 +335,8 @@ extension Unicode.UTF16: Unicode.Encoding { public static func transcode( _ content: FromEncoding.EncodedScalar, from _: FromEncoding.Type ) -> EncodedScalar? { - if _fastPath(FromEncoding.self == UTF8.self) { - let c = _identityCast(content, to: UTF8.EncodedScalar.self) + if _fastPath(FromEncoding.self == Unicode.UTF8.self) { + let c = _identityCast(content, to: Unicode.UTF8.EncodedScalar.self) var b = c.count b = b &- 1 if _fastPath(b == 0) { @@ -363,8 +368,8 @@ extension Unicode.UTF16: Unicode.Encoding { r &= (1 &<< 21) - 1 return encode(Unicode.Scalar(_unchecked: r)) } - else if _fastPath(FromEncoding.self == UTF16.self) { - return unsafeBitCast(content, to: UTF16.EncodedScalar.self) + else if _fastPath(FromEncoding.self == Unicode.UTF16.self) { + return unsafeBitCast(content, to: Unicode.UTF16.EncodedScalar.self) } return encode(FromEncoding.decode(content)) } @@ -386,7 +391,7 @@ extension Unicode.UTF16: Unicode.Encoding { } } -extension UTF16.ReverseParser: Unicode.Parser, _UTFParser { +extension Unicode.UTF16.ReverseParser: Unicode.Parser, _UTFParser { public typealias Encoding = Unicode.UTF16 @inlinable diff --git a/stdlib/public/core/UTF32.swift b/stdlib/public/core/UTF32.swift index c50a1c5812f35..c63dc27af8d79 100644 --- a/stdlib/public/core/UTF32.swift +++ b/stdlib/public/core/UTF32.swift @@ -2,7 +2,7 @@ // // This source file is part of the Swift.org open source project // -// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors +// Copyright (c) 2014 - 2020 Apple Inc. and the Swift project authors // Licensed under Apache License v2.0 with Runtime Library Exception // // See https://swift.org/LICENSE.txt for license information @@ -66,7 +66,7 @@ extension Unicode.UTF32: Unicode.Encoding { public typealias ReverseParser = Parser } -extension UTF32.Parser: Unicode.Parser { +extension Unicode.UTF32.Parser: Unicode.Parser { public typealias Encoding = Unicode.UTF32 /// Parses a single Unicode scalar value from `input`. @@ -82,7 +82,7 @@ extension UTF32.Parser: Unicode.Parser { else { return .error(length: 1) } // x is a valid scalar. - return .valid(UTF32.EncodedScalar(x)) + return .valid(Encoding.EncodedScalar(x)) } return .emptyInput } diff --git a/stdlib/public/core/UTF8.swift b/stdlib/public/core/UTF8.swift index 9cf22a654e28f..effc9c23eda56 100644 --- a/stdlib/public/core/UTF8.swift +++ b/stdlib/public/core/UTF8.swift @@ -2,7 +2,7 @@ // // This source file is part of the Swift.org open source project // -// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors +// Copyright (c) 2014 - 2020 Apple Inc. and the Swift project authors // Licensed under Apache License v2.0 with Runtime Library Exception // // See https://swift.org/LICENSE.txt for license information @@ -28,13 +28,13 @@ extension Unicode.UTF8 { /// let anA: Unicode.Scalar = "A" /// print(anA.value) /// // Prints "65" - /// print(UTF8.width(anA)) + /// print(Unicode.UTF8.width(anA)) /// // Prints "1" /// /// let anApple: Unicode.Scalar = "🍎" /// print(anApple.value) /// // Prints "127822" - /// print(UTF8.width(anApple)) + /// print(Unicode.UTF8.width(anApple)) /// // Prints "4" /// /// - Parameter x: A Unicode scalar value. @@ -134,8 +134,8 @@ extension Unicode.UTF8: _UnicodeEncoding { public static func transcode( _ content: FromEncoding.EncodedScalar, from _: FromEncoding.Type ) -> EncodedScalar? { - if _fastPath(FromEncoding.self == UTF16.self) { - let c = _identityCast(content, to: UTF16.EncodedScalar.self) + if _fastPath(FromEncoding.self == Unicode.UTF16.self) { + let c = _identityCast(content, to: Unicode.UTF16.EncodedScalar.self) var u0 = UInt16(truncatingIfNeeded: c._storage) if _fastPath(u0 < 0x80) { return EncodedScalar(_containing: UInt8(truncatingIfNeeded: u0)) @@ -155,8 +155,8 @@ extension Unicode.UTF8: _UnicodeEncoding { _biasedBits: (UInt32(u0) | r) &+ 0b0__1000_0001__1000_0001__1110_0001) } } - else if _fastPath(FromEncoding.self == UTF8.self) { - return _identityCast(content, to: UTF8.EncodedScalar.self) + else if _fastPath(FromEncoding.self == Unicode.UTF8.self) { + return _identityCast(content, to: Unicode.UTF8.EncodedScalar.self) } return encode(FromEncoding.decode(content)) } @@ -180,7 +180,7 @@ extension Unicode.UTF8: _UnicodeEncoding { } } -extension UTF8.ReverseParser: Unicode.Parser, _UTFParser { +extension Unicode.UTF8.ReverseParser: Unicode.Parser, _UTFParser { public typealias Encoding = Unicode.UTF8 @inline(__always) @inlinable diff --git a/stdlib/public/core/Unicode.swift b/stdlib/public/core/Unicode.swift index 04b399301627b..77a0ec497103f 100644 --- a/stdlib/public/core/Unicode.swift +++ b/stdlib/public/core/Unicode.swift @@ -2,7 +2,7 @@ // // This source file is part of the Swift.org open source project // -// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors +// Copyright (c) 2014 - 2020 Apple Inc. and the Swift project authors // Licensed under Apache License v2.0 with Runtime Library Exception // // See https://swift.org/LICENSE.txt for license information @@ -83,7 +83,7 @@ public protocol UnicodeCodec: Unicode.Encoding { /// /// var bytesIterator = str.utf8.makeIterator() /// var scalars: [Unicode.Scalar] = [] - /// var utf8Decoder = UTF8() + /// var utf8Decoder = Unicode.UTF8() /// Decode: while true { /// switch utf8Decoder.decode(&bytesIterator) { /// case .scalarValue(let v): scalars.append(v) @@ -115,8 +115,8 @@ public protocol UnicodeCodec: Unicode.Encoding { /// representation. The following code uses the `UTF8` codec to encode a /// fermata in UTF-8: /// - /// var bytes: [UTF8.CodeUnit] = [] - /// UTF8.encode("𝄐", into: { bytes.append($0) }) + /// var bytes: [Unicode.UTF8.CodeUnit] = [] + /// Unicode.UTF8.encode("𝄐", into: { bytes.append($0) }) /// print(bytes) /// // Prints "[240, 157, 132, 144]" /// @@ -165,7 +165,7 @@ extension Unicode.UTF8: UnicodeCodec { /// /// var bytesIterator = str.utf8.makeIterator() /// var scalars: [Unicode.Scalar] = [] - /// var utf8Decoder = UTF8() + /// var utf8Decoder = Unicode.UTF8() /// Decode: while true { /// switch utf8Decoder.decode(&bytesIterator) { /// case .scalarValue(let v): scalars.append(v) @@ -196,7 +196,7 @@ extension Unicode.UTF8: UnicodeCodec { defer { self = ._swift3Buffer(parser) } switch parser.parseScalar(from: &input) { - case .valid(let s): return .scalarValue(UTF8.decode(s)) + case .valid(let s): return .scalarValue(Unicode.UTF8.decode(s)) case .error: return .error case .emptyInput: return .emptyInput } @@ -234,7 +234,7 @@ extension Unicode.UTF8: UnicodeCodec { switch p.parseScalar(from: &i) { case .valid(let s): return ( - result: UTF8.decode(s).value, + result: Unicode.UTF8.decode(s).value, length: UInt8(truncatingIfNeeded: s.count)) case .error(let l): return (result: nil, length: UInt8(truncatingIfNeeded: l)) @@ -249,8 +249,8 @@ extension Unicode.UTF8: UnicodeCodec { /// value (`\u{1D110}`) but requires four code units for its UTF-8 /// representation. The following code encodes a fermata in UTF-8: /// - /// var bytes: [UTF8.CodeUnit] = [] - /// UTF8.encode("𝄐", into: { bytes.append($0) }) + /// var bytes: [Unicode.UTF8.CodeUnit] = [] + /// Unicode.UTF8.encode("𝄐", into: { bytes.append($0) }) /// print(bytes) /// // Prints "[240, 157, 132, 144]" /// @@ -287,7 +287,7 @@ extension Unicode.UTF8: UnicodeCodec { /// /// let eAcute = "Γ©" /// for codeUnit in eAcute.utf8 { - /// print(codeUnit, UTF8.isContinuation(codeUnit)) + /// print(codeUnit, Unicode.UTF8.isContinuation(codeUnit)) /// } /// // Prints "195 false" /// // Prints "169 true" @@ -342,7 +342,7 @@ extension Unicode.UTF16: UnicodeCodec { /// /// var codeUnitIterator = str.utf16.makeIterator() /// var scalars: [Unicode.Scalar] = [] - /// var utf16Decoder = UTF16() + /// var utf16Decoder = Unicode.UTF16() /// Decode: while true { /// switch utf16Decoder.decode(&codeUnitIterator) { /// case .scalarValue(let v): scalars.append(v) @@ -371,7 +371,7 @@ extension Unicode.UTF16: UnicodeCodec { } defer { self = ._swift3Buffer(parser) } switch parser.parseScalar(from: &input) { - case .valid(let s): return .scalarValue(UTF16.decode(s)) + case .valid(let s): return .scalarValue(Unicode.UTF16.decode(s)) case .error: return .error case .emptyInput: return .emptyInput } @@ -387,7 +387,7 @@ extension Unicode.UTF16: UnicodeCodec { let result = decode(&input) switch result { case .scalarValue(let us): - return (result, UTF16.width(us)) + return (result, Unicode.UTF16.width(us)) case .emptyInput: return (result, 0) @@ -404,8 +404,8 @@ extension Unicode.UTF16: UnicodeCodec { /// value (`\u{1D110}`) but requires two code units for its UTF-16 /// representation. The following code encodes a fermata in UTF-16: /// - /// var codeUnits: [UTF16.CodeUnit] = [] - /// UTF16.encode("𝄐", into: { codeUnits.append($0) }) + /// var codeUnits: [Unicode.UTF16.CodeUnit] = [] + /// Unicode.UTF16.encode("𝄐", into: { codeUnits.append($0) }) /// print(codeUnits) /// // Prints "[55348, 56592]" /// @@ -449,12 +449,12 @@ extension Unicode.UTF32: UnicodeCodec { /// its `unicodeScalars` view. /// /// // UTF-32 representation of "✨Unicode✨" - /// let codeUnits: [UTF32.CodeUnit] = + /// let codeUnits: [Unicode.UTF32.CodeUnit] = /// [10024, 85, 110, 105, 99, 111, 100, 101, 10024] /// /// var codeUnitIterator = codeUnits.makeIterator() /// var scalars: [Unicode.Scalar] = [] - /// var utf32Decoder = UTF32() + /// var utf32Decoder = Unicode.UTF32() /// Decode: while true { /// switch utf32Decoder.decode(&codeUnitIterator) { /// case .scalarValue(let v): scalars.append(v) @@ -481,7 +481,7 @@ extension Unicode.UTF32: UnicodeCodec { var parser = ForwardParser() switch parser.parseScalar(from: &input) { - case .valid(let s): return .scalarValue(UTF32.decode(s)) + case .valid(let s): return .scalarValue(Unicode.UTF32.decode(s)) case .error: return .error case .emptyInput: return .emptyInput } @@ -494,8 +494,8 @@ extension Unicode.UTF32: UnicodeCodec { /// can be represented in UTF-32 as a single code unit. The following code /// encodes a fermata in UTF-32: /// - /// var codeUnit: UTF32.CodeUnit = 0 - /// UTF32.encode("𝄐", into: { codeUnit = $0 }) + /// var codeUnit: Unicode.UTF32.CodeUnit = 0 + /// Unicode.UTF32.encode("𝄐", into: { codeUnit = $0 }) /// print(codeUnit) /// // Prints "119056" /// @@ -523,10 +523,13 @@ extension Unicode.UTF32: UnicodeCodec { /// print(Array(bytes)) /// // Prints "[70, 101, 114, 109, 97, 116, 97, 32, 240, 157, 132, 144]" /// -/// var codeUnits: [UTF32.CodeUnit] = [] +/// var codeUnits: [Unicode.UTF32.CodeUnit] = [] /// let sink = { codeUnits.append($0) } -/// transcode(bytes.makeIterator(), from: UTF8.self, to: UTF32.self, -/// stoppingOnError: false, into: sink) +/// transcode(bytes.makeIterator(), +/// from: Unicode.UTF8.self, +/// to: Unicode.UTF32.self, +/// stoppingOnError: false, +/// into: sink) /// print(codeUnits) /// // Prints "[70, 101, 114, 109, 97, 116, 97, 32, 119056]" /// @@ -591,40 +594,36 @@ public func transcode< /// representation. public // @testable protocol _StringElement { - static func _toUTF16CodeUnit(_: Self) -> UTF16.CodeUnit + static func _toUTF16CodeUnit(_ x: Self) -> Unicode.UTF16.CodeUnit - static func _fromUTF16CodeUnit(_ utf16: UTF16.CodeUnit) -> Self + static func _fromUTF16CodeUnit(_ utf16: Unicode.UTF16.CodeUnit) -> Self } -extension UTF16.CodeUnit: _StringElement { +extension Unicode.UTF16.CodeUnit: _StringElement { @inlinable public // @testable - static func _toUTF16CodeUnit(_ x: UTF16.CodeUnit) -> UTF16.CodeUnit { + static func _toUTF16CodeUnit(_ x: Self) -> Unicode.UTF16.CodeUnit { return x } @inlinable public // @testable - static func _fromUTF16CodeUnit( - _ utf16: UTF16.CodeUnit - ) -> UTF16.CodeUnit { + static func _fromUTF16CodeUnit(_ utf16: Unicode.UTF16.CodeUnit) -> Self { return utf16 } } -extension UTF8.CodeUnit: _StringElement { +extension Unicode.UTF8.CodeUnit: _StringElement { @inlinable public // @testable - static func _toUTF16CodeUnit(_ x: UTF8.CodeUnit) -> UTF16.CodeUnit { + static func _toUTF16CodeUnit(_ x: Self) -> Unicode.UTF16.CodeUnit { _internalInvariant(x <= 0x7f, "should only be doing this with ASCII") - return UTF16.CodeUnit(truncatingIfNeeded: x) + return Unicode.UTF16.CodeUnit(truncatingIfNeeded: x) } @inlinable public // @testable - static func _fromUTF16CodeUnit( - _ utf16: UTF16.CodeUnit - ) -> UTF8.CodeUnit { + static func _fromUTF16CodeUnit(_ utf16: Unicode.UTF16.CodeUnit) -> Self { _internalInvariant(utf16 <= 0x7f, "should only be doing this with ASCII") - return UTF8.CodeUnit(truncatingIfNeeded: utf16) + return Self(truncatingIfNeeded: utf16) } } diff --git a/stdlib/public/core/UnicodeHelpers.swift b/stdlib/public/core/UnicodeHelpers.swift index 64e7ea189fd9f..6b383b24c66bd 100644 --- a/stdlib/public/core/UnicodeHelpers.swift +++ b/stdlib/public/core/UnicodeHelpers.swift @@ -2,7 +2,7 @@ // // This source file is part of the Swift.org open source project // -// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors +// Copyright (c) 2014 - 2020 Apple Inc. and the Swift project authors // Licensed under Apache License v2.0 with Runtime Library Exception // // See https://swift.org/LICENSE.txt for license information @@ -16,7 +16,7 @@ @inlinable @inline(__always) internal func _decodeUTF8(_ x: UInt8) -> Unicode.Scalar { - _internalInvariant(UTF8.isASCII(x)) + _internalInvariant(Unicode.UTF8.isASCII(x)) return Unicode.Scalar(_unchecked: UInt32(x)) } @@ -24,7 +24,7 @@ internal func _decodeUTF8(_ x: UInt8) -> Unicode.Scalar { @inline(__always) internal func _decodeUTF8(_ x: UInt8, _ y: UInt8) -> Unicode.Scalar { _internalInvariant(_utf8ScalarLength(x) == 2) - _internalInvariant(UTF8.isContinuation(y)) + _internalInvariant(Unicode.UTF8.isContinuation(y)) let x = UInt32(x) let value = ((x & 0b0001_1111) &<< 6) | _continuationPayload(y) return Unicode.Scalar(_unchecked: value) @@ -36,7 +36,8 @@ internal func _decodeUTF8( _ x: UInt8, _ y: UInt8, _ z: UInt8 ) -> Unicode.Scalar { _internalInvariant(_utf8ScalarLength(x) == 3) - _internalInvariant(UTF8.isContinuation(y) && UTF8.isContinuation(z)) + _internalInvariant(Unicode.UTF8.isContinuation(y)) + _internalInvariant(Unicode.UTF8.isContinuation(z)) let x = UInt32(x) let value = ((x & 0b0000_1111) &<< 12) | (_continuationPayload(y) &<< 6) @@ -50,9 +51,9 @@ internal func _decodeUTF8( _ x: UInt8, _ y: UInt8, _ z: UInt8, _ w: UInt8 ) -> Unicode.Scalar { _internalInvariant(_utf8ScalarLength(x) == 4) - _internalInvariant( - UTF8.isContinuation(y) && UTF8.isContinuation(z) - && UTF8.isContinuation(w)) + _internalInvariant(Unicode.UTF8.isContinuation(y)) + _internalInvariant(Unicode.UTF8.isContinuation(z)) + _internalInvariant(Unicode.UTF8.isContinuation(w)) let x = UInt32(x) let value = ((x & 0b0000_1111) &<< 18) | (_continuationPayload(y) &<< 12) @@ -66,20 +67,20 @@ internal func _decodeScalar( ) -> (Unicode.Scalar, scalarLength: Int) { let high = utf16[i] if i + 1 >= utf16.count { - _internalInvariant(!UTF16.isLeadSurrogate(high)) - _internalInvariant(!UTF16.isTrailSurrogate(high)) + _internalInvariant(!Unicode.UTF16.isLeadSurrogate(high)) + _internalInvariant(!Unicode.UTF16.isTrailSurrogate(high)) return (Unicode.Scalar(_unchecked: UInt32(high)), 1) } - if !UTF16.isLeadSurrogate(high) { - _internalInvariant(!UTF16.isTrailSurrogate(high)) + if !Unicode.UTF16.isLeadSurrogate(high) { + _internalInvariant(!Unicode.UTF16.isTrailSurrogate(high)) return (Unicode.Scalar(_unchecked: UInt32(high)), 1) } let low = utf16[i+1] - _internalInvariant(UTF16.isLeadSurrogate(high)) - _internalInvariant(UTF16.isTrailSurrogate(low)) - return (UTF16._decodeSurrogates(high, low), 2) + _internalInvariant(Unicode.UTF16.isLeadSurrogate(high)) + _internalInvariant(Unicode.UTF16.isTrailSurrogate(low)) + return (Unicode.UTF16._decodeSurrogates(high, low), 2) } @inlinable @@ -116,8 +117,8 @@ internal func _decodeScalar( @inlinable @inline(__always) internal func _utf8ScalarLength(_ x: UInt8) -> Int { - _internalInvariant(!UTF8.isContinuation(x)) - if UTF8.isASCII(x) { return 1 } + _internalInvariant(!Unicode.UTF8.isContinuation(x)) + if Unicode.UTF8.isASCII(x) { return 1 } // TODO(String micro-performance): check codegen return (~x).leadingZeroBitCount } @@ -127,7 +128,7 @@ internal func _utf8ScalarLength( _ utf8: UnsafeBufferPointer, endingAt i: Int ) -> Int { var len = 1 - while UTF8.isContinuation(utf8[_unchecked: i &- len]) { + while Unicode.UTF8.isContinuation(utf8[_unchecked: i &- len]) { len &+= 1 } _internalInvariant(len == _utf8ScalarLength(utf8[i &- len])) @@ -147,7 +148,7 @@ internal func _scalarAlign( guard _fastPath(idx != utf8.count) else { return idx } var i = idx - while _slowPath(UTF8.isContinuation(utf8[_unchecked: i])) { + while _slowPath(Unicode.UTF8.isContinuation(utf8[_unchecked: i])) { i &-= 1 _internalInvariant(i >= 0, "Malformed contents: starts with continuation byte") @@ -216,9 +217,11 @@ extension _StringGuts { _internalInvariant(isFastUTF8) return self.withFastUTF8 { utf8 in - _internalInvariant(i == utf8.count || !UTF8.isContinuation(utf8[i])) + _internalInvariant( + i == utf8.count || !Unicode.UTF8.isContinuation(utf8[i]) + ) var len = 1 - while UTF8.isContinuation(utf8[i &- len]) { + while Unicode.UTF8.isContinuation(utf8[i &- len]) { _internalInvariant(i &- len > 0) len += 1 } @@ -244,7 +247,7 @@ extension _StringGuts { if _fastPath(isFastUTF8) { return self.withFastUTF8 { - return !UTF8.isContinuation($0[i._encodedOffset]) + return !Unicode.UTF8.isContinuation($0[i._encodedOffset]) } } @@ -278,7 +281,7 @@ extension _StringGuts { let start = idx._encodedOffset let leading = _getForeignCodeUnit(at: start) - if _fastPath(!UTF16.isSurrogate(leading)) { + if _fastPath(!Unicode.UTF16.isSurrogate(leading)) { return (Unicode.Scalar(_unchecked: UInt32(leading)), 1) } @@ -288,15 +291,17 @@ extension _StringGuts { // TODO(String performance): Consider having a valid performance flag // available to check, and assert it's not set in the condition here. let nextOffset = start &+ 1 - if _slowPath(UTF16.isTrailSurrogate(leading) || nextOffset == self.count) { + if _slowPath( + Unicode.UTF16.isTrailSurrogate(leading) || nextOffset == self.count + ) { return (Unicode.Scalar._replacementCharacter, 1) } let trailing = _getForeignCodeUnit(at: nextOffset) - if _slowPath(!UTF16.isTrailSurrogate(trailing)) { + if _slowPath(!Unicode.UTF16.isTrailSurrogate(trailing)) { return (Unicode.Scalar._replacementCharacter, 1) } - return (UTF16._decodeSurrogates(leading, trailing), 2) + return (Unicode.UTF16._decodeSurrogates(leading, trailing), 2) } @_effects(releasenone) @@ -309,7 +314,7 @@ extension _StringGuts { let end = idx._encodedOffset let trailing = _getForeignCodeUnit(at: end &- 1) - if _fastPath(!UTF16.isSurrogate(trailing)) { + if _fastPath(!Unicode.UTF16.isSurrogate(trailing)) { return (Unicode.Scalar(_unchecked: UInt32(trailing)), 1) } @@ -319,15 +324,15 @@ extension _StringGuts { // TODO(String performance): Consider having a valid performance flag // available to check, and assert it's not set in the condition here. let priorOffset = end &- 2 - if _slowPath(UTF16.isLeadSurrogate(trailing) || priorOffset < 0) { + if _slowPath(Unicode.UTF16.isLeadSurrogate(trailing) || priorOffset < 0) { return (Unicode.Scalar._replacementCharacter, 1) } let leading = _getForeignCodeUnit(at: priorOffset) - if _slowPath(!UTF16.isLeadSurrogate(leading)) { + if _slowPath(!Unicode.UTF16.isLeadSurrogate(leading)) { return (Unicode.Scalar._replacementCharacter, 1) } - return (UTF16._decodeSurrogates(leading, trailing), 2) + return (Unicode.UTF16._decodeSurrogates(leading, trailing), 2) } @_effects(releasenone) @@ -339,7 +344,7 @@ extension _StringGuts { let start = idx._encodedOffset let cu = _getForeignCodeUnit(at: start) - if _fastPath(!UTF16.isSurrogate(cu)) { + if _fastPath(!Unicode.UTF16.isSurrogate(cu)) { return cu } @@ -348,16 +353,16 @@ extension _StringGuts { // // TODO(String performance): Consider having a valid performance flag // available to check, and assert it's not set in the condition here. - if UTF16.isLeadSurrogate(cu) { + if Unicode.UTF16.isLeadSurrogate(cu) { let nextOffset = start &+ 1 guard nextOffset < self.count, - UTF16.isTrailSurrogate(_getForeignCodeUnit(at: nextOffset)) - else { return UTF16._replacementCodeUnit } + Unicode.UTF16.isTrailSurrogate(_getForeignCodeUnit(at: nextOffset)) + else { return Unicode.UTF16._replacementCodeUnit } } else { let priorOffset = start &- 1 guard priorOffset >= 0, - UTF16.isLeadSurrogate(_getForeignCodeUnit(at: priorOffset)) - else { return UTF16._replacementCodeUnit } + Unicode.UTF16.isLeadSurrogate(_getForeignCodeUnit(at: priorOffset)) + else { return Unicode.UTF16._replacementCodeUnit } } return cu @@ -371,7 +376,7 @@ extension _StringGuts { _internalInvariant(idx._encodedOffset < self.count) let ecCU = foreignErrorCorrectedUTF16CodeUnit(at: idx) - if _fastPath(!UTF16.isTrailSurrogate(ecCU)) { + if _fastPath(!Unicode.UTF16.isTrailSurrogate(ecCU)) { return idx._scalarAligned } _internalInvariant(idx._encodedOffset > 0, diff --git a/stdlib/public/core/UnicodeScalar.swift b/stdlib/public/core/UnicodeScalar.swift index b437eb299dbc4..91e3027c6efe1 100644 --- a/stdlib/public/core/UnicodeScalar.swift +++ b/stdlib/public/core/UnicodeScalar.swift @@ -2,7 +2,7 @@ // // This source file is part of the Swift.org open source project // -// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors +// Copyright (c) 2014 - 2020 Apple Inc. and the Swift project authors // Licensed under Apache License v2.0 with Runtime Library Exception // // See https://swift.org/LICENSE.txt for license information @@ -418,7 +418,7 @@ extension Unicode.Scalar.UTF16View: RandomAccessCollection { /// If the collection is empty, `endIndex` is equal to `startIndex`. @inlinable public var endIndex: Int { - return 0 + UTF16.width(value) + return 0 + Unicode.UTF16.width(value) } /// Accesses the code unit at the specified position. @@ -427,10 +427,10 @@ extension Unicode.Scalar.UTF16View: RandomAccessCollection { /// must be a valid index of the collection that is not equal to the /// `endIndex` property. @inlinable - public subscript(position: Int) -> UTF16.CodeUnit { - if position == 1 { return UTF16.trailSurrogate(value) } - if endIndex == 1 { return UTF16.CodeUnit(value.value) } - return UTF16.leadSurrogate(value) + public subscript(position: Int) -> Unicode.UTF16.CodeUnit { + if position == 1 { return Unicode.UTF16.trailSurrogate(value) } + if endIndex == 1 { return Unicode.UTF16.CodeUnit(value.value) } + return Unicode.UTF16.leadSurrogate(value) } } @@ -464,7 +464,7 @@ extension Unicode.Scalar.UTF8View: RandomAccessCollection { /// /// If the collection is empty, `endIndex` is equal to `startIndex`. @inlinable - public var endIndex: Int { return 0 + UTF8.width(value) } + public var endIndex: Int { return 0 + Unicode.UTF8.width(value) } /// Accesses the code unit at the specified position. /// @@ -472,7 +472,7 @@ extension Unicode.Scalar.UTF8View: RandomAccessCollection { /// must be a valid index of the collection that is not equal to the /// `endIndex` property. @inlinable - public subscript(position: Int) -> UTF8.CodeUnit { + public subscript(position: Int) -> Unicode.UTF8.CodeUnit { _precondition(position >= startIndex && position < endIndex, "Unicode.Scalar.UTF8View index is out of bounds") return value.withUTF8CodeUnits { $0[position] } @@ -481,7 +481,7 @@ extension Unicode.Scalar.UTF8View: RandomAccessCollection { extension Unicode.Scalar { internal static var _replacementCharacter: Unicode.Scalar { - return Unicode.Scalar(_value: UTF32._replacementCodeUnit) + return Unicode.Scalar(_value: Unicode.UTF32._replacementCodeUnit) } } @@ -517,7 +517,7 @@ extension Unicode.Scalar { internal func withUTF8CodeUnits( _ body: (UnsafeBufferPointer) throws -> Result ) rethrows -> Result { - let encodedScalar = UTF8.encode(self)! + let encodedScalar = Unicode.UTF8.encode(self)! var (codeUnits, utf8Count) = encodedScalar._bytes // The first code unit is in the least significant byte of codeUnits. diff --git a/test/Constraints/class.swift b/test/Constraints/class.swift index 565022ade8383..3bec695768a12 100644 --- a/test/Constraints/class.swift +++ b/test/Constraints/class.swift @@ -33,7 +33,7 @@ _ = ternary(true, ef, c) class X { init() {} - init(x:Int, y:UnicodeScalar) {} + init(x:Int, y:Unicode.Scalar) {} } var x0 = X() diff --git a/test/Constraints/construction.swift b/test/Constraints/construction.swift index ac8c185bf5145..a865158e34afb 100644 --- a/test/Constraints/construction.swift +++ b/test/Constraints/construction.swift @@ -10,13 +10,13 @@ struct Y { enum Z { case none - case char(UnicodeScalar) + case char(Unicode.Scalar) case string(String) case point(Int, Int) init() { self = .none } - init(_ c: UnicodeScalar) { self = .char(c) } - // expected-note@-1 2 {{candidate expects value of type 'UnicodeScalar' (aka 'Unicode.Scalar') for parameter #1}} + init(_ c: Unicode.Scalar) { self = .char(c) } + // expected-note@-1 2 {{candidate expects value of type 'Unicode.Scalar' for parameter #1}} init(_ s: String) { self = .string(s) } // expected-note@-1 2 {{candidate expects value of type 'String' for parameter #1}} init(_ x: Int, _ y: Int) { self = .point(x, y) } @@ -49,7 +49,7 @@ X(i: 1, j: 2) // expected-warning{{unused}} Y(1, 2, "hello") // expected-warning{{unused}} // Unions -Z(UnicodeScalar("a")) // expected-warning{{unused}} +Z(Unicode.Scalar("a")) // expected-warning{{unused}} Z(1, 2) // expected-warning{{unused}} acceptZ(.none) diff --git a/test/Constraints/default_literals.swift b/test/Constraints/default_literals.swift index f52e85ec2ac62..a447b11ead773 100644 --- a/test/Constraints/default_literals.swift +++ b/test/Constraints/default_literals.swift @@ -27,7 +27,7 @@ var d = 3.5 genericFloatingLiteral(d) extension UInt32 { - func asChar() -> UnicodeScalar { return UnicodeScalar(self)! } + func asChar() -> Unicode.Scalar { return Unicode.Scalar(self)! } } var ch = UInt32(65).asChar() diff --git a/test/Constraints/generics.swift b/test/Constraints/generics.swift index bb4ed1d14f0f1..7d8536e367087 100644 --- a/test/Constraints/generics.swift +++ b/test/Constraints/generics.swift @@ -21,7 +21,7 @@ func weirdConcat(_ t: T, u: U) { var b1, b2 : Bool _ = b1 != b2 -extension UnicodeScalar { +extension Unicode.Scalar { func isAlpha2() -> Bool { return (self >= "A" && self <= "Z") || (self >= "a" && self <= "z") } diff --git a/test/Constraints/nested_generics.swift b/test/Constraints/nested_generics.swift index 4f1f59e5ebbea..997c3153c92a1 100644 --- a/test/Constraints/nested_generics.swift +++ b/test/Constraints/nested_generics.swift @@ -13,7 +13,7 @@ struct G { } typealias GInt = G -typealias GChar = G +typealias GChar = G GInt(x: GChar()) // expected-warning{{unused}} GInt().foo(GChar()) diff --git a/test/Constraints/super_constructor.swift b/test/Constraints/super_constructor.swift index d6976b7ec010f..7eb43c8c4d0b0 100644 --- a/test/Constraints/super_constructor.swift +++ b/test/Constraints/super_constructor.swift @@ -42,9 +42,9 @@ class B { init(x:Int) { // expected-note{{candidate expects value of type 'Int' for parameter #1}} } - init(a:UnicodeScalar) { // expected-note {{candidate expects value of type 'UnicodeScalar' (aka 'Unicode.Scalar') for parameter #1}} + init(a:Unicode.Scalar) { // expected-note {{candidate expects value of type 'Unicode.Scalar' for parameter #1}} } - init(b:UnicodeScalar) { // expected-note {{candidate expects value of type 'UnicodeScalar' (aka 'Unicode.Scalar') for parameter #1}} + init(b:Unicode.Scalar) { // expected-note {{candidate expects value of type 'Unicode.Scalar' for parameter #1}} } init(z:Float) { // expected-note{{candidate expects value of type 'Float' for parameter #1}} diff --git a/test/Constraints/super_method.swift b/test/Constraints/super_method.swift index 0e098e903df2b..9546d33deb5e6 100644 --- a/test/Constraints/super_method.swift +++ b/test/Constraints/super_method.swift @@ -11,7 +11,7 @@ class D : B { override func bar(_ a: Float) -> Int { return super.bar(a) } - func bas() -> (Int, UnicodeScalar, String) { + func bas() -> (Int, Unicode.Scalar, String) { return (super.zim(), super.zang(), super.zung()) } @@ -29,7 +29,7 @@ class B { func bar(_ a: Float) -> Int {} func zim() -> Int {} - func zang() -> UnicodeScalar {} + func zang() -> Unicode.Scalar {} func zung() -> String {} var zippity : Int { return 123 } diff --git a/test/Interpreter/constructor.swift b/test/Interpreter/constructor.swift index bb05e0ca51212..15ddb273c5927 100644 --- a/test/Interpreter/constructor.swift +++ b/test/Interpreter/constructor.swift @@ -31,7 +31,7 @@ A(1) // CHECK: c A(1, "2") -typealias BChar = B +typealias BChar = B // CHECK: d BChar() // CHECK: e diff --git a/test/Interpreter/enum.swift b/test/Interpreter/enum.swift index da9f6c4b17cf6..2ae3a904b1e3e 100644 --- a/test/Interpreter/enum.swift +++ b/test/Interpreter/enum.swift @@ -5,7 +5,7 @@ // REQUIRES: executable_test enum Singleton { - case x(Int, UnicodeScalar) + case x(Int, Unicode.Scalar) } enum NoPayload { @@ -15,13 +15,13 @@ enum NoPayload { } enum SinglePayloadTrivial { - case x(UnicodeScalar, Int) + case x(Unicode.Scalar, Int) case y case z } enum MultiPayloadTrivial { - case x(UnicodeScalar, Int) + case x(Unicode.Scalar, Int) case y(Int, Double) case z } diff --git a/test/Interpreter/extended_grapheme_cluster_literal.swift b/test/Interpreter/extended_grapheme_cluster_literal.swift index a4fc2c8a675d6..af2f21d43cecb 100644 --- a/test/Interpreter/extended_grapheme_cluster_literal.swift +++ b/test/Interpreter/extended_grapheme_cluster_literal.swift @@ -18,7 +18,7 @@ private struct Expressible } public func string(_ characters: UInt32...) -> String { - return String(characters.map { Character(UnicodeScalar($0)!) }) + return String(characters.map { Character(Unicode.Scalar($0)!) }) } private func expressible(_ literal: Expressible, as type: T.Type) -> String where T: CustomStringConvertible { diff --git a/test/Interpreter/simple.swift b/test/Interpreter/simple.swift index 8faeba7dbc28b..ea56e960ee16d 100644 --- a/test/Interpreter/simple.swift +++ b/test/Interpreter/simple.swift @@ -7,11 +7,11 @@ if (true) { print(123, terminator: "") - print(UnicodeScalar(65)!, terminator: "") - print(UnicodeScalar(66)!, terminator: "") - print(UnicodeScalar(67)!, terminator: "") - print(UnicodeScalar(0o104)!, terminator: "") - print(UnicodeScalar(10)!, terminator: "") + print(Unicode.Scalar(65)!, terminator: "") + print(Unicode.Scalar(66)!, terminator: "") + print(Unicode.Scalar(67)!, terminator: "") + print(Unicode.Scalar(0o104)!, terminator: "") + print(Unicode.Scalar(10)!, terminator: "") print("Hello \u{2603}\n", terminator: "") // Hi Snowman! print("Hello β˜ƒ\n", terminator: "") } diff --git a/test/Interpreter/string_literal.swift b/test/Interpreter/string_literal.swift index 63e24b50f07c1..cbd5a401ade89 100644 --- a/test/Interpreter/string_literal.swift +++ b/test/Interpreter/string_literal.swift @@ -17,7 +17,7 @@ private struct Expressible } private func string(_ characters: UInt32...) -> String { - return String(characters.map { Character(UnicodeScalar($0)!) }) + return String(characters.map { Character(Unicode.Scalar($0)!) }) } private func expressible(_ literal: Expressible, as type: T.Type) -> String where T: CustomStringConvertible { diff --git a/test/Interpreter/super_constructor.swift b/test/Interpreter/super_constructor.swift index fe83befd2f5c5..669c143616714 100644 --- a/test/Interpreter/super_constructor.swift +++ b/test/Interpreter/super_constructor.swift @@ -7,7 +7,7 @@ struct S { self.a = a self.b = b } - init(_ x:UnicodeScalar) { + init(_ x: Unicode.Scalar) { a = 219 b = 912 print("constructed \(x)") @@ -16,7 +16,7 @@ struct S { class C { var a, b : Int - init(x:UnicodeScalar) { + init(x: Unicode.Scalar) { a = 20721 b = 12702 print("constructed \(x)") diff --git a/test/Interpreter/unicode_scalar_literal.swift b/test/Interpreter/unicode_scalar_literal.swift index 797397ca29b8b..9efeb6aeabfbe 100644 --- a/test/Interpreter/unicode_scalar_literal.swift +++ b/test/Interpreter/unicode_scalar_literal.swift @@ -17,7 +17,7 @@ private struct Expressible } private func string(_ characters: UInt32...) -> String { - return String(characters.map { Character(UnicodeScalar($0)!) }) + return String(characters.map { Character(Unicode.Scalar($0)!) }) } private func expressible(_ literal: Expressible, as type: T.Type) -> String where T: CustomStringConvertible { @@ -46,10 +46,10 @@ testSuite.test("Character literal type") { expectEqual(expressible("𝔹", as: Character.self), 𝔹) } -testSuite.test("UnicodeScalar literal type") { - expectEqual(expressible("b", as: UnicodeScalar.self), b) - expectEqual(expressible("Ξ²", as: UnicodeScalar.self), Ξ²) - expectEqual(expressible("𝔹", as: UnicodeScalar.self), 𝔹) +testSuite.test("Unicode.Scalar literal type") { + expectEqual(expressible("b", as: Unicode.Scalar.self), b) + expectEqual(expressible("Ξ²", as: Unicode.Scalar.self), Ξ²) + expectEqual(expressible("𝔹", as: Unicode.Scalar.self), 𝔹) } runAllTests() diff --git a/test/Interpreter/writeback.swift b/test/Interpreter/writeback.swift index 1a93db5affb81..ad92b1084fa36 100644 --- a/test/Interpreter/writeback.swift +++ b/test/Interpreter/writeback.swift @@ -2,9 +2,9 @@ // REQUIRES: executable_test struct Foo { - var _x : (Int, UnicodeScalar, String) + var _x : (Int, Unicode.Scalar, String) - var x : (Int, String, UnicodeScalar) { + var x : (Int, String, Unicode.Scalar) { get { var (a, b, c) = _x return (a, c, b) @@ -17,7 +17,7 @@ struct Foo { } } - init(a:Int, b:String, c:UnicodeScalar) { + init(a:Int, b:String, c:Unicode.Scalar) { _x = (a, c, b) } } diff --git a/test/Parse/enum.swift b/test/Parse/enum.swift index 83bee6d5464a3..3e0a23c521c54 100644 --- a/test/Parse/enum.swift +++ b/test/Parse/enum.swift @@ -184,7 +184,7 @@ enum RawTypeWithNegativeValues : Int { case AutoIncAcrossZero = -1, Zero, One } -enum RawTypeWithUnicodeScalarValues : UnicodeScalar { // expected-error {{'RawTypeWithUnicodeScalarValues' declares raw type 'UnicodeScalar' (aka 'Unicode.Scalar'), but does not conform to RawRepresentable and conformance could not be synthesized}} +enum RawTypeWithUnicodeScalarValues : Unicode.Scalar { // expected-error {{'RawTypeWithUnicodeScalarValues' declares raw type 'Unicode.Scalar', but does not conform to RawRepresentable and conformance could not be synthesized}} case Kearney = "K" case Lovejoy // expected-error {{enum cases require explicit raw values when the raw type is not expressible by integer or string literal}} case Marshall = "M" diff --git a/test/Parse/generic_disambiguation.swift b/test/Parse/generic_disambiguation.swift index ebb900e3e8c47..de12297e71666 100644 --- a/test/Parse/generic_disambiguation.swift +++ b/test/Parse/generic_disambiguation.swift @@ -42,8 +42,8 @@ A.F>.c() A<(A) -> B>.c() A<[[Int]]>.c() A<[[A]]>.c() -A<(Int, UnicodeScalar)>.c() -A<(a:Int, b:UnicodeScalar)>.c() +A<(Int, Unicode.Scalar)>.c() +A<(a:Int, b:Unicode.Scalar)>.c() A.c() A<@convention(c) () -> Int32>.c() A<(@autoclosure @escaping () -> Int, Int) -> Void>.c() diff --git a/test/Prototypes/PatternMatching.swift b/test/Prototypes/PatternMatching.swift index 33065d4a3729e..d7ca0716929f2 100644 --- a/test/Prototypes/PatternMatching.swift +++ b/test/Prototypes/PatternMatching.swift @@ -269,7 +269,7 @@ func | (m0: M0, m1: M1) -> MatchOneOf { //===--- Just for testing -------------------------------------------------===// struct MatchStaticString : Pattern { - typealias Element = UTF8.CodeUnit + typealias Element = Unicode.UTF8.CodeUnit typealias Buffer = UnsafeBufferPointer typealias Index = Buffer.Index @@ -296,9 +296,9 @@ extension StaticString { } } -extension Collection where Iterator.Element == UTF8.CodeUnit { +extension Collection where Iterator.Element == Unicode.UTF8.CodeUnit { var u8str : String { - var a = Array() + var a = Array() a.reserveCapacity(count + 1) a.append(contentsOf: self) a.append(0) @@ -306,7 +306,7 @@ extension Collection where Iterator.Element == UTF8.CodeUnit { } } -extension Pattern where Element == UTF8.CodeUnit { +extension Pattern where Element == Unicode.UTF8.CodeUnit { func searchTest( in c: C, format: (MatchData)->String = { String(reflecting: $0) }) diff --git a/test/Prototypes/TextFormatting.swift b/test/Prototypes/TextFormatting.swift index 6ab0d1ee5859c..dbc718a4e23d5 100644 --- a/test/Prototypes/TextFormatting.swift +++ b/test/Prototypes/TextFormatting.swift @@ -194,9 +194,9 @@ public struct IntegerFormat : TextOutputStreamable { let nDigits = _writePositive(rest, &stream) let digit = UInt32(value % radix) let baseCharOrd : UInt32 = digit <= 9 - ? UnicodeScalar("0").value - : UnicodeScalar("A").value - 10 - stream.write(String(UnicodeScalar(baseCharOrd + digit)!)) + ? Unicode.Scalar("0").value + : Unicode.Scalar("A").value - 10 + stream.write(String(Unicode.Scalar(baseCharOrd + digit)!)) return nDigits + 1 } diff --git a/test/Prototypes/UnicodeDecoders.swift b/test/Prototypes/UnicodeDecoders.swift index cbfc2ffd19191..b584d5ae0b145 100644 --- a/test/Prototypes/UnicodeDecoders.swift +++ b/test/Prototypes/UnicodeDecoders.swift @@ -2,7 +2,7 @@ // // This source file is part of the Swift.org open source project // -// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors +// Copyright (c) 2014 - 2020 Apple Inc. and the Swift project authors // Licensed under Apache License v2.0 with Runtime Library Exception // // See https://swift.org/LICENSE.txt for license information @@ -291,7 +291,7 @@ func checkStringProtocol( } } -func checkDecodeUTF( +func checkDecodeUTF( _ codec: Codec.Type, _ expectedHead: [UInt32], _ expectedRepairedTail: [UInt32], _ utfStr: [Codec.CodeUnit] ) -> AssertionResult { diff --git a/test/SILGen/expressions.swift b/test/SILGen/expressions.swift index e37e4a85bfba6..c614433cce5fa 100644 --- a/test/SILGen/expressions.swift +++ b/test/SILGen/expressions.swift @@ -212,7 +212,7 @@ func generic_member_ref(_ x: Generic) -> Int { } // CHECK-LABEL: sil hidden [ossa] @$s11expressions24bound_generic_member_ref{{[_0-9a-zA-Z]*}}F -func bound_generic_member_ref(_ x: Generic) -> Int { +func bound_generic_member_ref(_ x: Generic) -> Int { var x = x // CHECK: bb0([[XADDR:%[0-9]+]] : $Generic): return x.mono_member @@ -376,9 +376,9 @@ func declref_to_metatype() -> Spoon.Type { } // CHECK-LABEL: sil hidden [ossa] @$s11expressions27declref_to_generic_metatype{{[_0-9a-zA-Z]*}}F -func declref_to_generic_metatype() -> Generic.Type { +func declref_to_generic_metatype() -> Generic.Type { // FIXME parsing of T in expression context - typealias GenericChar = Generic + typealias GenericChar = Generic return GenericChar.self // CHECK: metatype $@thin Generic.Type } diff --git a/test/SILGen/mangling.swift b/test/SILGen/mangling.swift index 2d401ff78c260..f056b58d37a78 100644 --- a/test/SILGen/mangling.swift +++ b/test/SILGen/mangling.swift @@ -83,7 +83,7 @@ func uses_objc_class_and_protocol(o: NSObject, p: NSAnsing, p2: BetterAnsing) {} func uses_clang_struct(r: NSRect) {} // CHECK-LABEL: sil hidden [ossa] @$s8mangling14uses_optionals1xs7UnicodeO6ScalarVSgSiSg_tF -func uses_optionals(x: Int?) -> UnicodeScalar? { return nil } +func uses_optionals(x: Int?) -> Unicode.Scalar? { return nil } struct HasVarInit { static var state = true && false diff --git a/test/SILGen/properties.swift b/test/SILGen/properties.swift index 90890a41048cc..a9c4058bef2e2 100644 --- a/test/SILGen/properties.swift +++ b/test/SILGen/properties.swift @@ -427,13 +427,13 @@ func generic_mono_subscript_set(_ g: inout Generic, i: Int, x: Float) { } // CHECK-LABEL: sil hidden [ossa] @{{.*}}bound_generic_mono_phys_get -func bound_generic_mono_phys_get(_ g: inout Generic, x: Int) -> Int { +func bound_generic_mono_phys_get(_ g: inout Generic, x: Int) -> Int { return g.mono_phys // CHECK: struct_element_addr %{{.*}}, #Generic.mono_phys } // CHECK-LABEL: sil hidden [ossa] @$s10properties26bound_generic_mono_log_get{{[_0-9a-zA-Z]*}}F -func bound_generic_mono_log_get(_ g: Generic, x: Int) -> Int { +func bound_generic_mono_log_get(_ g: Generic, x: Int) -> Int { return g.mono_log // CHECK: [[GENERIC_GET_METHOD:%[0-9]+]] = function_ref @$s10properties7GenericV8mono_log{{[_0-9a-zA-Z]*}}vg // CHECK: apply [[GENERIC_GET_METHOD]]< diff --git a/test/SILOptimizer/utf8_decoding_fastpath.swift b/test/SILOptimizer/utf8_decoding_fastpath.swift index a77cd0cae3b87..81ce5442f462f 100644 --- a/test/SILOptimizer/utf8_decoding_fastpath.swift +++ b/test/SILOptimizer/utf8_decoding_fastpath.swift @@ -176,7 +176,7 @@ public struct CustomNonContiguousCollection: Collection { // CHECK-NOT: function_ref {{.*}}_fromCodeUnits // CHECK-LABEL: end sil function{{.*}}decodeCustomContiguousAsUTF8 public func decodeCustomContiguousAsUTF8(_ c: CustomContiguousCollection) -> String { - return String(decoding: c, as: UTF8.self) + return String(decoding: c, as: Unicode.UTF8.self) } // CustomNonContiguousCollection @@ -189,13 +189,13 @@ public func decodeCustomContiguousAsUTF8(_ c: CustomContiguousCollection) -> Str // CHECK-NOT: function_ref {{.*}}_fromUTF8Repairing // CHECK-LABEL: end sil function{{.*}}decodeCustomNonContiguousAsUTF8 public func decodeCustomNonContiguousAsUTF8(_ c: CustomNonContiguousCollection) -> String { - return String(decoding: c, as: UTF8.self) + return String(decoding: c, as: Unicode.UTF8.self) } // UTF-16 // // NOTE: The SIL optimizer cannot currently fold away a (UTF16.self == -// UTF8.self) metatype comparison, so we have to disabel the check-not for UTF-8 +// UTF8.self) metatype comparison, so we have to disable the check-not for UTF-8 // construction :-( // // CHECK-LABEL: sil {{.*}}decodeUTF16{{.*}} : $@convention @@ -206,5 +206,5 @@ public func decodeCustomNonContiguousAsUTF8(_ c: CustomNonContiguousCollection) // xCHECK-NOT: function_ref {{.*}}_fromNonContiguousUnsafeBitcastUTF8Repairing // CHECK-LABEL: end sil function{{.*}}decodeUTF16 public func decodeUTF16(_ c: Array) -> String { - return String(decoding: c, as: UTF16.self) + return String(decoding: c, as: Unicode.UTF16.self) } diff --git a/test/SourceKit/CodeFormat/indent-bracestmt.swift b/test/SourceKit/CodeFormat/indent-bracestmt.swift index 74c8d85d28f4a..d6468f7244466 100644 --- a/test/SourceKit/CodeFormat/indent-bracestmt.swift +++ b/test/SourceKit/CodeFormat/indent-bracestmt.swift @@ -18,7 +18,7 @@ class Foo { func Foo1() { let msg = String([65, 108, 105, 103, 110].map { c in - Character(UnicodeScalar(c)) + Character(Unicode.Scalar(c)) }) } diff --git a/test/decl/subscript/subscripting.swift b/test/decl/subscript/subscripting.swift index 667f8e511ca42..04c65cf0ad8a0 100644 --- a/test/decl/subscript/subscripting.swift +++ b/test/decl/subscript/subscripting.swift @@ -276,7 +276,7 @@ func subscript_rvalue_materialize(_ i: inout Int) { i = X1(stored: 0)[i] } -func subscript_coerce(_ fn: ([UnicodeScalar], [UnicodeScalar]) -> Bool) {} +func subscript_coerce(_ fn: ([Unicode.Scalar], [Unicode.Scalar]) -> Bool) {} func test_subscript_coerce() { subscript_coerce({ $0[$0.count-1] < $1[$1.count-1] }) } diff --git a/test/decl/var/properties.swift b/test/decl/var/properties.swift index 185168cb953d4..e471bc424fea3 100644 --- a/test/decl/var/properties.swift +++ b/test/decl/var/properties.swift @@ -573,13 +573,13 @@ func test_settable_of_nonsettable(_ a: Aleph) { struct MonoStruct { static var foo: Int = 0 - static var (bar, bas): (String, UnicodeScalar) = ("zero", "0") + static var (bar, bas): (String, Unicode.Scalar) = ("zero", "0") static var zim: UInt8 { return 0 } - static var zang = UnicodeScalar("\0") + static var zang = Unicode.Scalar("\0") static var zung: UInt16 { get { @@ -616,7 +616,7 @@ protocol Proto { static var foo: Int { get } } -func staticPropRefs() -> (Int, Int, String, UnicodeScalar, UInt8) { +func staticPropRefs() -> (Int, Int, String, Unicode.Scalar, UInt8) { return (MonoStruct.foo, MonoEnum.foo, MonoStruct.bar, MonoStruct.bas, MonoStruct.zim) } diff --git a/test/expr/primary/literal/string.swift b/test/expr/primary/literal/string.swift index 4244cd2fa921f..c0acc6ce14539 100644 --- a/test/expr/primary/literal/string.swift +++ b/test/expr/primary/literal/string.swift @@ -26,7 +26,7 @@ func verify( with: T.Type) { } -verify(unicodeScalarLiteral: "Γ₯", with: UnicodeScalar.self) +verify(unicodeScalarLiteral: "Γ₯", with: Unicode.Scalar.self) verify(unicodeScalarLiteral: "ß", with: Character.self) verify(unicodeScalarLiteral: "c", with: String.self) verify(unicodeScalarLiteral: "βˆ‚", with: StaticString.self) diff --git a/test/stdlib/Character.swift b/test/stdlib/Character.swift index 19ecd73256f0e..5dde791a9061d 100644 --- a/test/stdlib/Character.swift +++ b/test/stdlib/Character.swift @@ -14,7 +14,7 @@ import SwiftPrivate // // These scalars should be "base characters" with regards to their position in // a grapheme cluster. -let baseScalars: [UnicodeScalar] = [ +let baseScalars: [Unicode.Scalar] = [ // U+0065 LATIN SMALL LETTER E "\u{0065}", @@ -54,7 +54,7 @@ let baseScalars: [UnicodeScalar] = [ // Single Unicode scalars that are "continuing characters" with regards to // their position in a grapheme cluster. -let continuingScalars: [UnicodeScalar] = [ +let continuingScalars: [Unicode.Scalar] = [ // U+0300 COMBINING GRAVE ACCENT "\u{0300}", @@ -316,7 +316,7 @@ CharacterTests.test("RoundTripping/Random") { CharacterTests.test("forall x: ASCII . String(Character(x)) == String(x)") { // For all ASCII chars, constructing a Character then a String should be the // same as constructing a String directly. - let asciiDomain = (0..<128).map({ UnicodeScalar(Int($0))! }) + let asciiDomain = (0..<128).map({ Unicode.Scalar(Int($0))! }) expectEqualFunctionsForDomain(asciiDomain, { String($0) }, { String(Character($0)) }) @@ -327,8 +327,8 @@ CharacterTests.test( // For all ASCII chars, constructing a Character then a String should ordered // the same as constructing a String directly. let asciiDomain = Array(0..<127) - let ascii0to126 = asciiDomain.map({ UnicodeScalar(Int($0))! }) - let ascii1to127 = asciiDomain.map({ UnicodeScalar(Int($0 + 1))! }) + let ascii0to126 = asciiDomain.map({ Unicode.Scalar(Int($0))! }) + let ascii1to127 = asciiDomain.map({ Unicode.Scalar(Int($0 + 1))! }) expectEqualMethodsForDomain( ascii0to126, ascii1to127, @@ -364,7 +364,7 @@ var UnicodeScalarTests = TestSuite("UnicodeScalar") UnicodeScalarTests.test("UInt8(ascii: UnicodeScalar)") { for i in 0..<0x7f { - let us = UnicodeScalar(i)! + let us = Unicode.Scalar(i)! expectEqual(UInt8(i), UInt8(ascii: us)) } } @@ -374,7 +374,7 @@ UnicodeScalarTests.test("UInt8(ascii: UnicodeScalar)/non-ASCII should trap") { _isFastAssertConfiguration() }, reason: "this trap is not guaranteed to happen in -Ounchecked")) .code { - let us: UnicodeScalar = "\u{E5}" + let us: Unicode.Scalar = "\u{E5}" expectCrashLater() _blackHole(UInt8(ascii: us)) } @@ -387,17 +387,17 @@ UnicodeScalarTests.test("UInt32(_: UnicodeScalar),UInt64(_: UnicodeScalar)") { } UnicodeScalarTests.test("isASCII()") { - expectTrue(UnicodeScalar(0)!.isASCII) - expectTrue(("A" as UnicodeScalar).isASCII) - expectTrue(UnicodeScalar(127)!.isASCII) - expectFalse(UnicodeScalar(128)!.isASCII) - expectFalse(UnicodeScalar(256)!.isASCII) + expectTrue(Unicode.Scalar(0)!.isASCII) + expectTrue(("A" as Unicode.Scalar).isASCII) + expectTrue(Unicode.Scalar(127)!.isASCII) + expectFalse(Unicode.Scalar(128)!.isASCII) + expectFalse(Unicode.Scalar(256)!.isASCII) } UnicodeScalarTests.test("Comparable") { // FIXME: these tests are insufficient. - let CharA: UnicodeScalar = "A" + let CharA: Unicode.Scalar = "A" expectTrue(CharA == "A") expectTrue("A" == CharA) @@ -413,8 +413,8 @@ UnicodeScalarTests.test("Comparable") { UnicodeScalarTests.test("LosslessStringConvertible") { // FIXME: these tests are insufficient. - checkLosslessStringConvertible((0xE000...0xF000).map { UnicodeScalar(Int($0))! }) - checkLosslessStringConvertible((0...127).map { UnicodeScalar(Int($0))! }) + checkLosslessStringConvertible((0xE000...0xF000).map { Unicode.Scalar(Int($0))! }) + checkLosslessStringConvertible((0...127).map { Unicode.Scalar(Int($0))! }) } if #available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *) { diff --git a/test/stdlib/Mirror.swift b/test/stdlib/Mirror.swift index 4755be399ad11..f8323b58615ba 100644 --- a/test/stdlib/Mirror.swift +++ b/test/stdlib/Mirror.swift @@ -2,7 +2,7 @@ // // This source file is part of the Swift.org open source project // -// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors +// Copyright (c) 2014 - 2020 Apple Inc. and the Swift project authors // Licensed under Apache License v2.0 with Runtime Library Exception // // See https://swift.org/LICENSE.txt for license information @@ -1772,7 +1772,7 @@ mirrors.test("Character/Mirror") { mirrors.test("UnicodeScalar") { do { // U+0061 LATIN SMALL LETTER A - let input: UnicodeScalar = "\u{61}" + let input: Unicode.Scalar = "\u{61}" var output = "" dump(input, to: &output) @@ -1784,7 +1784,7 @@ mirrors.test("UnicodeScalar") { do { // U+304B HIRAGANA LETTER KA - let input: UnicodeScalar = "\u{304b}" + let input: Unicode.Scalar = "\u{304b}" var output = "" dump(input, to: &output) @@ -1796,7 +1796,7 @@ mirrors.test("UnicodeScalar") { do { // U+3099 COMBINING KATAKANA-HIRAGANA VOICED SOUND MARK - let input: UnicodeScalar = "\u{3099}" + let input: Unicode.Scalar = "\u{3099}" var output = "" dump(input, to: &output) @@ -1808,7 +1808,7 @@ mirrors.test("UnicodeScalar") { do { // U+1F425 FRONT-FACING BABY CHICK - let input: UnicodeScalar = "\u{1f425}" + let input: Unicode.Scalar = "\u{1f425}" var output = "" dump(input, to: &output) diff --git a/test/stdlib/NSSlowString.swift b/test/stdlib/NSSlowString.swift index d45c55f214b12..3a788503468cc 100644 --- a/test/stdlib/NSSlowString.swift +++ b/test/stdlib/NSSlowString.swift @@ -80,7 +80,7 @@ tests.test("Zalgo") // Check that we handle absurdly long graphemes var zalgo = "aπŸ‘©β€πŸ‘©β€πŸ‘§β€πŸ‘¦c" for combo in 0x300...0x36f { - zalgo.append(String(UnicodeScalar(combo)!)) + zalgo.append(String(Unicode.Scalar(combo)!)) } check( NSSlowString(string: zalgo) as String, diff --git a/test/stdlib/PrintString.swift b/test/stdlib/PrintString.swift index 69d835e4034a6..9486679f9a637 100644 --- a/test/stdlib/PrintString.swift +++ b/test/stdlib/PrintString.swift @@ -22,16 +22,16 @@ PrintTests.test("Printable") { expectPrinted("a", ch) expectDebugPrinted("\"a\"", ch) - let us0: UnicodeScalar = "a" + let us0: Unicode.Scalar = "a" expectPrinted("a", us0) expectDebugPrinted("\"a\"", us0) - let us1: UnicodeScalar = "\\" + let us1: Unicode.Scalar = "\\" expectPrinted("\\", us1) expectEqual("\"\\\\\"", us1.description) expectDebugPrinted("\"\\\\\"", us1) - let us2: UnicodeScalar = "あ" + let us2: Unicode.Scalar = "あ" expectPrinted("あ", us2) expectEqual("\"あ\"", us2.description) expectDebugPrinted("\"\\u{3042}\"", us2) diff --git a/test/stdlib/RangeDiagnostics.swift b/test/stdlib/RangeDiagnostics.swift index 3f4d165082fea..e9b3f40c5344d 100644 --- a/test/stdlib/RangeDiagnostics.swift +++ b/test/stdlib/RangeDiagnostics.swift @@ -2,7 +2,7 @@ // // This source file is part of the Swift.org open source project // -// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors +// Copyright (c) 2014 - 2020 Apple Inc. and the Swift project authors // Licensed under Apache License v2.0 with Runtime Library Exception // // See https://swift.org/LICENSE.txt for license information @@ -144,8 +144,8 @@ func typeInference_commonTypes() { expectType(Range.self, &range) } do { - var range = UnicodeScalar("a")..<"z" - expectType(Range.self, &range) + var range = Unicode.Scalar("a")..<"z" + expectType(Range.self, &range) } do { let s = "" @@ -225,8 +225,8 @@ func typeInference_commonTypes() { expectType(ClosedRange.self, &range) } do { - var range = UnicodeScalar("a")..."z" - expectType(ClosedRange.self, &range) + var range = Unicode.Scalar("a")..."z" + expectType(ClosedRange.self, &range) } do { let s = "" diff --git a/test/stdlib/StringAPI.swift b/test/stdlib/StringAPI.swift index 47ee8c50667ea..be4c850b2f758 100644 --- a/test/stdlib/StringAPI.swift +++ b/test/stdlib/StringAPI.swift @@ -392,7 +392,7 @@ StringTests.test("Regression/corelibs-foundation") { //The CRLF ("\r\n") sequence is also treated like a surrogate pair, but its constinuent //characters "\r" and "\n" can exist outside the pair! - let replacementCharacter = String(describing: UnicodeScalar(0xFFFD)!) + let replacementCharacter = String(describing: Unicode.Scalar(0xFFFD)!) let CR: UInt16 = 13 //carriage return let LF: UInt16 = 10 //new line diff --git a/test/stdlib/StringAPICString.swift b/test/stdlib/StringAPICString.swift index be062847c6455..d8cf57100c13c 100644 --- a/test/stdlib/StringAPICString.swift +++ b/test/stdlib/StringAPICString.swift @@ -149,13 +149,13 @@ CStringTests.test("String(cString:)") { CStringTests.test("String.decodeCString") { do { let s = getNullUTF8() - let result = String.decodeCString(s, as: UTF8.self) + let result = String.decodeCString(s, as: Unicode.UTF8.self) expectNil(result) } do { // repairing let (s, dealloc) = getIllFormedUTF8String1() if let (result, repairsMade) = String.decodeCString( - s, as: UTF8.self, repairingInvalidCodeUnits: true) { + s, as: Unicode.UTF8.self, repairingInvalidCodeUnits: true) { expectEqual("\u{41}\u{fffd}\u{fffd}\u{fffd}\u{41}", result) expectTrue(repairsMade) } else { @@ -166,7 +166,7 @@ CStringTests.test("String.decodeCString") { do { // non repairing let (s, dealloc) = getIllFormedUTF8String1() let result = String.decodeCString( - s, as: UTF8.self, repairingInvalidCodeUnits: false) + s, as: Unicode.UTF8.self, repairingInvalidCodeUnits: false) expectNil(result) dealloc() } diff --git a/test/stdlib/StringCreate.swift b/test/stdlib/StringCreate.swift index 9bdce7e0c317d..8ade24defee8b 100644 --- a/test/stdlib/StringCreate.swift +++ b/test/stdlib/StringCreate.swift @@ -22,14 +22,14 @@ extension String { StringCreateTests.test("String(decoding:as:)") { func validateDecodingAs(_ str: String) { // Non-contiguous (maybe) storage - expectEqual(str, String(decoding: str.utf8, as: UTF8.self)) - expectEqual(str, String(decoding: str.utf16, as: UTF16.self)) - expectEqual(str, String(decoding: str.utf32, as: UTF32.self)) + expectEqual(str, String(decoding: str.utf8, as: Unicode.UTF8.self)) + expectEqual(str, String(decoding: str.utf16, as: Unicode.UTF16.self)) + expectEqual(str, String(decoding: str.utf32, as: Unicode.UTF32.self)) // Contiguous storage - expectEqual(str, String(decoding: Array(str.utf8), as: UTF8.self)) - expectEqual(str, String(decoding: Array(str.utf16), as: UTF16.self)) - expectEqual(str, String(decoding: Array(str.utf32), as: UTF32.self)) + expectEqual(str, String(decoding: Array(str.utf8), as: Unicode.UTF8.self)) + expectEqual(str, String(decoding: Array(str.utf16), as: Unicode.UTF16.self)) + expectEqual(str, String(decoding: Array(str.utf32), as: Unicode.UTF32.self)) } @@ -39,11 +39,11 @@ StringCreateTests.test("String(decoding:as:)") { // Corner-case: UBP with null pointer (https://bugs.swift.org/browse/SR-9869) expectEqual( - "", String(decoding: UnsafeBufferPointer(_empty: ()), as: UTF8.self)) + "", String(decoding: UnsafeBufferPointer(_empty: ()), as: Unicode.UTF8.self)) expectEqual( - "", String(decoding: UnsafeBufferPointer(_empty: ()), as: UTF16.self)) + "", String(decoding: UnsafeBufferPointer(_empty: ()), as: Unicode.UTF16.self)) expectEqual( - "", String(decoding: UnsafeBufferPointer(_empty: ()), as: UTF32.self)) + "", String(decoding: UnsafeBufferPointer(_empty: ()), as: Unicode.UTF32.self)) } if #available(macOS 10.16, iOS 14.0, watchOS 7.0, tvOS 14.0, *) { diff --git a/test/stdlib/StringIndex.swift b/test/stdlib/StringIndex.swift index 5bd575033e616..b5cbcbadbb2a0 100644 --- a/test/stdlib/StringIndex.swift +++ b/test/stdlib/StringIndex.swift @@ -31,12 +31,12 @@ StringIndexTests.test("basic sanity checks") { let utf32 = Array(s.unicodeScalars.map { $0.value }) let subUTF32 = Array(s[...].unicodeScalars.map { $0.value }) - expectEqual(s, String(decoding: utf8, as: UTF8.self)) - expectEqual(s, String(decoding: subUTF8, as: UTF8.self)) - expectEqual(s, String(decoding: utf16, as: UTF16.self)) - expectEqual(s, String(decoding: subUTF16, as: UTF16.self)) - expectEqual(s, String(decoding: utf32, as: UTF32.self)) - expectEqual(s, String(decoding: subUTF32, as: UTF32.self)) + expectEqual(s, String(decoding: utf8, as: Unicode.UTF8.self)) + expectEqual(s, String(decoding: subUTF8, as: Unicode.UTF8.self)) + expectEqual(s, String(decoding: utf16, as: Unicode.UTF16.self)) + expectEqual(s, String(decoding: subUTF16, as: Unicode.UTF16.self)) + expectEqual(s, String(decoding: utf32, as: Unicode.UTF32.self)) + expectEqual(s, String(decoding: subUTF32, as: Unicode.UTF32.self)) } } @@ -260,7 +260,7 @@ StringIndexTests.test("Misaligned") { lastScalarI += 1 continue } - expectTrue(UTF8.isContinuation(str.utf8[idx])) + expectTrue(Unicode.UTF8.isContinuation(str.utf8[idx])) let lastScalarIdx = scalarIndices[lastScalarI] @@ -381,7 +381,7 @@ StringIndexTests.test("Exhaustive Index Interchange") { while curUTF8Idx < curScalarIdx { expect(curScalar == str.unicodeScalars[curUTF8Idx]) expect(curSubChar == str[curUTF8Idx]) - expect(!UTF16.isTrailSurrogate(str.utf16[curUTF8Idx])) + expect(!Unicode.UTF16.isTrailSurrogate(str.utf16[curUTF8Idx])) expect(utf8StartIdx == str[curUTF8Idx...].startIndex) expect(str[utf8StartIdx.. containing U+D7FF" - let problematicChar = UnicodeScalar(0xD7FF)! + // "CharacterSet.insert(charactersIn: ClosedRange) crashes on a closed ClosedRange containing U+D7FF" + let problematicChar = Unicode.Scalar(0xD7FF)! let range = capitalA...problematicChar var characters = CharacterSet(charactersIn: range) // this should not crash expectTrue(characters.contains(problematicChar)) @@ -116,7 +116,7 @@ class TestCharacterSet : TestCharacterSetSuper { func testUpperBoundaryInsert_SR_2988() { // "CharacterSet.insert(_: Unicode.Scalar) crashes on U+D7FF" - let problematicChar = UnicodeScalar(0xD7FF)! + let problematicChar = Unicode.Scalar(0xD7FF)! var characters = CharacterSet() characters.insert(problematicChar) // this should not crash expectTrue(characters.contains(problematicChar)) @@ -125,26 +125,26 @@ class TestCharacterSet : TestCharacterSetSuper { } func testInsertAndRemove() { - var asciiUppercase = CharacterSet(charactersIn: UnicodeScalar(0x41)!...UnicodeScalar(0x5A)!) - expectTrue(asciiUppercase.contains(UnicodeScalar(0x49)!)) - expectTrue(asciiUppercase.contains(UnicodeScalar(0x5A)!)) - expectTrue(asciiUppercase.contains(UnicodeScalar(0x41)!)) + var asciiUppercase = CharacterSet(charactersIn: Unicode.Scalar(0x41)!...Unicode.Scalar(0x5A)!) + expectTrue(asciiUppercase.contains(Unicode.Scalar(0x49)!)) + expectTrue(asciiUppercase.contains(Unicode.Scalar(0x5A)!)) + expectTrue(asciiUppercase.contains(Unicode.Scalar(0x41)!)) - asciiUppercase.remove(UnicodeScalar(0x49)!) - expectTrue(!asciiUppercase.contains(UnicodeScalar(0x49)!)) - expectTrue(asciiUppercase.contains(UnicodeScalar(0x5A)!)) - expectTrue(asciiUppercase.contains(UnicodeScalar(0x41)!)) + asciiUppercase.remove(Unicode.Scalar(0x49)!) + expectTrue(!asciiUppercase.contains(Unicode.Scalar(0x49)!)) + expectTrue(asciiUppercase.contains(Unicode.Scalar(0x5A)!)) + expectTrue(asciiUppercase.contains(Unicode.Scalar(0x41)!)) // Zero-length range - asciiUppercase.remove(charactersIn: UnicodeScalar(0x41)!.. () in @@ -30,16 +30,16 @@ UnicodeInternals.test("copy") { (u8) -> () in let p8 = u8.baseAddress! - UTF16._copy(source: p8, destination: p16, count: 3) + Unicode.UTF16._copy(source: p8, destination: p16, count: 3) expectEqual([ 0, 1, 2, 9, 10, 11 ], Array(u16)) - UTF16._copy(source: p16 + 3, destination: p8, count: 3) + Unicode.UTF16._copy(source: p16 + 3, destination: p8, count: 3) expectEqual([ 9, 10, 11, 3, 4, 5 ], Array(u8)) - UTF16._copy(source: p16, destination: p16 + 3, count: 3) + Unicode.UTF16._copy(source: p16, destination: p16 + 3, count: 3) expectEqual([ 0, 1, 2, 0, 1, 2 ], Array(u16)) - UTF16._copy(source: p8, destination: p8 + 3, count: 3) + Unicode.UTF16._copy(source: p8, destination: p8 + 3, count: 3) expectEqual([ 9, 10, 11, 9, 10, 11 ], Array(u8)) } } @@ -57,12 +57,12 @@ UnicodeAPIs.test("UnicodeDecodingResult/Equatable") { checkEquatable(instances, oracle: ==) } -typealias ASCII = Unicode.ASCII -typealias UTF8 = Unicode.UTF8 -typealias UTF16 = Unicode.UTF16 -typealias UTF32 = Unicode.UTF32 - UnicodeAPIs.test("UTF-8 and UTF-16 queries") { + typealias ASCII = Unicode.ASCII + typealias UTF8 = Unicode.UTF8 + typealias UTF16 = Unicode.UTF16 + typealias UTF32 = Unicode.UTF32 + guard #available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *) else { return } diff --git a/test/stdlib/UnicodeScalarDiagnostics.swift b/test/stdlib/UnicodeScalarDiagnostics.swift index f9d26537109b6..6b9c314124fb0 100644 --- a/test/stdlib/UnicodeScalarDiagnostics.swift +++ b/test/stdlib/UnicodeScalarDiagnostics.swift @@ -5,26 +5,26 @@ func isString(_ s: inout String) {} -func test_UnicodeScalarDoesNotImplementArithmetic(_ us: UnicodeScalar, i: Int) { +func test_UnicodeScalarDoesNotImplementArithmetic(_ us: Unicode.Scalar, i: Int) { var a1 = "a" + "b" // OK isString(&a1) let a2 = "a" - "b" // expected-error {{binary operator '-' cannot be applied to two 'String' operands}} let a3 = "a" * "b" // expected-error {{binary operator '*' cannot be applied to two 'String' operands}} let a4 = "a" / "b" // expected-error {{binary operator '/' cannot be applied to two 'String' operands}} - let b1 = us + us // expected-error {{binary operator '+' cannot be applied to two 'UnicodeScalar' (aka 'Unicode.Scalar') operands}} - let b2 = us - us // expected-error {{binary operator '-' cannot be applied to two 'UnicodeScalar' (aka 'Unicode.Scalar') operands}} - let b3 = us * us // expected-error {{binary operator '*' cannot be applied to two 'UnicodeScalar' (aka 'Unicode.Scalar') operands}} - let b4 = us / us // expected-error {{binary operator '/' cannot be applied to two 'UnicodeScalar' (aka 'Unicode.Scalar') operands}} + let b1 = us + us // expected-error {{binary operator '+' cannot be applied to two 'Unicode.Scalar' operands}} + let b2 = us - us // expected-error {{binary operator '-' cannot be applied to two 'Unicode.Scalar' operands}} + let b3 = us * us // expected-error {{binary operator '*' cannot be applied to two 'Unicode.Scalar' operands}} + let b4 = us / us // expected-error {{binary operator '/' cannot be applied to two 'Unicode.Scalar' operands}} - let c1 = us + i // expected-error {{cannot convert value of type 'UnicodeScalar' (aka 'Unicode.Scalar') to expected argument type 'Int'}} - let c2 = us - i // expected-error {{cannot convert value of type 'UnicodeScalar' (aka 'Unicode.Scalar') to expected argument type 'Int'}} - let c3 = us * i // expected-error {{cannot convert value of type 'UnicodeScalar' (aka 'Unicode.Scalar') to expected argument type 'Int'}} - let c4 = us / i // expected-error {{cannot convert value of type 'UnicodeScalar' (aka 'Unicode.Scalar') to expected argument type 'Int'}} + let c1 = us + i // expected-error {{cannot convert value of type 'Unicode.Scalar' to expected argument type 'Int'}} + let c2 = us - i // expected-error {{cannot convert value of type 'Unicode.Scalar' to expected argument type 'Int'}} + let c3 = us * i // expected-error {{cannot convert value of type 'Unicode.Scalar' to expected argument type 'Int'}} + let c4 = us / i // expected-error {{cannot convert value of type 'Unicode.Scalar' to expected argument type 'Int'}} - let d1 = i + us // expected-error {{cannot convert value of type 'UnicodeScalar' (aka 'Unicode.Scalar') to expected argument type 'Int'}} - let d2 = i - us // expected-error {{cannot convert value of type 'UnicodeScalar' (aka 'Unicode.Scalar') to expected argument type 'Int'}} - let d3 = i * us // expected-error {{cannot convert value of type 'UnicodeScalar' (aka 'Unicode.Scalar') to expected argument type 'Int'}} - let d4 = i / us // expected-error {{cannot convert value of type 'UnicodeScalar' (aka 'Unicode.Scalar') to expected argument type 'Int'}} + let d1 = i + us // expected-error {{cannot convert value of type 'Unicode.Scalar' to expected argument type 'Int'}} + let d2 = i - us // expected-error {{cannot convert value of type 'Unicode.Scalar' to expected argument type 'Int'}} + let d3 = i * us // expected-error {{cannot convert value of type 'Unicode.Scalar' to expected argument type 'Int'}} + let d4 = i / us // expected-error {{cannot convert value of type 'Unicode.Scalar' to expected argument type 'Int'}} } diff --git a/validation-test/Sema/type_checker_crashers_fixed/rdar29075927.swift b/validation-test/Sema/type_checker_crashers_fixed/rdar29075927.swift index d8958b921a722..424c2bf019379 100644 --- a/validation-test/Sema/type_checker_crashers_fixed/rdar29075927.swift +++ b/validation-test/Sema/type_checker_crashers_fixed/rdar29075927.swift @@ -10,16 +10,16 @@ protocol StringProtocol { mutating func append(other: T) where Content == T.Content, Element == Element, - Element == UnicodeScalar + Element == Unicode.Scalar } struct X : StringProtocol { typealias Content = Int - var unicodeScalars: [UnicodeScalar] + var unicodeScalars: [Unicode.Scalar] mutating func append(other: T) where Content == T.Content, - T.UnicodeScalars.Iterator.Element == UnicodeScalar + T.UnicodeScalars.Iterator.Element == Unicode.Scalar { print(other.unicodeScalars.first!) } diff --git a/validation-test/Sema/type_checker_perf/fast/rdar19157118.swift b/validation-test/Sema/type_checker_perf/fast/rdar19157118.swift index 58d4801434cc1..6dfda4ca12086 100644 --- a/validation-test/Sema/type_checker_perf/fast/rdar19157118.swift +++ b/validation-test/Sema/type_checker_perf/fast/rdar19157118.swift @@ -9,7 +9,7 @@ SelfType, ArgumentType, Result : Equatable _ function2: (SelfType) -> (ArgumentType) -> Result ) { fatalError() } -func test(ascii0to126: [UnicodeScalar], ascii1to127: [UnicodeScalar]) { +func test(ascii0to126: [Unicode.Scalar], ascii1to127: [Unicode.Scalar]) { expectEqualMethodsForDomain( ascii0to126, ascii1to127, diff --git a/validation-test/StdlibUnittest/Stdin.swift b/validation-test/StdlibUnittest/Stdin.swift index 056a92c9ca04e..6001bcdcaa37a 100644 --- a/validation-test/StdlibUnittest/Stdin.swift +++ b/validation-test/StdlibUnittest/Stdin.swift @@ -25,7 +25,7 @@ func simple_getline() -> [UInt8]? { return result } result.append(UInt8(c)) - if c == CInt(UnicodeScalar("\n").value) { + if c == CInt(Unicode.Scalar("\n").value) { return result } } diff --git a/validation-test/compiler_crashers_2_fixed/0058-rdar29223240.swift b/validation-test/compiler_crashers_2_fixed/0058-rdar29223240.swift index 61bfa54bdaa1b..d108a7ab4f127 100644 --- a/validation-test/compiler_crashers_2_fixed/0058-rdar29223240.swift +++ b/validation-test/compiler_crashers_2_fixed/0058-rdar29223240.swift @@ -1,6 +1,6 @@ // RUN: %target-swift-frontend %s -emit-ir -extension Array where Iterator.Element == UTF8.CodeUnit { +extension Array where Iterator.Element == Unicode.UTF8.CodeUnit { var u8str : String { return "" } diff --git a/validation-test/compiler_crashers_2_fixed/0102-sr4575.swift b/validation-test/compiler_crashers_2_fixed/0102-sr4575.swift index 900464d167316..c97e8002d5243 100644 --- a/validation-test/compiler_crashers_2_fixed/0102-sr4575.swift +++ b/validation-test/compiler_crashers_2_fixed/0102-sr4575.swift @@ -7,7 +7,7 @@ struct S { } extension S { - func foo(_ body: (UnsafeBufferPointer) -> R) -> R { - return Array(self.bar(UTF16.self)).withUnsafeBufferPointer(body) + func foo(_ body: (UnsafeBufferPointer) -> R) -> R { + return Array(self.bar(Unicode.UTF16.self)).withUnsafeBufferPointer(body) } } diff --git a/validation-test/compiler_crashers_2_fixed/0109-sr4737.swift b/validation-test/compiler_crashers_2_fixed/0109-sr4737.swift index 47cbee128db27..080ed6e63bc61 100644 --- a/validation-test/compiler_crashers_2_fixed/0109-sr4737.swift +++ b/validation-test/compiler_crashers_2_fixed/0109-sr4737.swift @@ -1,14 +1,14 @@ // RUN: not %target-swift-frontend %s -typecheck //===----------------------------------------------------------------------===// -extension UnicodeScalar { +extension Unicode.Scalar { // Hack providing an efficient API that is available to the standard library @usableFromInline @inline(__always) - init(_unchecked x: UInt32) { self = unsafeBitCast(x, to: UnicodeScalar.self) } + init(_unchecked x: UInt32) { self = unsafeBitCast(x, to: Unicode.Scalar.self) } - static var replacementCharacter: UnicodeScalar { - return UnicodeScalar(_unchecked: 0xfffd) + static var replacementCharacter: Unicode.Scalar { + return Unicode.Scalar(_unchecked: 0xfffd) } } //===----------------------------------------------------------------------===// @@ -250,7 +250,7 @@ extension UnicodeDecoder { public static func decode( _ input: inout I, repairingIllFormedSequences makeRepairs: Bool, - into output: (UnicodeScalar)->Void + into output: (Unicode.Scalar)->Void ) -> Int where I.Element == CodeUnit { @@ -263,7 +263,7 @@ extension UnicodeDecoder { case .invalid: if !makeRepairs { return 1 } errors += 1 - output(UnicodeScalar(_unchecked: 0xFFFD)) + output(Unicode.Scalar(_unchecked: 0xFFFD)) case .emptyInput: return errors } @@ -324,7 +324,7 @@ extension Unicode.DefaultScalarView : Sequence { } extension Unicode.DefaultScalarView.Iterator : IteratorProtocol, Sequence { - mutating func next() -> UnicodeScalar? { + mutating func next() -> Unicode.Scalar? { return parsing.next().map { Encoding.ForwardDecoder.decodeOne($0) } @@ -334,7 +334,7 @@ extension Unicode.DefaultScalarView.Iterator : IteratorProtocol, Sequence { extension Unicode.DefaultScalarView { struct Index { var codeUnitIndex: CodeUnits.Index - var scalar: UnicodeScalar + var scalar: Unicode.Scalar var stride: UInt8 } } @@ -364,7 +364,7 @@ extension Unicode.DefaultScalarView : Collection { return index( after: Index( codeUnitIndex: codeUnits.startIndex, - scalar: UnicodeScalar(_unchecked: 0), + scalar: Unicode.Scalar(_unchecked: 0), stride: 0) ) } @@ -375,12 +375,12 @@ extension Unicode.DefaultScalarView : Collection { get { return Index( codeUnitIndex: codeUnits.endIndex, - scalar: UnicodeScalar(_unchecked: 0), + scalar: Unicode.Scalar(_unchecked: 0), stride: 0) } } - public subscript(i: Index) -> UnicodeScalar { + public subscript(i: Index) -> Unicode.Scalar { @inline(__always) get { return i.scalar } } @@ -401,7 +401,7 @@ extension Unicode.DefaultScalarView : Collection { case .invalid(let stride): return Index( codeUnitIndex: nextPosition, - scalar: UnicodeScalar(_unchecked: 0xfffd), + scalar: Unicode.Scalar(_unchecked: 0xfffd), stride: numericCast(stride)) case .emptyInput: return endIndex @@ -459,7 +459,7 @@ extension Unicode.DefaultScalarView : BidirectionalCollection { let d: Int = -numericCast(stride) return Index( codeUnitIndex: codeUnits.index(i.codeUnitIndex, offsetBy: d) , - scalar: UnicodeScalar(_unchecked: 0xfffd), + scalar: Unicode.Scalar(_unchecked: 0xfffd), stride: numericCast(stride)) case .emptyInput: fatalError("index out of bounds.") } @@ -473,7 +473,7 @@ public protocol UnicodeEncoding { where CodeUnit == EncodedScalar.Iterator.Element static var encodedReplacementScalar : EncodedScalar { get } - static func decode(_ content: EncodedScalar) -> UnicodeScalar + static func decode(_ content: EncodedScalar) -> Unicode.Scalar associatedtype ForwardDecoder : UnicodeDecoder where EncodedScalar == ForwardDecoder.EncodedScalar @@ -573,27 +573,27 @@ extension Unicode.UTF8 : UnicodeEncoding { public var buffer = Buffer() } - public static func decode(_ source: EncodedScalar) -> UnicodeScalar { + public static func decode(_ source: EncodedScalar) -> Unicode.Scalar { let bits = source._storage switch source._bitCount { case 8: - return UnicodeScalar(_unchecked: bits) + return Unicode.Scalar(_unchecked: bits) case 16: var value = (bits & 0b0_______________________11_1111__0000_0000) &>> 8 value |= (bits & 0b0________________________________0001_1111) &<< 6 - return UnicodeScalar(_unchecked: value) + return Unicode.Scalar(_unchecked: value) case 24: var value = (bits & 0b0____________11_1111__0000_0000__0000_0000) &>> 16 value |= (bits & 0b0_______________________11_1111__0000_0000) &>> 2 value |= (bits & 0b0________________________________0000_1111) &<< 12 - return UnicodeScalar(_unchecked: value) + return Unicode.Scalar(_unchecked: value) default: assert(source.count == 4) var value = (bits & 0b0_11_1111__0000_0000__0000_0000__0000_0000) &>> 24 value |= (bits & 0b0____________11_1111__0000_0000__0000_0000) &>> 10 value |= (bits & 0b0_______________________11_1111__0000_0000) &<< 4 value |= (bits & 0b0________________________________0000_0111) &<< 18 - return UnicodeScalar(_unchecked: value) + return Unicode.Scalar(_unchecked: value) } } } @@ -850,14 +850,14 @@ extension Unicode.UTF16 : UnicodeEncoding { public var buffer: Buffer } - public static func decode(_ source: EncodedScalar) -> UnicodeScalar { + public static func decode(_ source: EncodedScalar) -> Unicode.Scalar { let bits = source._storage if _fastPath(source._bitCount == 16) { - return UnicodeScalar(_unchecked: bits & 0xffff) + return Unicode.Scalar(_unchecked: bits & 0xffff) } assert(source._bitCount == 32) let value = 0x10000 + (bits >> 16 & 0x03ff | (bits & 0x03ff) << 10) - return UnicodeScalar(_unchecked: value) + return Unicode.Scalar(_unchecked: value) } } @@ -880,14 +880,14 @@ extension Unicode.UTF16.ForwardDecoder : _UTF16Decoder { import StdlibUnittest import SwiftPrivate -func checkDecodeUTF( +func checkDecodeUTF( _ codec: Codec.Type, _ expectedHead: [UInt32], _ expectedRepairedTail: [UInt32], _ utfStr: [Codec.CodeUnit] ) -> AssertionResult { var decoded = [UInt32]() var expected = expectedHead func output(_ scalar: UInt32) { decoded.append(scalar) } - func output1(_ scalar: UnicodeScalar) { decoded.append(scalar.value) } + func output1(_ scalar: Unicode.Scalar) { decoded.append(scalar.value) } var result = assertionSuccess() @@ -1047,8 +1047,8 @@ public struct UTFTest { public let string: String public let utf8: [UInt8] public let utf16: [UInt16] - public let unicodeScalars: [UnicodeScalar] - public let unicodeScalarsRepairedTail: [UnicodeScalar] + public let unicodeScalars: [Unicode.Scalar] + public let unicodeScalarsRepairedTail: [Unicode.Scalar] public let flags: Flags public let loc: SourceLoc @@ -1072,9 +1072,9 @@ public struct UTFTest { self.string = string self.utf8 = utf8 self.utf16 = utf16 - self.unicodeScalars = scalars.map { UnicodeScalar($0)! } + self.unicodeScalars = scalars.map { Unicode.Scalar($0)! } self.unicodeScalarsRepairedTail = - scalarsRepairedTail.map { UnicodeScalar($0)! } + scalarsRepairedTail.map { Unicode.Scalar($0)! } self.flags = flags self.loc = SourceLoc(file, line, comment: "test data") } diff --git a/validation-test/stdlib/ErrorHandling.swift b/validation-test/stdlib/ErrorHandling.swift index eedf51bb58690..f41d19040129f 100644 --- a/validation-test/stdlib/ErrorHandling.swift +++ b/validation-test/stdlib/ErrorHandling.swift @@ -86,8 +86,8 @@ ErrorHandlingTests.test("ErrorHandling/withCString extends lifetime") { do { // Don't use x anywhere in this test after this point. try x.withCString { p in - expectEqual(p[0], Int8(("a" as UnicodeScalar).value)) - expectEqual(p[1], Int8(("d" as UnicodeScalar).value)) + expectEqual(p[0], Int8(("a" as Unicode.Scalar).value)) + expectEqual(p[1], Int8(("d" as Unicode.Scalar).value)) throw SillyError.JazzHands } expectUnreachable() diff --git a/validation-test/stdlib/String.swift b/validation-test/stdlib/String.swift index d2e35647dca44..4b0d3b45c25dc 100644 --- a/validation-test/stdlib/String.swift +++ b/validation-test/stdlib/String.swift @@ -67,7 +67,7 @@ extension Substring { // A thin wrapper around _StringGuts implementing RangeReplaceableCollection struct StringFauxUTF16Collection: RangeReplaceableCollection, RandomAccessCollection { - typealias Element = UTF16.CodeUnit + typealias Element = Unicode.UTF16.CodeUnit typealias Index = Int typealias Indices = CountableRange @@ -96,7 +96,7 @@ struct StringFauxUTF16Collection: RangeReplaceableCollection, RandomAccessCollec ) where C : Collection, C.Element == Element { var utf16 = Array(_str.utf16) utf16.replaceSubrange(subrange, with: newElements) - self._str = String(decoding: utf16, as: UTF16.self) + self._str = String(decoding: utf16, as: Unicode.UTF16.self) } mutating func reserveCapacity(_ n: Int) { @@ -900,8 +900,8 @@ StringTests.test("stringGutsExtensibility") .skip(.nativeRuntime("Foundation dependency")) .code { #if _runtime(_ObjC) - let ascii = UTF16.CodeUnit(UnicodeScalar("X").value) - let nonAscii = UTF16.CodeUnit(UnicodeScalar("Γ©").value) + let ascii = Unicode.UTF16.CodeUnit(Unicode.Scalar("X").value) + let nonAscii = Unicode.UTF16.CodeUnit(Unicode.Scalar("Γ©").value) for k in 0..<3 { for count in 1..<16 { @@ -918,14 +918,14 @@ StringTests.test("stringGutsExtensibility") for i in 0.. String.UnicodeScalarView in String(makeStringGuts(s1)).unicodeScalars }, - { String(decoding: doubleS2[0..<$0], as: UTF16.self).unicodeScalars } + { String(decoding: doubleS2[0..<$0], as: Unicode.UTF16.self).unicodeScalars } ) checkRangeReplaceable( { String(makeStringGuts(s1)).unicodeScalars }, @@ -1081,7 +1081,7 @@ StringTests.test("StringRRC") { let doubleS2 = Array(String(makeStringGuts(s2 + s2)).utf16) checkRangeReplaceable( { () -> String in String(makeStringGuts(s1)) }, - { String(decoding: doubleS2[0..<$0], as: UTF16.self) } + { String(decoding: doubleS2[0..<$0], as: Unicode.UTF16.self) } ) checkRangeReplaceable( { String(makeStringGuts(s1)) }, @@ -1133,11 +1133,11 @@ StringTests.test("toInt") { // then print if the new String is or is not still an Int. func testConvertabilityOfStringWithModification( _ initialValue: Int, - modification: (_ chars: inout [UTF8.CodeUnit]) -> Void + modification: (_ chars: inout [Unicode.UTF8.CodeUnit]) -> Void ) { var chars = Array(String(initialValue).utf8) modification(&chars) - let str = String(decoding: chars, as: UTF8.self) + let str = String(decoding: chars, as: Unicode.UTF8.self) expectNil(Int(str)) } @@ -1239,8 +1239,8 @@ StringTests.test("lowercased()") { let asciiDomain: [Int32] = Array(0..<128) expectEqualFunctionsForDomain( asciiDomain, - { String(UnicodeScalar(Int(tolower($0)))!) }, - { String(UnicodeScalar(Int($0))!).lowercased() }) + { String(Unicode.Scalar(Int(tolower($0)))!) }, + { String(Unicode.Scalar(Int($0))!).lowercased() }) expectEqual("", "".lowercased()) expectEqual("abcd", "abCD".lowercased()) @@ -1273,8 +1273,8 @@ StringTests.test("uppercased()") { let asciiDomain: [Int32] = Array(0..<128) expectEqualFunctionsForDomain( asciiDomain, - { String(UnicodeScalar(Int(toupper($0)))!) }, - { String(UnicodeScalar(Int($0))!).uppercased() }) + { String(Unicode.Scalar(Int(toupper($0)))!) }, + { String(Unicode.Scalar(Int($0))!).uppercased() }) expectEqual("", "".uppercased()) expectEqual("ABCD", "abCD".uppercased()) @@ -1407,25 +1407,25 @@ StringTests.test("String.append(_: UnicodeScalar)") { do { // U+0061 LATIN SMALL LETTER A - let input: UnicodeScalar = "\u{61}" + let input: Unicode.Scalar = "\u{61}" s.append(String(input)) expectEqual(["\u{61}"], Array(s.unicodeScalars)) } do { // U+304B HIRAGANA LETTER KA - let input: UnicodeScalar = "\u{304b}" + let input: Unicode.Scalar = "\u{304b}" s.append(String(input)) expectEqual(["\u{61}", "\u{304b}"], Array(s.unicodeScalars)) } do { // U+3099 COMBINING KATAKANA-HIRAGANA VOICED SOUND MARK - let input: UnicodeScalar = "\u{3099}" + let input: Unicode.Scalar = "\u{3099}" s.append(String(input)) expectEqual(["\u{61}", "\u{304b}", "\u{3099}"], Array(s.unicodeScalars)) } do { // U+1F425 FRONT-FACING BABY CHICK - let input: UnicodeScalar = "\u{1f425}" + let input: Unicode.Scalar = "\u{1f425}" s.append(String(input)) expectEqual( ["\u{61}", "\u{304b}", "\u{3099}", "\u{1f425}"], @@ -1486,7 +1486,7 @@ StringTests.test("String.append(_: Character)") { } internal func decodeCString< - C : UnicodeCodec + C: Unicode.Encoding >(_ s: String, as codec: C.Type) -> (result: String, repairsMade: Bool)? { let units = s.unicodeScalars.map({ $0.value }) + [0] @@ -1496,19 +1496,19 @@ internal func decodeCString< } StringTests.test("String.decodeCString/UTF8") { - let actual = decodeCString("foobar", as: UTF8.self) + let actual = decodeCString("foobar", as: Unicode.UTF8.self) expectFalse(actual!.repairsMade) expectEqual("foobar", actual!.result) } StringTests.test("String.decodeCString/UTF16") { - let actual = decodeCString("foobar", as: UTF16.self) + let actual = decodeCString("foobar", as: Unicode.UTF16.self) expectFalse(actual!.repairsMade) expectEqual("foobar", actual!.result) } StringTests.test("String.decodeCString/UTF32") { - let actual = decodeCString("foobar", as: UTF32.self) + let actual = decodeCString("foobar", as: Unicode.UTF32.self) expectFalse(actual!.repairsMade) expectEqual("foobar", actual!.result) } diff --git a/validation-test/stdlib/StringNormalization.swift b/validation-test/stdlib/StringNormalization.swift index 2de63c018b43b..2452140386171 100644 --- a/validation-test/stdlib/StringNormalization.swift +++ b/validation-test/stdlib/StringNormalization.swift @@ -1,8 +1,8 @@ -//===--- StringNormalization.swift ------------------------------------------------===// +//===--- StringNormalization.swift ----------------------------------------===// // // This source file is part of the Swift.org open source project // -// Copyright (c) 2014 - 2018 Apple Inc. and the Swift project authors +// Copyright (c) 2014 - 2020 Apple Inc. and the Swift project authors // Licensed under Apache License v2.0 with Runtime Library Exception // // See https://swift.org/LICENSE.txt for license information @@ -38,10 +38,10 @@ private func expectEqualIterators( file: String = #file, line: UInt = #line ) { - let expectedString = String(decoding: expected, as: UTF8.self) + let expectedString = String(decoding: expected, as: Unicode.UTF8.self) let expectedCodeUnits = expectedString._nfcCodeUnits for (otherLabel, other) in others { - let otherString = String(decoding: other, as: UTF8.self) + let otherString = String(decoding: other, as: Unicode.UTF8.self) expectEqual( expectedCodeUnits, otherString._nfcCodeUnits, diff --git a/validation-test/stdlib/StringUTF8.swift b/validation-test/stdlib/StringUTF8.swift index 83bff4e5daa76..122c91b355b30 100644 --- a/validation-test/stdlib/StringUTF8.swift +++ b/validation-test/stdlib/StringUTF8.swift @@ -104,7 +104,7 @@ UTF8Tests.test("Contiguous Access") { bytes.withContiguousStorageIfAvailable { let slowString = NSSlowString(characters: $0.baseAddress!, length: UInt($0.count)) - let string = String(decoding: $0, as: UTF16.self) + let string = String(decoding: $0, as: Unicode.UTF16.self) testForeignContiguous(slowString: slowString, string: string) } } diff --git a/validation-test/stdlib/StringViews.swift b/validation-test/stdlib/StringViews.swift index 8c85e68d8f66b..c23a381f9657f 100644 --- a/validation-test/stdlib/StringViews.swift +++ b/validation-test/stdlib/StringViews.swift @@ -2,7 +2,7 @@ // // This source file is part of the Swift.org open source project // -// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors +// Copyright (c) 2014 - 2020 Apple Inc. and the Swift project authors // Licensed under Apache License v2.0 with Runtime Library Exception // // See https://swift.org/LICENSE.txt for license information @@ -27,9 +27,9 @@ import Foundation // CHECK: testing... print("testing...") -let replacementUTF16: UTF16.CodeUnit = 0xFFFD -let replacementUTF8: [UTF8.CodeUnit] = [0xEF, 0xBF, 0xBD] -let replacementScalar = UnicodeScalar(replacementUTF16)! +let replacementUTF16: Unicode.UTF16.CodeUnit = 0xFFFD +let replacementUTF8: [Unicode.UTF8.CodeUnit] = [0xEF, 0xBF, 0xBD] +let replacementScalar = Unicode.Scalar(replacementUTF16)! let replacementCharacter = Character(replacementScalar) // This string contains a variety of non-ASCII characters, including @@ -41,8 +41,9 @@ var winter = winterUTF16.withUnsafeBufferPointer { String._fromInvalidUTF16($0) } -let winterInvalidUTF8: [UTF8.CodeUnit] = replacementUTF8 + ([0x20] as [UTF8.CodeUnit]) + replacementUTF8 + replacementUTF8 -let winterUTF8: [UTF8.CodeUnit] = [ +let winterInvalidUTF8: [Unicode.UTF8.CodeUnit] = replacementUTF8 + + ([0x20] as [Unicode.UTF8.CodeUnit]) + replacementUTF8 + replacementUTF8 +let winterUTF8: [Unicode.UTF8.CodeUnit] = [ 0xf0, 0x9f, 0x8f, 0x82, 0xe2, 0x98, 0x83, 0xe2, 0x9d, 0x85, 0xe2, 0x9d, 0x86, 0xe2, 0x9d, 0x84, 0xef, 0xb8, 0x8e, 0xe2, 0x9b, 0x84, 0xef, 0xb8, 0x8f, 0xe2, 0x9d, 0x84, 0xef, 0xb8, 0x8f @@ -74,7 +75,7 @@ tests.test("decoding") { ) expectEqualSequence( - summerBytes.map {UTF16.CodeUnit($0)}, + summerBytes.map {Unicode.UTF16.CodeUnit($0)}, summer.utf16 ) } @@ -105,7 +106,7 @@ tests.test("index-mapping/character-to-utf8/\(id)") { [0x20] + replacementUTF8[0..<2], replacementUTF8, replacementUTF8 - ] as [[UTF8.CodeUnit]], + ] as [[Unicode.UTF8.CodeUnit]], winter.indices.map { i in (0..<3).map { @@ -147,7 +148,7 @@ tests.test("index-mapping/unicode-scalar-to-utf8/\(id)") { [0x20] + replacementUTF8[0..<2], replacementUTF8, replacementUTF8 - ] as [[UTF8.CodeUnit]], + ] as [[Unicode.UTF8.CodeUnit]], winter.unicodeScalars.indices.map { i in (0..<3).map { @@ -204,7 +205,7 @@ tests.test("index-mapping/utf16-to-utf8/\(id)") { [0x20] + replacementUTF8[0..<2], replacementUTF8, replacementUTF8 - ] as [[UTF8.CodeUnit]], + ] as [[Unicode.UTF8.CodeUnit]], winter.utf16.indices.map { i16 in mapIndex(i16, winter.utf8).map { i8 in (0..<3).map { @@ -263,7 +264,7 @@ tests.test("index-mapping/character-to-utf16/\(id)") { 0x26c4, // 0xfe0f, 0x2744, // 0xfe0f, replacementUTF16, 0x20, replacementUTF16, replacementUTF16 - ] as [UTF16.CodeUnit], + ] as [Unicode.UTF16.CodeUnit], winter.indices.map { winter.utf16[mapIndex($0, winter.utf16)!] @@ -273,7 +274,7 @@ tests.test("index-mapping/character-to-utf16/\(id)") { expectEqual(winter.utf16.endIndex, mapIndex(winter.endIndex, winter.utf16)) expectEqualSequence( - summerBytes.map { UTF16.CodeUnit($0) }, + summerBytes.map { Unicode.UTF16.CodeUnit($0) }, summer.indices.map { summer.utf16[mapIndex($0, summer.utf16)!] } ) @@ -291,7 +292,7 @@ tests.test("index-mapping/unicode-scalar-to-utf16/\(id)") { 0x26c4, 0xfe0f, 0x2744, 0xfe0f, replacementUTF16, 0x20, replacementUTF16, replacementUTF16 - ] as [UTF16.CodeUnit], + ] as [Unicode.UTF16.CodeUnit], winter.unicodeScalars.indices.map { winter.utf16[mapIndex($0, winter.utf16)!] @@ -302,7 +303,7 @@ tests.test("index-mapping/unicode-scalar-to-utf16/\(id)") { mapIndex(winter.unicodeScalars.endIndex, winter.utf16)) expectEqualSequence( - summerBytes.map { UTF16.CodeUnit($0) }, + summerBytes.map { Unicode.UTF16.CodeUnit($0) }, summer.unicodeScalars.indices.map { summer.utf16[mapIndex($0, summer.utf16)!] } @@ -330,7 +331,7 @@ tests.test("index-mapping/utf8-to-utf16/\(id)") { 0x20, replacementUTF16, err(replacementUTF16), err(replacementUTF16), replacementUTF16, err(replacementUTF16), err(replacementUTF16) - ] as [UTF16.CodeUnit?], + ] as [Unicode.UTF16.CodeUnit?], winter.utf8.indices.map { mapIndex($0, winter.utf16).map { @@ -344,7 +345,7 @@ tests.test("index-mapping/utf8-to-utf16/\(id)") { mapIndex(winter.utf8.endIndex, winter.utf16)!) expectEqualSequence( - summerBytes.map { UTF16.CodeUnit($0) }, + summerBytes.map { Unicode.UTF16.CodeUnit($0) }, summer.utf8.indices.map { summer.utf16[mapIndex($0, summer.utf16)!] } ) @@ -363,20 +364,20 @@ func checkToUnicodeScalar( mapIndex: @escaping (String.Index, String.UnicodeScalarView)->String.Index? ) { -func err(_ scalarValue: UInt32) -> UnicodeScalar? { - return id == "legacy" ? nil : UnicodeScalar(scalarValue) +func err(_ scalarValue: UInt32) -> Unicode.Scalar? { + return id == "legacy" ? nil : Unicode.Scalar(scalarValue) } tests.test("index-mapping/character-to-unicode-scalar/\(id)") { - let winterCharacterUnicodeScalars: [UnicodeScalar] = [ - UnicodeScalar(0x1f3c2)!, - UnicodeScalar(0x2603)!, - UnicodeScalar(0x2745)!, - UnicodeScalar(0x2746)!, - UnicodeScalar(0x2744)!, // 0xfe0e, - UnicodeScalar(0x26c4)!, // 0xfe0f, - UnicodeScalar(0x2744)!, // 0xfe0f - replacementScalar, UnicodeScalar(0x20)!, replacementScalar, replacementScalar + let winterCharacterUnicodeScalars: [Unicode.Scalar] = [ + Unicode.Scalar(0x1f3c2)!, + Unicode.Scalar(0x2603)!, + Unicode.Scalar(0x2745)!, + Unicode.Scalar(0x2746)!, + Unicode.Scalar(0x2744)!, // 0xfe0e, + Unicode.Scalar(0x26c4)!, // 0xfe0f, + Unicode.Scalar(0x2744)!, // 0xfe0f + replacementScalar, Unicode.Scalar(0x20)!, replacementScalar, replacementScalar ] expectEqualSequence( @@ -389,7 +390,7 @@ tests.test("index-mapping/character-to-unicode-scalar/\(id)") { expectEqual(winter.unicodeScalars.endIndex, mapIndex(winter.endIndex, winter.unicodeScalars)) expectEqualSequence( - summerBytes.map { UnicodeScalar($0) }, + summerBytes.map { Unicode.Scalar($0) }, summer.indices.map { summer.unicodeScalars[mapIndex($0, summer.unicodeScalars)!] } ) @@ -399,20 +400,20 @@ tests.test("index-mapping/character-to-unicode-scalar/\(id)") { tests.test("index-mapping/utf8-to-unicode-scalar/\(id)") { // Define expectation separately to help the type-checker, which // otherwise runs out of time solving. - let winterUtf8UnicodeScalars: [UnicodeScalar?] = [ - UnicodeScalar(0x1f3c2), err(0x1f3c2), err(0x1f3c2), err(0x1f3c2), - UnicodeScalar(0x2603), err(0x2603), err(0x2603), - UnicodeScalar(0x2745), err(0x2745), err(0x2745), - UnicodeScalar(0x2746), err(0x2746), err(0x2746), - UnicodeScalar(0x2744), err(0x2744), err(0x2744), - UnicodeScalar(0xfe0e), err(0xfe0e), err(0xfe0e), - UnicodeScalar(0x26c4), err(0x26c4), err(0x26c4), - UnicodeScalar(0xfe0f), err(0xfe0f), err(0xfe0f), - UnicodeScalar(0x2744), err(0x2744), err(0x2744), - UnicodeScalar(0xfe0f), err(0xfe0f), err(0xfe0f), + let winterUtf8UnicodeScalars: [Unicode.Scalar?] = [ + Unicode.Scalar(0x1f3c2), err(0x1f3c2), err(0x1f3c2), err(0x1f3c2), + Unicode.Scalar(0x2603), err(0x2603), err(0x2603), + Unicode.Scalar(0x2745), err(0x2745), err(0x2745), + Unicode.Scalar(0x2746), err(0x2746), err(0x2746), + Unicode.Scalar(0x2744), err(0x2744), err(0x2744), + Unicode.Scalar(0xfe0e), err(0xfe0e), err(0xfe0e), + Unicode.Scalar(0x26c4), err(0x26c4), err(0x26c4), + Unicode.Scalar(0xfe0f), err(0xfe0f), err(0xfe0f), + Unicode.Scalar(0x2744), err(0x2744), err(0x2744), + Unicode.Scalar(0xfe0f), err(0xfe0f), err(0xfe0f), replacementScalar, err(replacementScalar.value), err(replacementScalar.value), - UnicodeScalar(0x20), + Unicode.Scalar(0x20), replacementScalar, err(replacementScalar.value), err(replacementScalar.value), replacementScalar, @@ -433,7 +434,7 @@ tests.test("index-mapping/utf8-to-unicode-scalar/\(id)") { mapIndex(winter.utf8.endIndex, winter.unicodeScalars)!) expectEqualSequence( - summerBytes.map { UnicodeScalar($0) as UnicodeScalar? }, + summerBytes.map { Unicode.Scalar($0) as Unicode.Scalar? }, summer.utf8.indices.map { i in mapIndex(i, summer.unicodeScalars).map { summer.unicodeScalars[$0] @@ -447,8 +448,8 @@ tests.test("index-mapping/utf8-to-unicode-scalar/\(id)") { } tests.test("index-mapping/utf16-to-unicode-scalar/\(id)") { - let winterUtf16UnicodeScalars: [UnicodeScalar?] = [ - UnicodeScalar(0x1f3c2), + let winterUtf16UnicodeScalars: [Unicode.Scalar?] = [ + Unicode.Scalar(0x1f3c2), // Prior to UTF-8 String, this tested for empty array in "legacy mode" or // the replacemnet character otherwise. However, SE-0180 (String Index @@ -461,13 +462,13 @@ tests.test("index-mapping/utf16-to-unicode-scalar/\(id)") { // err(replacementScalar.value), err(0x1f3c2), - UnicodeScalar(0x2603), - UnicodeScalar(0x2745), - UnicodeScalar(0x2746), - UnicodeScalar(0x2744), UnicodeScalar(0xfe0e), - UnicodeScalar(0x26c4), UnicodeScalar(0xfe0f), - UnicodeScalar(0x2744), UnicodeScalar(0xfe0f), - replacementScalar, UnicodeScalar(0x20), replacementScalar, replacementScalar + Unicode.Scalar(0x2603), + Unicode.Scalar(0x2745), + Unicode.Scalar(0x2746), + Unicode.Scalar(0x2744), Unicode.Scalar(0xfe0e), + Unicode.Scalar(0x26c4), Unicode.Scalar(0xfe0f), + Unicode.Scalar(0x2744), Unicode.Scalar(0xfe0f), + replacementScalar, Unicode.Scalar(0x20), replacementScalar, replacementScalar ] expectEqualSequence( @@ -484,7 +485,7 @@ tests.test("index-mapping/utf16-to-unicode-scalar/\(id)") { mapIndex(winter.utf16.endIndex, winter.unicodeScalars)!) expectEqualSequence( - summerBytes.map { UnicodeScalar($0) as UnicodeScalar? }, + summerBytes.map { Unicode.Scalar($0) as Unicode.Scalar? }, summer.utf16.indices.map { i in mapIndex(i, summer.unicodeScalars).map { summer.unicodeScalars[$0] @@ -529,7 +530,7 @@ tests.test("index-mapping/unicode-scalar-to-character/\(id)") { expectEqual(winter.endIndex, mapIndex(winter.unicodeScalars.endIndex, winter)!) expectEqualSequence( - summerBytes.map { Character(UnicodeScalar($0)) }, + summerBytes.map { Character(Unicode.Scalar($0)) }, summer.unicodeScalars.indices.map { summer[mapIndex($0, summer)!] } ) @@ -570,7 +571,7 @@ tests.test("index-mapping/utf8-to-character/\(id)") { mapIndex(winter.utf8.endIndex, winter)!) expectEqualSequence( - summerBytes.map { Character(UnicodeScalar($0)) }, + summerBytes.map { Character(Unicode.Scalar($0)) }, summer.utf8.indices.map { summer[mapIndex($0, summer)!] } ) @@ -615,7 +616,7 @@ tests.test("index-mapping/utf16-to-character/\(id)") { mapIndex(winter.utf16.endIndex, winter)!) expectEqualSequence( - summerBytes.map { Character(UnicodeScalar($0)) }, + summerBytes.map { Character(Unicode.Scalar($0)) }, summer.utf16.indices.map { summer[mapIndex($0, summer)!] } @@ -672,7 +673,7 @@ tests.test("UTF8 indexes") { while true { //===--- loop condition -------------------------------------------===// let b = u8[u8i0a] - let isLeadingByte = !UTF8.isContinuation(b) + let isLeadingByte = !Unicode.UTF8.isContinuation(b) if dsa == ds && isLeadingByte { break } // //===--------------------------------------------------------------===// @@ -683,7 +684,7 @@ tests.test("UTF8 indexes") { // we should be able to round-trip through UTF16 expectEqual(u8i0a, u16i0a.samePosition(in: u8)!) - if UTF16.isLeadSurrogate(u16[u16i0a]) { + if Unicode.UTF16.isLeadSurrogate(u16[u16i0a]) { // We only have well-formed UTF16 in this string, so the // successor points to a trailing surrogate of a pair and // thus shouldn't convert to a UTF8 position diff --git a/validation-test/stdlib/Unicode.swift.gyb b/validation-test/stdlib/Unicode.swift.gyb index 8a7b8e69cbd5e..b3b59e3ff3e10 100644 --- a/validation-test/stdlib/Unicode.swift.gyb +++ b/validation-test/stdlib/Unicode.swift.gyb @@ -12,86 +12,86 @@ import StdlibCollectionUnittest var UTF16APIs = TestSuite("UTF16APIs") UTF16APIs.test("width") { - expectEqual(1, UTF16.width("x")) - expectEqual(2, UTF16.width("\u{101010}")) - expectEqual(2, UTF16.width("π„ž")) + expectEqual(1, Unicode.UTF16.width("x")) + expectEqual(2, Unicode.UTF16.width("\u{101010}")) + expectEqual(2, Unicode.UTF16.width("π„ž")) } UTF16APIs.test("leadSurrogate,trailSurrogate") { do { - let us: UnicodeScalar = "π„ž" - expectEqual(0xD834, UTF16.leadSurrogate(us)) - expectEqual(0xDD1E, UTF16.trailSurrogate(us)) + let us: Unicode.Scalar = "π„ž" + expectEqual(0xD834, Unicode.UTF16.leadSurrogate(us)) + expectEqual(0xDD1E, Unicode.UTF16.trailSurrogate(us)) } do { - let us: UnicodeScalar = "\u{10000}" - expectEqual(0xD800, UTF16.leadSurrogate(us)) - expectEqual(0xDC00, UTF16.trailSurrogate(us)) + let us: Unicode.Scalar = "\u{10000}" + expectEqual(0xD800, Unicode.UTF16.leadSurrogate(us)) + expectEqual(0xDC00, Unicode.UTF16.trailSurrogate(us)) } do { - let us: UnicodeScalar = "\u{20000}" - expectEqual(0xD840, UTF16.leadSurrogate(us)) - expectEqual(0xDC00, UTF16.trailSurrogate(us)) + let us: Unicode.Scalar = "\u{20000}" + expectEqual(0xD840, Unicode.UTF16.leadSurrogate(us)) + expectEqual(0xDC00, Unicode.UTF16.trailSurrogate(us)) } do { - let us: UnicodeScalar = "\u{80000}" - expectEqual(0xD9C0, UTF16.leadSurrogate(us)) - expectEqual(0xDC00, UTF16.trailSurrogate(us)) + let us: Unicode.Scalar = "\u{80000}" + expectEqual(0xD9C0, Unicode.UTF16.leadSurrogate(us)) + expectEqual(0xDC00, Unicode.UTF16.trailSurrogate(us)) } do { - let us: UnicodeScalar = "\u{F0000}" - expectEqual(0xDB80, UTF16.leadSurrogate(us)) - expectEqual(0xDC00, UTF16.trailSurrogate(us)) + let us: Unicode.Scalar = "\u{F0000}" + expectEqual(0xDB80, Unicode.UTF16.leadSurrogate(us)) + expectEqual(0xDC00, Unicode.UTF16.trailSurrogate(us)) } do { - let us: UnicodeScalar = "\u{100000}" - expectEqual(0xDBC0, UTF16.leadSurrogate(us)) - expectEqual(0xDC00, UTF16.trailSurrogate(us)) + let us: Unicode.Scalar = "\u{100000}" + expectEqual(0xDBC0, Unicode.UTF16.leadSurrogate(us)) + expectEqual(0xDC00, Unicode.UTF16.trailSurrogate(us)) } do { - let us: UnicodeScalar = "\u{10FFFF}" - expectEqual(0xDBFF, UTF16.leadSurrogate(us)) - expectEqual(0xDFFF, UTF16.trailSurrogate(us)) + let us: Unicode.Scalar = "\u{10FFFF}" + expectEqual(0xDBFF, Unicode.UTF16.leadSurrogate(us)) + expectEqual(0xDFFF, Unicode.UTF16.trailSurrogate(us)) } } UTF16APIs.test("leadSurrogate/trap/U+0000") { - let us: UnicodeScalar = "\u{00}" + let us: Unicode.Scalar = "\u{00}" expectCrashLater() - _ = UTF16.leadSurrogate(us) + _ = Unicode.UTF16.leadSurrogate(us) } UTF16APIs.test("leadSurrogate/trap/U+005A") { - let us: UnicodeScalar = "\u{5A}" + let us: Unicode.Scalar = "\u{5A}" expectCrashLater() - _ = UTF16.leadSurrogate(us) + _ = Unicode.UTF16.leadSurrogate(us) } UTF16APIs.test("leadSurrogate/trap/U+FFFF") { - let us: UnicodeScalar = "\u{FFFF}" + let us: Unicode.Scalar = "\u{FFFF}" expectCrashLater() - _ = UTF16.leadSurrogate(us) + _ = Unicode.UTF16.leadSurrogate(us) } UTF16APIs.test("trailSurrogate/trap/U+0000") { - let us: UnicodeScalar = "\u{00}" + let us: Unicode.Scalar = "\u{00}" expectCrashLater() - _ = UTF16.trailSurrogate(us) + _ = Unicode.UTF16.trailSurrogate(us) } UTF16APIs.test("trailSurrogate/trap/U+005A") { - let us: UnicodeScalar = "\u{5A}" + let us: Unicode.Scalar = "\u{5A}" expectCrashLater() - _ = UTF16.trailSurrogate(us) + _ = Unicode.UTF16.trailSurrogate(us) } UTF16APIs.test("trailSurrogate/trap/U+FFFF") { - let us: UnicodeScalar = "\u{FFFF}" + let us: Unicode.Scalar = "\u{FFFF}" expectCrashLater() - _ = UTF16.trailSurrogate(us) + _ = Unicode.UTF16.trailSurrogate(us) } -func checkDecodeUTF( +func checkDecodeUTF( _ codec: Codec.Type, _ expectedHead: [UInt32], _ expectedRepairedTail: [UInt32], _ utfStr: [Codec.CodeUnit] ) -> AssertionResult { @@ -102,7 +102,7 @@ func checkDecodeUTF( transcode( iterator, from: codec, - to: UTF32.self, + to: Unicode.UTF32.self, stoppingOnError: true, into: output) if expectedHead != decoded { @@ -123,7 +123,7 @@ func checkDecodeUTF( transcode( iterator, from: codec, - to: UTF32.self, + to: Unicode.UTF32.self, stoppingOnError: false, into: output) if expected != decoded { @@ -141,14 +141,14 @@ func checkDecodeUTF8( _ expectedHead: [UInt32], _ expectedRepairedTail: [UInt32], _ utf8Str: [UInt8] ) -> AssertionResult { - return checkDecodeUTF(UTF8.self, expectedHead, expectedRepairedTail, utf8Str) + return checkDecodeUTF(Unicode.UTF8.self, expectedHead, expectedRepairedTail, utf8Str) } func checkDecodeUTF16( _ expectedHead: [UInt32], _ expectedRepairedTail: [UInt32], _ utf16Str: [UInt16] ) -> AssertionResult { - return checkDecodeUTF(UTF16.self, expectedHead, expectedRepairedTail, + return checkDecodeUTF(Unicode.UTF16.self, expectedHead, expectedRepairedTail, utf16Str) } @@ -156,7 +156,7 @@ func checkDecodeUTF32( _ expectedHead: [UInt32], _ expectedRepairedTail: [UInt32], _ utf32Str: [UInt32] ) -> AssertionResult { - return checkDecodeUTF(UTF32.self, expectedHead, expectedRepairedTail, + return checkDecodeUTF(Unicode.UTF32.self, expectedHead, expectedRepairedTail, utf32Str) } @@ -167,8 +167,8 @@ func checkEncodeUTF8(_ expected: [UInt8], let iterator = scalars.makeIterator() let hadError = transcode( iterator, - from: UTF32.self, - to: UTF8.self, + from: Unicode.UTF32.self, + to: Unicode.UTF8.self, stoppingOnError: true, into: output) expectFalse(hadError) @@ -187,29 +187,29 @@ var UnicodeScalarTests = TestSuite("UnicodeScalarTests") UnicodeScalarTests.test("literal") { do { // U+0041 LATIN CAPITAL LETTER A - let us: UnicodeScalar = "A" + let us: Unicode.Scalar = "A" expectEqual(0x0041, us.value) } do { // U+3042 HIRAGANA LETTER A - let us: UnicodeScalar = "あ" + let us: Unicode.Scalar = "あ" expectEqual(0x3042, us.value) } do { // U+4F8B CJK UNIFIED IDEOGRAPH-4F8B - let us: UnicodeScalar = "δΎ‹" + let us: Unicode.Scalar = "δΎ‹" expectEqual(0x4F8B, us.value) } } UnicodeScalarTests.test("init") { - expectEqual("f", UnicodeScalar(102)) - expectEqual("g", UnicodeScalar(UInt32(103))) - expectEqual("h", UnicodeScalar(UInt16(104))) - expectEqual("i", UnicodeScalar(UInt8(105))) - expectEqual(nil, UnicodeScalar(UInt32(0xD800))) + expectEqual("f", Unicode.Scalar(102)) + expectEqual("g", Unicode.Scalar(UInt32(103))) + expectEqual("h", Unicode.Scalar(UInt16(104))) + expectEqual("i", Unicode.Scalar(UInt8(105))) + expectEqual(nil, Unicode.Scalar(UInt32(0xD800))) } var UTF8Decoder = TestSuite("UTF8Decoder") @@ -1305,10 +1305,10 @@ var UTF16Decoder = TestSuite("UTF16Decoder") UTF16Decoder.test("UTF16.transcodedLength") { do { - var u8: [UTF8.CodeUnit] = [ 0, 1, 2, 3, 4, 5 ] - let (count, isASCII) = UTF16.transcodedLength( + var u8: [Unicode.UTF8.CodeUnit] = [ 0, 1, 2, 3, 4, 5 ] + let (count, isASCII) = Unicode.UTF16.transcodedLength( of: u8.makeIterator(), - decodedAs: UTF8.self, + decodedAs: Unicode.UTF8.self, repairingIllFormedSequences: false)! expectEqual(6, count) expectTrue(isASCII) @@ -1316,20 +1316,20 @@ UTF16Decoder.test("UTF16.transcodedLength") { do { // "€" == U+20AC. - var u8: [UTF8.CodeUnit] = [ 0xF0, 0xA4, 0xAD, 0xA2 ] - let (count, isASCII) = UTF16.transcodedLength( + var u8: [Unicode.UTF8.CodeUnit] = [ 0xF0, 0xA4, 0xAD, 0xA2 ] + let (count, isASCII) = Unicode.UTF16.transcodedLength( of: u8.makeIterator(), - decodedAs: UTF8.self, + decodedAs: Unicode.UTF8.self, repairingIllFormedSequences: false)! expectEqual(2, count) expectFalse(isASCII) } do { - let u16: [UTF16.CodeUnit] = [ 6, 7, 8, 9, 10, 11 ] - let (count, isASCII) = UTF16.transcodedLength( + let u16: [Unicode.UTF16.CodeUnit] = [ 6, 7, 8, 9, 10, 11 ] + let (count, isASCII) = Unicode.UTF16.transcodedLength( of: u16.makeIterator(), - decodedAs: UTF16.self, + decodedAs: Unicode.UTF16.self, repairingIllFormedSequences: false)! expectEqual(6, count) expectTrue(isASCII) @@ -1514,8 +1514,8 @@ UnicodeAPIs.test("transcode/MutableArray") { let output: (UInt16) -> Void = { transcoded.append($0) } transcode( input.makeIterator(), - from: UTF16.self, - to: UTF16.self, + from: Unicode.UTF16.self, + to: Unicode.UTF16.self, stoppingOnError: true, into: output) expectEqual(input, transcoded) @@ -1527,8 +1527,8 @@ UnicodeAPIs.test("transcode/ReferenceTypedArray") { let output: (UInt16) -> Void = { transcoded.append($0) } transcode( input.makeIterator(), - from: UTF16.self, - to: UTF16.self, + from: Unicode.UTF16.self, + to: Unicode.UTF16.self, stoppingOnError: true, into: output) expectEqual(input, transcoded) @@ -1559,8 +1559,8 @@ class NonContiguousNSString : NSString { let iterator = utf8.makeIterator() let hadError = transcode( iterator, - from: UTF8.self, - to: UTF16.self, + from: Unicode.UTF8.self, + to: Unicode.UTF16.self, stoppingOnError: true, into: output) expectFalse(hadError) @@ -1580,8 +1580,8 @@ class NonContiguousNSString : NSString { let iterator = scalars.makeIterator() let hadError = transcode( iterator, - from: UTF32.self, - to: UTF16.self, + from: Unicode.UTF32.self, + to: Unicode.UTF16.self, stoppingOnError: true, into: output) expectFalse(hadError) @@ -1652,8 +1652,8 @@ StringCookedViews.test("UTF8ForContiguousUTF16").forEach(in: utfTests) { var iterator = test.utf32.makeIterator() transcode( iterator, - from: UTF32.self, - to: UTF16.self, + from: Unicode.UTF32.self, + to: Unicode.UTF16.self, stoppingOnError: false, into: output) @@ -1679,8 +1679,8 @@ StringCookedViews.test("UTF8ForContiguousUTF16/StringsWithUnpairedSurrogates") { var iterator = expectedScalars.makeIterator() transcode( iterator, - from: UTF32.self, - to: UTF8.self, + from: Unicode.UTF32.self, + to: Unicode.UTF8.self, stoppingOnError: false, into: output) @@ -1729,8 +1729,8 @@ StringCookedViews.test("UTF8ForNonContiguousUTF16/fromUTF16").forEach(in: utfTes var expectedScalars = test.utf32 + test.utf32RepairedTail transcode( expectedScalars.makeIterator(), - from: UTF32.self, - to: UTF8.self, + from: Unicode.UTF32.self, + to: Unicode.UTF8.self, stoppingOnError: false, into: { expected.append($0) }) @@ -1749,8 +1749,8 @@ StringCookedViews.test("UTF8ForNonContiguousUTF16/utf16Tests"){ var iterator = expectedScalars.makeIterator() transcode( iterator, - from: UTF32.self, - to: UTF8.self, + from: Unicode.UTF32.self, + to: Unicode.UTF8.self, stoppingOnError: false, into: output) @@ -1823,8 +1823,8 @@ StringCookedViews.test("UTF16").forEach(in: utfTests) { var iterator = expectedScalars.makeIterator() transcode( iterator, - from: UTF32.self, - to: UTF16.self, + from: Unicode.UTF32.self, + to: Unicode.UTF16.self, stoppingOnError: false, into: output) @@ -1841,8 +1841,8 @@ StringCookedViews.test("UTF16/StringsWithUnpairedSurrogates") { var iterator = expectedScalars.makeIterator() transcode( iterator, - from: UTF32.self, - to: UTF16.self, + from: Unicode.UTF32.self, + to: Unicode.UTF16.self, stoppingOnError: false, into: output) @@ -1862,7 +1862,7 @@ StringCookedViews.test("UnicodeScalars/StringsWithUnpairedSurrogates") { forStringsWithUnpairedSurrogates { (test: UTF16Test, subject: String) -> Void in let expectedScalars = (test.scalarsHead + test.scalarsRepairedTail).map { - UnicodeScalar($0)! + Unicode.Scalar($0)! } checkBidirectionalCollection( expectedScalars, subject.unicodeScalars) @@ -1893,9 +1893,9 @@ let nullOffsetTests = [ let NullCodeUnitOffsetTests = TestSuite("NullCodeUnitOffsetTests") % for (Encoding, View) in [ -% ('UTF8', 'utf8'), -% ('UTF16', 'utf16'), -% ('UTF32', 'unicodeScalars.map{ $0.value }') +% ('Unicode.UTF8', 'utf8'), +% ('Unicode.UTF16', 'utf16'), +% ('Unicode.UTF32', 'unicodeScalars.map{ $0.value }') % ]: NullCodeUnitOffsetTests.test("${Encoding}._nullCodeUnitOffset(in:)") { diff --git a/validation-test/stdlib/UnicodeLongTest.swift b/validation-test/stdlib/UnicodeLongTest.swift index 9f555de33781f..d707311185bcc 100644 --- a/validation-test/stdlib/UnicodeLongTest.swift +++ b/validation-test/stdlib/UnicodeLongTest.swift @@ -11,19 +11,19 @@ var UTF8Decoder = TestSuite("UTF8Decoder") UTF8Decoder.test("Internal/_decodeOne") { // Ensure we accept all valid scalars - func ensureValid(_ scalar: UnicodeScalar) { + func ensureValid(_ scalar: Unicode.Scalar) { var data: UInt32 = 0 var i: UInt32 = 0 - Swift.UTF8.encode(scalar) { cp in + Unicode.UTF8.encode(scalar) { cp in data |= UInt32(cp) << (i*8) i += 1 } - let (codePoint, _) = UTF8._decodeOne(data) + let (codePoint, _) = Unicode.UTF8._decodeOne(data) expectEqual(scalar.value, codePoint, "data=\(asHex(data))") } - for i in 0..<0xd800 { ensureValid(UnicodeScalar(i)!) } - for i in 0xe000...0x10ffff { ensureValid(UnicodeScalar(i)!) } + for i in 0..<0xd800 { ensureValid(Unicode.Scalar(i)!) } + for i in 0xe000...0x10ffff { ensureValid(Unicode.Scalar(i)!) } // Check number of valid/invalid sequences of different lengths var validLengthCounts = [ 0, 0, 0, 0, 0 ] @@ -34,7 +34,7 @@ UTF8Decoder.test("Internal/_decodeOne") { for cu0 in head { for rest in tail { let data = rest << 8 | cu0 - let (codePoint, length) = UTF8._decodeOne(data) + let (codePoint, length) = Unicode.UTF8._decodeOne(data) if codePoint != nil { validLengthCounts[Int(length)] += 1 } else { diff --git a/validation-test/stdlib/UnicodeUTFEncoders.swift b/validation-test/stdlib/UnicodeUTFEncoders.swift index 40a8608c48b41..8d3403f2ddd3c 100644 --- a/validation-test/stdlib/UnicodeUTFEncoders.swift +++ b/validation-test/stdlib/UnicodeUTFEncoders.swift @@ -20,7 +20,7 @@ protocol TestableUnicodeCodec : UnicodeCodec { static func name() -> NSString } -extension UTF8 : TestableUnicodeCodec { +extension Unicode.UTF8: TestableUnicodeCodec { static func encodingId() -> String.Encoding { return .utf8 } @@ -29,7 +29,7 @@ extension UTF8 : TestableUnicodeCodec { } } -extension UTF16 : TestableUnicodeCodec { +extension Unicode.UTF16: TestableUnicodeCodec { static func encodingId() -> String.Encoding { return .utf16LittleEndian } @@ -38,7 +38,7 @@ extension UTF16 : TestableUnicodeCodec { } } -extension UTF32 : TestableUnicodeCodec { +extension Unicode.UTF32: TestableUnicodeCodec { static func encodingId() -> String.Encoding { return .utf32LittleEndian } @@ -58,12 +58,12 @@ var unicodeScalarCount: Int { return count } -func nthUnicodeScalar(_ n: UInt32) -> UnicodeScalar { +func nthUnicodeScalar(_ n: UInt32) -> Unicode.Scalar { var count: UInt32 = 0 for r in unicodeScalarRanges { count += r.upperBound - r.lowerBound if count > n { - return UnicodeScalar(r.upperBound - (count - n))! + return Unicode.Scalar(r.upperBound - (count - n))! } } preconditionFailure("Index out of range") @@ -100,7 +100,7 @@ final class CodecTest { var nsEncodeBuffer: [CodeUnit] = Array(repeating: 0, count: 4) var encodeBuffer: [CodeUnit] = Array(repeating: 0, count: 4) - final func testOne(_ scalar: UnicodeScalar) { + final func testOne(_ scalar: Unicode.Scalar) { /* Progress reporter if (scalar.value % 0x1000) == 0 { print("\(asHex(scalar.value))") @@ -153,9 +153,9 @@ var UTFEncoders = TestSuite("UTFEncoders") UTFEncoders.test("encode") { let minScalarOrd = 0 let maxScalarOrd = unicodeScalarCount - CodecTest().run(minScalarOrd, maxScalarOrd) - CodecTest().run(minScalarOrd, maxScalarOrd) - CodecTest().run(minScalarOrd, maxScalarOrd) + CodecTest().run(minScalarOrd, maxScalarOrd) + CodecTest().run(minScalarOrd, maxScalarOrd) + CodecTest().run(minScalarOrd, maxScalarOrd) } runAllTests()