-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[stdlib] Mark NFD and NFC as SPI #42124
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// This source file is part of the Swift.org open source project | ||
// | ||
// Copyright (c) 2022 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 | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
//===----------------------------------------------------------------------===// | ||
// Unicode.NFD | ||
//===----------------------------------------------------------------------===// | ||
|
||
extension Unicode { | ||
@_spi(_Unicode) | ||
@available(SwiftStdlib 5.7, *) | ||
public struct _NFD { | ||
let base: Substring.UnicodeScalarView | ||
} | ||
} | ||
|
||
@available(SwiftStdlib 5.7, *) | ||
extension Unicode._NFD { | ||
@_spi(_Unicode) | ||
@available(SwiftStdlib 5.7, *) | ||
public struct Iterator { | ||
var base: Unicode._InternalNFD<Substring>.Iterator | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here |
||
} | ||
} | ||
|
||
@available(SwiftStdlib 5.7, *) | ||
extension Unicode._NFD.Iterator: IteratorProtocol { | ||
@_spi(_Unicode) | ||
@available(SwiftStdlib 5.7, *) | ||
public mutating func next() -> Unicode.Scalar? { | ||
base.next()?.scalar | ||
} | ||
} | ||
|
||
@available(SwiftStdlib 5.7, *) | ||
extension Unicode._NFD: Sequence { | ||
@_spi(_Unicode) | ||
@available(SwiftStdlib 5.7, *) | ||
public func makeIterator() -> Iterator { | ||
Iterator(base: Unicode._InternalNFD(base: base).makeIterator()) | ||
} | ||
} | ||
|
||
extension String { | ||
@_spi(_Unicode) | ||
@available(SwiftStdlib 5.7, *) | ||
public var _nfd: Unicode._NFD { | ||
Unicode._NFD(base: self[...].unicodeScalars) | ||
} | ||
} | ||
|
||
extension Substring { | ||
@_spi(_Unicode) | ||
@available(SwiftStdlib 5.7, *) | ||
public var _nfd: Unicode._NFD { | ||
Unicode._NFD(base: unicodeScalars) | ||
} | ||
} | ||
|
||
//===----------------------------------------------------------------------===// | ||
// Unicode.NFC | ||
//===----------------------------------------------------------------------===// | ||
|
||
extension Unicode { | ||
@_spi(_Unicode) | ||
@available(SwiftStdlib 5.7, *) | ||
public struct _NFC { | ||
let base: Substring.UnicodeScalarView | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here |
||
} | ||
} | ||
|
||
@available(SwiftStdlib 5.7, *) | ||
extension Unicode._NFC { | ||
@_spi(_Unicode) | ||
@available(SwiftStdlib 5.7, *) | ||
public struct Iterator { | ||
var base: Unicode._InternalNFC<Substring>.Iterator | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ditto |
||
} | ||
} | ||
|
||
@available(SwiftStdlib 5.7, *) | ||
extension Unicode._NFC.Iterator: IteratorProtocol { | ||
@_spi(_Unicode) | ||
@available(SwiftStdlib 5.7, *) | ||
public mutating func next() -> Unicode.Scalar? { | ||
base.next() | ||
} | ||
} | ||
|
||
@available(SwiftStdlib 5.7, *) | ||
extension Unicode._NFC: Sequence { | ||
@_spi(_Unicode) | ||
@available(SwiftStdlib 5.7, *) | ||
public func makeIterator() -> Iterator { | ||
Iterator( | ||
base: Unicode._InternalNFC<Substring>.Iterator( | ||
iterator: Unicode._InternalNFD<Substring>(base: base).makeIterator() | ||
) | ||
) | ||
} | ||
} | ||
|
||
extension String { | ||
@_spi(_Unicode) | ||
@available(SwiftStdlib 5.7, *) | ||
public var _nfc: Unicode._NFC { | ||
Unicode._NFC(base: self[...].unicodeScalars) | ||
} | ||
} | ||
|
||
extension Substring { | ||
@_spi(_Unicode) | ||
@available(SwiftStdlib 5.7, *) | ||
public var _nfc: Unicode._NFC { | ||
Unicode._NFC(base: unicodeScalars) | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To avoid surprises, I recommend spelling out the memberwise initializer here. The compiler-provided one probably works fine, but it usually is a good idea to be explicit about things that might get exposed.
(E.g. I don't know for sure if the implicit initializer will be declared public or internal.
internal
would make more sense, but ¯\_(ツ)_/¯)