Skip to content

Commit f5421bd

Browse files
committed
[SE-0163] Migrate from deprecated Unicode APIs
1 parent e51eaef commit f5421bd

File tree

2 files changed

+30
-25
lines changed

2 files changed

+30
-25
lines changed

stdlib/public/core/MigrationSupport.swift

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,18 @@
22
//
33
// This source file is part of the Swift.org open source project
44
//
5-
// Copyright (c) 2014 - 2018 Apple Inc. and the Swift project authors
5+
// Copyright (c) 2014 - 2020 Apple Inc. and the Swift project authors
66
// Licensed under Apache License v2.0 with Runtime Library Exception
77
//
88
// See https://swift.org/LICENSE.txt for license information
99
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
1010
//
1111
//===----------------------------------------------------------------------===//
12-
12+
//
1313
// This file contains only support for types deprecated from previous versions
1414
// of Swift
15+
//
16+
//===----------------------------------------------------------------------===//
1517

1618
@available(swift, deprecated: 3.0, obsoleted: 5.0, renamed: "BidirectionalCollection")
1719
public typealias BidirectionalIndexable = BidirectionalCollection
@@ -243,17 +245,22 @@ extension String.UnicodeScalarView: _CustomPlaygroundQuickLookable {
243245
}
244246
}
245247

246-
//===--- Slicing Support --------------------------------------------------===//
248+
//===----------------------------------------------------------------------===//
249+
//
250+
// [SE-0163] The following typealiases are "soft deprecated" only.
251+
// See the API_TO_BE_DEPRECATED macro in the <os/availability.h> header.
252+
// Another evolution proposal might be required, to formally deprecate them.
247253

248-
// @available(swift,deprecated: 5.0, renamed: "Unicode.UTF8")
254+
@available(swift, deprecated: 100000, renamed: "Unicode.UTF8")
249255
public typealias UTF8 = Unicode.UTF8
250-
// @available(swift, deprecated: 5.0, renamed: "Unicode.UTF16")
256+
@available(swift, deprecated: 100000, renamed: "Unicode.UTF16")
251257
public typealias UTF16 = Unicode.UTF16
252-
// @available(swift, deprecated: 5.0, renamed: "Unicode.UTF32")
258+
@available(swift, deprecated: 100000, renamed: "Unicode.UTF32")
253259
public typealias UTF32 = Unicode.UTF32
254-
// @available(swift, deprecated: 5.0, renamed: "Unicode.Scalar")
260+
@available(swift, deprecated: 100000, renamed: "Unicode.Scalar")
255261
public typealias UnicodeScalar = Unicode.Scalar
256262

263+
//===----------------------------------------------------------------------===//
257264

