File tree Expand file tree Collapse file tree 2 files changed +27
-13
lines changed
Expand file tree Collapse file tree 2 files changed +27
-13
lines changed Original file line number Diff line number Diff line change @@ -88,25 +88,26 @@ extension Character {
8888}
8989
9090extension Character {
91- @usableFromInline
92- typealias UTF8View = String . UTF8View
91+ /// A view of a character's contents as a collection of UTF-8 code units. See
92+ /// String.UTF8View for more information
93+ public typealias UTF8View = String . UTF8View
9394
95+ /// A UTF-8 encoding of `self`.
9496 @inlinable
95- internal var utf8 : UTF8View {
96- return _str . utf8
97- }
98- @ usableFromInline
99- typealias UTF16View = String . UTF16View
97+ public var utf8 : UTF8View { return _str . utf8 }
98+
99+ /// A view of a character's contents as a collection of UTF-16 code units. See
100+ /// String.UTF16View for more information
101+ public typealias UTF16View = String . UTF16View
100102
103+ /// A UTF-16 encoding of `self`.
101104 @inlinable
102- internal var utf16 : UTF16View {
103- return _str. utf16
104- }
105+ public var utf16 : UTF16View { return _str. utf16 }
106+
105107 public typealias UnicodeScalarView = String . UnicodeScalarView
108+
106109 @inlinable
107- public var unicodeScalars : UnicodeScalarView {
108- return _str. unicodeScalars
109- }
110+ public var unicodeScalars : UnicodeScalarView { return _str. unicodeScalars }
110111}
111112
112113extension Character :
Original file line number Diff line number Diff line change @@ -347,6 +347,19 @@ CharacterTests.test("String.append(_: Character)") {
347347 }
348348}
349349
350+ CharacterTests . test ( " utf6/16/unicodescalar views " ) {
351+ for c in testCharacters {
352+ expectEqualSequence ( String ( c) . unicodeScalars, c. unicodeScalars)
353+ expectEqualSequence ( String ( c) . utf8, c. utf8)
354+ expectEqualSequence ( String ( c) . utf16, c. utf16)
355+
356+ expectEqualSequence (
357+ String ( c) . unicodeScalars. reversed ( ) , c. unicodeScalars. reversed ( ) )
358+ expectEqualSequence ( String ( c) . utf8. reversed ( ) , c. utf8. reversed ( ) )
359+ expectEqualSequence ( String ( c) . utf16. reversed ( ) , c. utf16. reversed ( ) )
360+ }
361+ }
362+
350363var UnicodeScalarTests = TestSuite ( " UnicodeScalar " )
351364
352365UnicodeScalarTests . test ( " UInt8(ascii: UnicodeScalar) " ) {
You can’t perform that action at this time.
0 commit comments