mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
stdlib: add a mirror for the Unicode scalar String view
Swift SVN r20977
This commit is contained in:
@@ -15,7 +15,7 @@
|
|||||||
%TMirrorConformance = gyb.parseTemplate("../common/MirrorConformance.gyb")
|
%TMirrorConformance = gyb.parseTemplate("../common/MirrorConformance.gyb")
|
||||||
%TMirrorBoilerplate = gyb.parseTemplate("../common/MirrorBoilerplate.gyb")
|
%TMirrorBoilerplate = gyb.parseTemplate("../common/MirrorBoilerplate.gyb")
|
||||||
|
|
||||||
% for Self in ['UTF8View','UTF16View']:
|
% for Self in ['UTF8View', 'UTF16View', 'UnicodeScalarView']:
|
||||||
% MirrorDecl = gyb.executeTemplate(TMirrorDecl,introspecteeType=Self)
|
% MirrorDecl = gyb.executeTemplate(TMirrorDecl,introspecteeType=Self)
|
||||||
% MirrorConformance = gyb.executeTemplate(TMirrorConformance,introspecteeType=Self)
|
% MirrorConformance = gyb.executeTemplate(TMirrorConformance,introspecteeType=Self)
|
||||||
% MirrorBoilerplate = gyb.executeTemplate(TMirrorBoilerplate,introspecteeType=Self)
|
% MirrorBoilerplate = gyb.executeTemplate(TMirrorBoilerplate,introspecteeType=Self)
|
||||||
@@ -28,6 +28,7 @@ extension String {
|
|||||||
|
|
||||||
subscript(i: Int) -> (String, MirrorType) {
|
subscript(i: Int) -> (String, MirrorType) {
|
||||||
_precondition(i >= 0 && i < count, "MirrorType access out of bounds")
|
_precondition(i >= 0 && i < count, "MirrorType access out of bounds")
|
||||||
|
// FIXME(performance): optimize for sequential access.
|
||||||
return ("[\(i)]", reflect(_value[advance(_value.startIndex, i)]))
|
return ("[\(i)]", reflect(_value[advance(_value.startIndex, i)]))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ public func <(
|
|||||||
}
|
}
|
||||||
|
|
||||||
extension String {
|
extension String {
|
||||||
public struct UnicodeScalarView : Sliceable, SequenceType {
|
public struct UnicodeScalarView : Sliceable, SequenceType, Reflectable {
|
||||||
init(_ _core: _StringCore) {
|
init(_ _core: _StringCore) {
|
||||||
self._core = _core
|
self._core = _core
|
||||||
}
|
}
|
||||||
@@ -213,6 +213,10 @@ extension String {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public func getMirror() -> MirrorType {
|
||||||
|
return _UnicodeScalarViewMirror(self)
|
||||||
|
}
|
||||||
|
|
||||||
var _core: _StringCore
|
var _core: _StringCore
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -766,8 +766,14 @@ Reflection.test("String.UnicodeScalarView/Mirror") {
|
|||||||
var output = ""
|
var output = ""
|
||||||
dump("\u{61}\u{304b}\u{3099}\u{1f425}".unicodeScalars, &output)
|
dump("\u{61}\u{304b}\u{3099}\u{1f425}".unicodeScalars, &output)
|
||||||
|
|
||||||
// FIXME: the output is not pretty now.
|
var expected = ""
|
||||||
//expectEqual(expected, output)
|
expected += "▿ \u{61}\u{304b}\u{3099}\u{1f425}\n"
|
||||||
|
expected += " - [0]: \u{61}\n"
|
||||||
|
expected += " - [1]: \u{304b}\n"
|
||||||
|
expected += " - [2]: \u{3099}\n"
|
||||||
|
expected += " - [3]: \u{1f425}\n"
|
||||||
|
|
||||||
|
expectEqual(expected, output)
|
||||||
}
|
}
|
||||||
|
|
||||||
Reflection.test("TupleMirror/NoLeak") {
|
Reflection.test("TupleMirror/NoLeak") {
|
||||||
|
|||||||
Reference in New Issue
Block a user