258265
extension String.UTF16View: _CustomPlaygroundQuickLookable {
259266
@available(swift, deprecated: 4.2/*, obsoleted: 5.0*/, message: "UTF16View.customPlaygroundQuickLook will be removed in Swift 5.0")

stdlib/public/core/Unicode.swift

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,19 @@
22
//
33
// This source file is part of the Swift.org open source project
44
//
5-
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
5+
// Copyright (c) 2014 - 2020 Apple Inc. and the Swift project authors
66
// Licensed under Apache License v2.0 with Runtime Library Exception
77
//
88
// See https://swift.org/LICENSE.txt for license information
99
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
1010
//
1111
//===----------------------------------------------------------------------===//
12+
//
13+
// [SE-0163] UnicodeCodec and UnicodeDecodingResult are "soft deprecated" only.
14+
// See the API_TO_BE_DEPRECATED macro in the <os/availability.h> header.
15+
// Another evolution proposal might be required, to formally deprecate them.
16+
//
17+
//===----------------------------------------------------------------------===//
1218

1319
import SwiftShims
1420

@@ -20,6 +26,7 @@ import SwiftShims
2026
/// Each `UnicodeDecodingResult` instance can represent a Unicode scalar value,
2127
/// an indication that no more Unicode scalars are available, or an indication
2228
/// of a decoding error.
29+
@available(swift, deprecated: 100000, message: "[SE-0163] Use the Unicode.Encoding APIs")
2330
@frozen
2431
public enum UnicodeDecodingResult: Equatable {
2532
/// A decoded Unicode scalar value.
@@ -30,23 +37,6 @@ public enum UnicodeDecodingResult: Equatable {
3037

3138
/// An indication of a decoding error.
3239
case error
33-
34-
@inlinable
35-
public static func == (
36-
lhs: UnicodeDecodingResult,
37-
rhs: UnicodeDecodingResult
38-
) -> Bool {
39-
switch (lhs, rhs) {
40-
case (.scalarValue(let lhsScalar), .scalarValue(let rhsScalar)):
41-
return lhsScalar == rhsScalar
42-
case (.emptyInput, .emptyInput):
43-
return true
44-
case (.error, .error):
45-
return true
46-
default:
47-
return false
48-
}
49-
}
5040
}
5141

5242
/// A Unicode encoding form that translates between Unicode scalar values and
@@ -58,6 +48,7 @@ public enum UnicodeDecodingResult: Equatable {
5848
/// UTF-8, UTF-16, and UTF-32 encoding schemes as the `UTF8`, `UTF16`, and
5949
/// `UTF32` types, respectively. Use the `Unicode.Scalar` type to work with
6050
/// decoded Unicode scalar values.
51+
@available(swift, deprecated: 100000, message: "[SE-0163] Use the Unicode.Encoding APIs")
6152
public protocol UnicodeCodec: Unicode.Encoding {
6253

6354
/// Creates an instance of the codec.
@@ -139,6 +130,7 @@ public protocol UnicodeCodec: Unicode.Encoding {
139130

140131
/// A codec for translating between Unicode scalar values and UTF-8 code
141132
/// units.
133+
@available(swift, deprecated: 100000, message: "[SE-0163] Use the Unicode.Encoding APIs")
142134
extension Unicode.UTF8: UnicodeCodec {
143135
/// Creates an instance of the UTF-8 codec.
144136
@inlinable
@@ -276,6 +268,9 @@ extension Unicode.UTF8: UnicodeCodec {
276268
if _fastPath(s == 0) { return }
277269
processCodeUnit(UInt8(truncatingIfNeeded: s) &- 0x01)
278270
}
271+
}
272+
273+
extension Unicode.UTF8 {
279274

280275
/// Returns a Boolean value indicating whether the specified code unit is a
281276
/// UTF-8 continuation byte.
@@ -316,6 +311,7 @@ extension Unicode.UTF8: UnicodeCodec {
316311

317312
/// A codec for translating between Unicode scalar values and UTF-16 code
318313
/// units.
314+
@available(swift, deprecated: 100000, message: "[SE-0163] Use the Unicode.Encoding APIs")
319315
extension Unicode.UTF16: UnicodeCodec {
320316
/// Creates an instance of the UTF-16 codec.
321317
@inlinable
@@ -428,6 +424,7 @@ extension Unicode.UTF16: UnicodeCodec {
428424

429425
/// A codec for translating between Unicode scalar values and UTF-32 code
430426
/// units.
427+
@available(swift, deprecated: 100000, message: "[SE-0163] Use the Unicode.Encoding APIs")
431428
extension Unicode.UTF32: UnicodeCodec {
432429
/// Creates an instance of the UTF-32 codec.
433430
@inlinable
@@ -643,6 +640,7 @@ extension Unicode.Scalar {
643640
}
644641
}
645642

643+
@available(swift, deprecated: 100000, message: "[SE-0163] Use the Unicode.Encoding APIs")
646644
extension UnicodeCodec {
647645
@inlinable
648646
public static func _nullCodeUnitOffset(

0 commit comments

Comments
 (0)