mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
[stdlib] De-underscore Unicode "namespace"
This commit is contained in:
@@ -9,12 +9,12 @@
|
|||||||
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
|
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
|
||||||
//
|
//
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
extension _Unicode {
|
extension Unicode {
|
||||||
@_fixed_layout
|
@_fixed_layout
|
||||||
public enum ASCII {}
|
public enum ASCII {}
|
||||||
}
|
}
|
||||||
|
|
||||||
extension _Unicode.ASCII : UnicodeEncoding {
|
extension Unicode.ASCII : UnicodeEncoding {
|
||||||
public typealias CodeUnit = UInt8
|
public typealias CodeUnit = UInt8
|
||||||
public typealias EncodedScalar = CollectionOfOne<CodeUnit>
|
public typealias EncodedScalar = CollectionOfOne<CodeUnit>
|
||||||
|
|
||||||
@@ -69,19 +69,19 @@ extension _Unicode.ASCII : UnicodeEncoding {
|
|||||||
public typealias ReverseParser = Parser
|
public typealias ReverseParser = Parser
|
||||||
}
|
}
|
||||||
|
|
||||||
extension _Unicode.ASCII.Parser : UnicodeParser {
|
extension Unicode.ASCII.Parser : UnicodeParser {
|
||||||
public typealias Encoding = _Unicode.ASCII
|
public typealias Encoding = Unicode.ASCII
|
||||||
|
|
||||||
/// Parses a single Unicode scalar value from `input`.
|
/// Parses a single Unicode scalar value from `input`.
|
||||||
public mutating func parseScalar<I : IteratorProtocol>(
|
public mutating func parseScalar<I : IteratorProtocol>(
|
||||||
from input: inout I
|
from input: inout I
|
||||||
) -> _Unicode.ParseResult<Encoding.EncodedScalar>
|
) -> Unicode.ParseResult<Encoding.EncodedScalar>
|
||||||
where I.Element == Encoding.CodeUnit {
|
where I.Element == Encoding.CodeUnit {
|
||||||
let n = input.next()
|
let n = input.next()
|
||||||
if _fastPath(n != nil), let x = n {
|
if _fastPath(n != nil), let x = n {
|
||||||
guard _fastPath(Int8(extendingOrTruncating: x) >= 0)
|
guard _fastPath(Int8(extendingOrTruncating: x) >= 0)
|
||||||
else { return .error(length: 1) }
|
else { return .error(length: 1) }
|
||||||
return .valid(_Unicode.ASCII.EncodedScalar(x))
|
return .valid(Unicode.ASCII.EncodedScalar(x))
|
||||||
}
|
}
|
||||||
return .emptyInput
|
return .emptyInput
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -160,7 +160,7 @@ extension _StringCore {
|
|||||||
return try Swift._withCStringAndLength(
|
return try Swift._withCStringAndLength(
|
||||||
encodedAs: targetEncoding,
|
encodedAs: targetEncoding,
|
||||||
from: UnsafeBufferPointer(start: startASCII, count: count)[bounds],
|
from: UnsafeBufferPointer(start: startASCII, count: count)[bounds],
|
||||||
encodedAs: _Unicode.ASCII.self,
|
encodedAs: Unicode.ASCII.self,
|
||||||
execute: body
|
execute: body
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -168,7 +168,7 @@ extension _StringCore {
|
|||||||
return try Swift._withCStringAndLength(
|
return try Swift._withCStringAndLength(
|
||||||
encodedAs: targetEncoding,
|
encodedAs: targetEncoding,
|
||||||
from: UnsafeBufferPointer(start: startUTF16, count: count)[bounds],
|
from: UnsafeBufferPointer(start: startUTF16, count: count)[bounds],
|
||||||
encodedAs: _Unicode.UTF16.self,
|
encodedAs: Unicode.UTF16.self,
|
||||||
execute: body
|
execute: body
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -176,7 +176,7 @@ extension _StringCore {
|
|||||||
return try Swift._withCStringAndLength(
|
return try Swift._withCStringAndLength(
|
||||||
encodedAs: targetEncoding,
|
encodedAs: targetEncoding,
|
||||||
from: self[bounds],
|
from: self[bounds],
|
||||||
encodedAs: _Unicode.UTF16.self,
|
encodedAs: Unicode.UTF16.self,
|
||||||
execute: body
|
execute: body
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -336,7 +336,7 @@ public struct _StringCore {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var _unmanagedASCII : UnsafeBufferPointer<_Unicode.ASCII.CodeUnit>? {
|
var _unmanagedASCII : UnsafeBufferPointer<Unicode.ASCII.CodeUnit>? {
|
||||||
@inline(__always)
|
@inline(__always)
|
||||||
get {
|
get {
|
||||||
guard _fastPath(_baseAddress != nil && elementWidth == 1) else {
|
guard _fastPath(_baseAddress != nil && elementWidth == 1) else {
|
||||||
@@ -344,7 +344,7 @@ public struct _StringCore {
|
|||||||
}
|
}
|
||||||
return UnsafeBufferPointer(
|
return UnsafeBufferPointer(
|
||||||
start: _baseAddress!.assumingMemoryBound(
|
start: _baseAddress!.assumingMemoryBound(
|
||||||
to: _Unicode.ASCII.CodeUnit.self),
|
to: Unicode.ASCII.CodeUnit.self),
|
||||||
count: count
|
count: count
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -370,10 +370,10 @@ public struct _StringCore {
|
|||||||
{
|
{
|
||||||
defer { _fixLifetime(self) }
|
defer { _fixLifetime(self) }
|
||||||
if let bytes = _unmanagedASCII {
|
if let bytes = _unmanagedASCII {
|
||||||
if encoding == _Unicode.ASCII.self
|
if encoding == Unicode.ASCII.self
|
||||||
|| encoding == _Unicode.UTF8.self
|
|| encoding == Unicode.UTF8.self
|
||||||
|| encoding == _Unicode.UTF16.self
|
|| encoding == Unicode.UTF16.self
|
||||||
|| encoding == _Unicode.UTF32.self {
|
|| encoding == Unicode.UTF32.self {
|
||||||
bytes.forEach {
|
bytes.forEach {
|
||||||
processCodeUnit(Encoding.CodeUnit(extendingOrTruncating: $0))
|
processCodeUnit(Encoding.CodeUnit(extendingOrTruncating: $0))
|
||||||
}
|
}
|
||||||
@@ -388,7 +388,7 @@ public struct _StringCore {
|
|||||||
}
|
}
|
||||||
else if let content = _unmanagedUTF16 {
|
else if let content = _unmanagedUTF16 {
|
||||||
var i = content.makeIterator()
|
var i = content.makeIterator()
|
||||||
_Unicode.UTF16.ForwardParser._parse(&i) {
|
Unicode.UTF16.ForwardParser._parse(&i) {
|
||||||
Encoding._transcode($0, from: UTF16.self).forEach(processCodeUnit)
|
Encoding._transcode($0, from: UTF16.self).forEach(processCodeUnit)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ func _stdlib_NSStringHashValuePointer(_ str: OpaquePointer, _ isASCII: Bool) ->
|
|||||||
func _stdlib_CFStringHashCString(_ str: OpaquePointer, _ len: Int) -> Int
|
func _stdlib_CFStringHashCString(_ str: OpaquePointer, _ len: Int) -> Int
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
extension _Unicode {
|
extension Unicode {
|
||||||
internal static func hashASCII(
|
internal static func hashASCII(
|
||||||
_ string: UnsafeBufferPointer<UInt8>
|
_ string: UnsafeBufferPointer<UInt8>
|
||||||
) -> Int {
|
) -> Int {
|
||||||
@@ -97,11 +97,11 @@ internal func _hashString(_ string: String) -> Int {
|
|||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
if let asciiBuffer = core.asciiBuffer {
|
if let asciiBuffer = core.asciiBuffer {
|
||||||
return _Unicode.hashASCII(UnsafeBufferPointer(
|
return Unicode.hashASCII(UnsafeBufferPointer(
|
||||||
start: asciiBuffer.baseAddress!,
|
start: asciiBuffer.baseAddress!,
|
||||||
count: asciiBuffer.count))
|
count: asciiBuffer.count))
|
||||||
} else {
|
} else {
|
||||||
return _Unicode.hashUTF16(
|
return Unicode.hashUTF16(
|
||||||
UnsafeBufferPointer(start: core.startUTF16, count: core.count))
|
UnsafeBufferPointer(start: core.startUTF16, count: core.count))
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -9,13 +9,13 @@
|
|||||||
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
|
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
|
||||||
//
|
//
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
extension _Unicode {
|
extension Unicode {
|
||||||
public enum UTF16 {
|
public enum UTF16 {
|
||||||
case _swift3Buffer(_Unicode.UTF16.ForwardParser)
|
case _swift3Buffer(Unicode.UTF16.ForwardParser)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
extension _Unicode.UTF16 : UnicodeEncoding {
|
extension Unicode.UTF16 : UnicodeEncoding {
|
||||||
public typealias CodeUnit = UInt16
|
public typealias CodeUnit = UInt16
|
||||||
public typealias EncodedScalar = _UIntBuffer<UInt32, UInt16>
|
public typealias EncodedScalar = _UIntBuffer<UInt32, UInt16>
|
||||||
|
|
||||||
@@ -108,7 +108,7 @@ extension _Unicode.UTF16 : UnicodeEncoding {
|
|||||||
}
|
}
|
||||||
|
|
||||||
extension UTF16.ReverseParser : UnicodeParser, _UTFParser {
|
extension UTF16.ReverseParser : UnicodeParser, _UTFParser {
|
||||||
public typealias Encoding = _Unicode.UTF16
|
public typealias Encoding = Unicode.UTF16
|
||||||
|
|
||||||
public func _parseMultipleCodeUnits() -> (isValid: Bool, bitCount: UInt8) {
|
public func _parseMultipleCodeUnits() -> (isValid: Bool, bitCount: UInt8) {
|
||||||
_sanityCheck( // this case handled elsewhere
|
_sanityCheck( // this case handled elsewhere
|
||||||
@@ -128,8 +128,8 @@ extension UTF16.ReverseParser : UnicodeParser, _UTFParser {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
extension _Unicode.UTF16.ForwardParser : UnicodeParser, _UTFParser {
|
extension Unicode.UTF16.ForwardParser : UnicodeParser, _UTFParser {
|
||||||
public typealias Encoding = _Unicode.UTF16
|
public typealias Encoding = Unicode.UTF16
|
||||||
|
|
||||||
public func _parseMultipleCodeUnits() -> (isValid: Bool, bitCount: UInt8) {
|
public func _parseMultipleCodeUnits() -> (isValid: Bool, bitCount: UInt8) {
|
||||||
_sanityCheck( // this case handled elsewhere
|
_sanityCheck( // this case handled elsewhere
|
||||||
|
|||||||
@@ -9,13 +9,13 @@
|
|||||||
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
|
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
|
||||||
//
|
//
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
extension _Unicode {
|
extension Unicode {
|
||||||
public enum UTF32 {
|
public enum UTF32 {
|
||||||
case _swift3Codec
|
case _swift3Codec
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
extension _Unicode.UTF32 : UnicodeEncoding {
|
extension Unicode.UTF32 : UnicodeEncoding {
|
||||||
public typealias CodeUnit = UInt32
|
public typealias CodeUnit = UInt32
|
||||||
public typealias EncodedScalar = CollectionOfOne<UInt32>
|
public typealias EncodedScalar = CollectionOfOne<UInt32>
|
||||||
|
|
||||||
@@ -49,12 +49,12 @@ extension _Unicode.UTF32 : UnicodeEncoding {
|
|||||||
}
|
}
|
||||||
|
|
||||||
extension UTF32.Parser : UnicodeParser {
|
extension UTF32.Parser : UnicodeParser {
|
||||||
public typealias Encoding = _Unicode.UTF32
|
public typealias Encoding = Unicode.UTF32
|
||||||
|
|
||||||
/// Parses a single Unicode scalar value from `input`.
|
/// Parses a single Unicode scalar value from `input`.
|
||||||
public mutating func parseScalar<I : IteratorProtocol>(
|
public mutating func parseScalar<I : IteratorProtocol>(
|
||||||
from input: inout I
|
from input: inout I
|
||||||
) -> _Unicode.ParseResult<Encoding.EncodedScalar>
|
) -> Unicode.ParseResult<Encoding.EncodedScalar>
|
||||||
where I.Element == Encoding.CodeUnit {
|
where I.Element == Encoding.CodeUnit {
|
||||||
let n = input.next()
|
let n = input.next()
|
||||||
if _fastPath(n != nil), let x = n {
|
if _fastPath(n != nil), let x = n {
|
||||||
|
|||||||
@@ -9,14 +9,14 @@
|
|||||||
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
|
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
|
||||||
//
|
//
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
extension _Unicode {
|
extension Unicode {
|
||||||
@_fixed_layout
|
@_fixed_layout
|
||||||
public enum UTF8 {
|
public enum UTF8 {
|
||||||
case _swift3Buffer(_Unicode.UTF8.ForwardParser)
|
case _swift3Buffer(Unicode.UTF8.ForwardParser)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
extension _Unicode.UTF8 : UnicodeEncoding {
|
extension Unicode.UTF8 : UnicodeEncoding {
|
||||||
public typealias CodeUnit = UInt8
|
public typealias CodeUnit = UInt8
|
||||||
public typealias EncodedScalar = _UIntBuffer<UInt32, UInt8>
|
public typealias EncodedScalar = _UIntBuffer<UInt32, UInt8>
|
||||||
|
|
||||||
@@ -141,7 +141,7 @@ extension _Unicode.UTF8 : UnicodeEncoding {
|
|||||||
}
|
}
|
||||||
|
|
||||||
extension UTF8.ReverseParser : UnicodeParser, _UTFParser {
|
extension UTF8.ReverseParser : UnicodeParser, _UTFParser {
|
||||||
public typealias Encoding = _Unicode.UTF8
|
public typealias Encoding = Unicode.UTF8
|
||||||
@inline(__always)
|
@inline(__always)
|
||||||
@_inlineable
|
@_inlineable
|
||||||
public func _parseMultipleCodeUnits() -> (isValid: Bool, bitCount: UInt8) {
|
public func _parseMultipleCodeUnits() -> (isValid: Bool, bitCount: UInt8) {
|
||||||
@@ -217,8 +217,8 @@ extension UTF8.ReverseParser : UnicodeParser, _UTFParser {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
extension _Unicode.UTF8.ForwardParser : UnicodeParser, _UTFParser {
|
extension Unicode.UTF8.ForwardParser : UnicodeParser, _UTFParser {
|
||||||
public typealias Encoding = _Unicode.UTF8
|
public typealias Encoding = Unicode.UTF8
|
||||||
|
|
||||||
@inline(__always)
|
@inline(__always)
|
||||||
@_inlineable
|
@_inlineable
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ where Encoding.EncodedScalar == _UIntBuffer<UInt32, Encoding.CodeUnit> {
|
|||||||
@inline(__always)
|
@inline(__always)
|
||||||
public mutating func parseScalar<I : IteratorProtocol>(
|
public mutating func parseScalar<I : IteratorProtocol>(
|
||||||
from input: inout I
|
from input: inout I
|
||||||
) -> _Unicode.ParseResult<Encoding.EncodedScalar>
|
) -> Unicode.ParseResult<Encoding.EncodedScalar>
|
||||||
where I.Element == Encoding.CodeUnit {
|
where I.Element == Encoding.CodeUnit {
|
||||||
|
|
||||||
// Bufferless single-scalar fastpath.
|
// Bufferless single-scalar fastpath.
|
||||||
|
|||||||
@@ -142,7 +142,7 @@ public protocol UnicodeCodec : UnicodeEncoding {
|
|||||||
|
|
||||||
/// A codec for translating between Unicode scalar values and UTF-8 code
|
/// A codec for translating between Unicode scalar values and UTF-8 code
|
||||||
/// units.
|
/// units.
|
||||||
extension _Unicode.UTF8 : UnicodeCodec {
|
extension Unicode.UTF8 : UnicodeCodec {
|
||||||
/// Creates an instance of the UTF-8 codec.
|
/// Creates an instance of the UTF-8 codec.
|
||||||
public init() { self = ._swift3Buffer(ForwardParser()) }
|
public init() { self = ._swift3Buffer(ForwardParser()) }
|
||||||
|
|
||||||
@@ -308,11 +308,11 @@ extension _Unicode.UTF8 : UnicodeCodec {
|
|||||||
return Int(_swift_stdlib_strlen(input))
|
return Int(_swift_stdlib_strlen(input))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public typealias UTF8 = _Unicode.UTF8
|
public typealias UTF8 = Unicode.UTF8
|
||||||
|
|
||||||
/// A codec for translating between Unicode scalar values and UTF-16 code
|
/// A codec for translating between Unicode scalar values and UTF-16 code
|
||||||
/// units.
|
/// units.
|
||||||
extension _Unicode.UTF16 : UnicodeCodec {
|
extension Unicode.UTF16 : UnicodeCodec {
|
||||||
/// Creates an instance of the UTF-16 codec.
|
/// Creates an instance of the UTF-16 codec.
|
||||||
public init() { self = ._swift3Buffer(ForwardParser()) }
|
public init() { self = ._swift3Buffer(ForwardParser()) }
|
||||||
|
|
||||||
@@ -418,11 +418,11 @@ extension _Unicode.UTF16 : UnicodeCodec {
|
|||||||
processCodeUnit(UInt16(extendingOrTruncating: s))
|
processCodeUnit(UInt16(extendingOrTruncating: s))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public typealias UTF16 = _Unicode.UTF16
|
public typealias UTF16 = Unicode.UTF16
|
||||||
|
|
||||||
/// A codec for translating between Unicode scalar values and UTF-32 code
|
/// A codec for translating between Unicode scalar values and UTF-32 code
|
||||||
/// units.
|
/// units.
|
||||||
extension _Unicode.UTF32 : UnicodeCodec {
|
extension Unicode.UTF32 : UnicodeCodec {
|
||||||
/// Creates an instance of the UTF-32 codec.
|
/// Creates an instance of the UTF-32 codec.
|
||||||
public init() { self = ._swift3Codec }
|
public init() { self = ._swift3Codec }
|
||||||
|
|
||||||
@@ -508,7 +508,7 @@ extension _Unicode.UTF32 : UnicodeCodec {
|
|||||||
processCodeUnit(UInt32(input))
|
processCodeUnit(UInt32(input))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public typealias UTF32 = _Unicode.UTF32
|
public typealias UTF32 = Unicode.UTF32
|
||||||
|
|
||||||
/// Translates the given input from one Unicode encoding to another by calling
|
/// Translates the given input from one Unicode encoding to another by calling
|
||||||
/// the given closure.
|
/// the given closure.
|
||||||
@@ -918,7 +918,7 @@ extension UTF16 {
|
|||||||
&i, repairingIllFormedSequences: repairingIllFormedSequences
|
&i, repairingIllFormedSequences: repairingIllFormedSequences
|
||||||
) {
|
) {
|
||||||
if isASCII {
|
if isASCII {
|
||||||
isASCII = _Unicode.ASCII.transcode($0, from: Encoding.self) != nil
|
isASCII = Unicode.ASCII.transcode($0, from: Encoding.self) != nil
|
||||||
}
|
}
|
||||||
count += numericCast(self._transcode($0, from: Encoding.self).count)
|
count += numericCast(self._transcode($0, from: Encoding.self).count)
|
||||||
}
|
}
|
||||||
@@ -996,5 +996,5 @@ extension UTF16 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// A namespace for Unicode utilities.
|
/// A namespace for Unicode utilities.
|
||||||
public enum _Unicode {}
|
public enum Unicode {}
|
||||||
|
|
||||||
|
|||||||
@@ -9,7 +9,7 @@
|
|||||||
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
|
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
|
||||||
//
|
//
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
extension _Unicode {
|
extension Unicode {
|
||||||
/// The result of attempting to parse a `T` from some input.
|
/// The result of attempting to parse a `T` from some input.
|
||||||
public enum ParseResult<T> {
|
public enum ParseResult<T> {
|
||||||
/// A `T` was parsed successfully
|
/// A `T` was parsed successfully
|
||||||
@@ -40,7 +40,7 @@ public protocol UnicodeParser {
|
|||||||
/// Parses a single Unicode scalar value from `input`.
|
/// Parses a single Unicode scalar value from `input`.
|
||||||
mutating func parseScalar<I : IteratorProtocol>(
|
mutating func parseScalar<I : IteratorProtocol>(
|
||||||
from input: inout I
|
from input: inout I
|
||||||
) -> _Unicode.ParseResult<Encoding.EncodedScalar>
|
) -> Unicode.ParseResult<Encoding.EncodedScalar>
|
||||||
where I.Element == Encoding.CodeUnit
|
where I.Element == Encoding.CodeUnit
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -86,7 +86,7 @@ extension UnicodeParser {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
extension _Unicode {
|
extension Unicode {
|
||||||
@_fixed_layout
|
@_fixed_layout
|
||||||
public // @testable
|
public // @testable
|
||||||
struct _ParsingIterator<
|
struct _ParsingIterator<
|
||||||
@@ -104,7 +104,7 @@ extension _Unicode {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
extension _Unicode._ParsingIterator : IteratorProtocol, Sequence {
|
extension Unicode._ParsingIterator : IteratorProtocol, Sequence {
|
||||||
@inline(__always)
|
@inline(__always)
|
||||||
@_inlineable
|
@_inlineable
|
||||||
public mutating func next() -> Parser.Encoding.EncodedScalar? {
|
public mutating func next() -> Parser.Encoding.EncodedScalar? {
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ extension UnicodeScalar {
|
|||||||
}
|
}
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
extension _Unicode {
|
extension Unicode {
|
||||||
struct DefaultScalarView<
|
struct DefaultScalarView<
|
||||||
CodeUnits: BidirectionalCollection,
|
CodeUnits: BidirectionalCollection,
|
||||||
Encoding: UnicodeEncoding
|
Encoding: UnicodeEncoding
|
||||||
@@ -49,28 +49,28 @@ extension _Unicode {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
extension _Unicode.DefaultScalarView : Sequence {
|
extension Unicode.DefaultScalarView : Sequence {
|
||||||
struct Iterator {
|
struct Iterator {
|
||||||
var parsing: _Unicode._ParsingIterator<
|
var parsing: Unicode._ParsingIterator<
|
||||||
CodeUnits.Iterator, Encoding.ForwardParser>
|
CodeUnits.Iterator, Encoding.ForwardParser>
|
||||||
}
|
}
|
||||||
|
|
||||||
func makeIterator() -> Iterator {
|
func makeIterator() -> Iterator {
|
||||||
return Iterator(
|
return Iterator(
|
||||||
parsing: _Unicode._ParsingIterator(
|
parsing: Unicode._ParsingIterator(
|
||||||
codeUnits: codeUnits.makeIterator(),
|
codeUnits: codeUnits.makeIterator(),
|
||||||
parser: Encoding.ForwardParser()
|
parser: Encoding.ForwardParser()
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
extension _Unicode.DefaultScalarView.Iterator : IteratorProtocol, Sequence {
|
extension Unicode.DefaultScalarView.Iterator : IteratorProtocol, Sequence {
|
||||||
mutating func next() -> UnicodeScalar? {
|
mutating func next() -> UnicodeScalar? {
|
||||||
return parsing.next().map { Encoding.decode($0) }
|
return parsing.next().map { Encoding.decode($0) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
extension _Unicode.DefaultScalarView {
|
extension Unicode.DefaultScalarView {
|
||||||
struct Index {
|
struct Index {
|
||||||
var codeUnitIndex: CodeUnits.Index
|
var codeUnitIndex: CodeUnits.Index
|
||||||
var scalar: UnicodeScalar
|
var scalar: UnicodeScalar
|
||||||
@@ -78,25 +78,25 @@ extension _Unicode.DefaultScalarView {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
extension _Unicode.DefaultScalarView.Index : Comparable {
|
extension Unicode.DefaultScalarView.Index : Comparable {
|
||||||
@inline(__always)
|
@inline(__always)
|
||||||
public static func < (
|
public static func < (
|
||||||
lhs: _Unicode.DefaultScalarView<CodeUnits,Encoding>.Index,
|
lhs: Unicode.DefaultScalarView<CodeUnits,Encoding>.Index,
|
||||||
rhs: _Unicode.DefaultScalarView<CodeUnits,Encoding>.Index
|
rhs: Unicode.DefaultScalarView<CodeUnits,Encoding>.Index
|
||||||
) -> Bool {
|
) -> Bool {
|
||||||
return lhs.codeUnitIndex < rhs.codeUnitIndex
|
return lhs.codeUnitIndex < rhs.codeUnitIndex
|
||||||
}
|
}
|
||||||
|
|
||||||
@inline(__always)
|
@inline(__always)
|
||||||
public static func == (
|
public static func == (
|
||||||
lhs: _Unicode.DefaultScalarView<CodeUnits,Encoding>.Index,
|
lhs: Unicode.DefaultScalarView<CodeUnits,Encoding>.Index,
|
||||||
rhs: _Unicode.DefaultScalarView<CodeUnits,Encoding>.Index
|
rhs: Unicode.DefaultScalarView<CodeUnits,Encoding>.Index
|
||||||
) -> Bool {
|
) -> Bool {
|
||||||
return lhs.codeUnitIndex == rhs.codeUnitIndex
|
return lhs.codeUnitIndex == rhs.codeUnitIndex
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
extension _Unicode.DefaultScalarView : Collection {
|
extension Unicode.DefaultScalarView : Collection {
|
||||||
public var startIndex: Index {
|
public var startIndex: Index {
|
||||||
@inline(__always)
|
@inline(__always)
|
||||||
get {
|
get {
|
||||||
@@ -148,7 +148,7 @@ extension _Unicode.DefaultScalarView : Collection {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
extension _Unicode.DefaultScalarView : BidirectionalCollection {
|
extension Unicode.DefaultScalarView : BidirectionalCollection {
|
||||||
@inline(__always)
|
@inline(__always)
|
||||||
public func index(before i: Index) -> Index {
|
public func index(before i: Index) -> Index {
|
||||||
var parser = Encoding.ReverseParser()
|
var parser = Encoding.ReverseParser()
|
||||||
@@ -348,7 +348,7 @@ func checkDecodeUTF<Codec : UnicodeCodec & UnicodeEncoding>(
|
|||||||
}
|
}
|
||||||
|
|
||||||
//===--- Scalar View ----------------------------------------------------===//
|
//===--- Scalar View ----------------------------------------------------===//
|
||||||
let scalars = _Unicode.DefaultScalarView(utfStr, fromEncoding: Codec.self)
|
let scalars = Unicode.DefaultScalarView(utfStr, fromEncoding: Codec.self)
|
||||||
expectEqualSequence(expected, scalars.map { $0.value })
|
expectEqualSequence(expected, scalars.map { $0.value })
|
||||||
expectEqualSequence(
|
expectEqualSequence(
|
||||||
expected.reversed(),
|
expected.reversed(),
|
||||||
@@ -2442,18 +2442,18 @@ public func run_UTF8Decode(_ N: Int) {
|
|||||||
typealias D = UTF8.ReverseParser
|
typealias D = UTF8.ReverseParser
|
||||||
D.decode(&it, repairingIllFormedSequences: true) { total = total &+ $0.value }
|
D.decode(&it, repairingIllFormedSequences: true) { total = total &+ $0.value }
|
||||||
#elseif SEQUENCE
|
#elseif SEQUENCE
|
||||||
for s in _Unicode.DefaultScalarView(string, fromEncoding: UTF8.self) {
|
for s in Unicode.DefaultScalarView(string, fromEncoding: UTF8.self) {
|
||||||
total = total &+ s.value
|
total = total &+ s.value
|
||||||
}
|
}
|
||||||
#elseif COLLECTION
|
#elseif COLLECTION
|
||||||
let scalars = _Unicode.DefaultScalarView(string, fromEncoding: UTF8.self)
|
let scalars = Unicode.DefaultScalarView(string, fromEncoding: UTF8.self)
|
||||||
var i = scalars.startIndex
|
var i = scalars.startIndex
|
||||||
while i != scalars.endIndex {
|
while i != scalars.endIndex {
|
||||||
total = total &+ scalars[i].value
|
total = total &+ scalars[i].value
|
||||||
i = scalars.index(after: i)
|
i = scalars.index(after: i)
|
||||||
}
|
}
|
||||||
#elseif REVERSE_COLLECTION
|
#elseif REVERSE_COLLECTION
|
||||||
let scalars = _Unicode.DefaultScalarView(string, fromEncoding: UTF8.self)
|
let scalars = Unicode.DefaultScalarView(string, fromEncoding: UTF8.self)
|
||||||
var i = scalars.endIndex
|
var i = scalars.endIndex
|
||||||
while i != scalars.startIndex {
|
while i != scalars.startIndex {
|
||||||
i = scalars.index(before: i)
|
i = scalars.index(before: i)
|
||||||
|
|||||||
Reference in New Issue
Block a user