stdlib: add a mirror for the Unicode scalar String view

Swift SVN r20977
This commit is contained in:
Dmitri Hrybenko
2014-08-03 20:01:34 +00:00
parent 1c484d91a0
commit 6e401c20ca
3 changed files with 15 additions and 4 deletions

View File

@@ -15,7 +15,7 @@
%TMirrorConformance = gyb.parseTemplate("../common/MirrorConformance.gyb")
%TMirrorBoilerplate = gyb.parseTemplate("../common/MirrorBoilerplate.gyb")
% for Self in ['UTF8View','UTF16View']:
% for Self in ['UTF8View', 'UTF16View', 'UnicodeScalarView']:
% MirrorDecl = gyb.executeTemplate(TMirrorDecl,introspecteeType=Self)
% MirrorConformance = gyb.executeTemplate(TMirrorConformance,introspecteeType=Self)
% MirrorBoilerplate = gyb.executeTemplate(TMirrorBoilerplate,introspecteeType=Self)
@@ -28,6 +28,7 @@ extension String {
subscript(i: Int) -> (String, MirrorType) {
_precondition(i >= 0 && i < count, "MirrorType access out of bounds")
// FIXME(performance): optimize for sequential access.
return ("[\(i)]", reflect(_value[advance(_value.startIndex, i)]))
}

View File

@@ -25,7 +25,7 @@ public func <(
}
extension String {
public struct UnicodeScalarView : Sliceable, SequenceType {
public struct UnicodeScalarView : Sliceable, SequenceType, Reflectable {
init(_ _core: _StringCore) {
self._core = _core
}
@@ -213,6 +213,10 @@ extension String {
}
}
public func getMirror() -> MirrorType {
return _UnicodeScalarViewMirror(self)
}
var _core: _StringCore
}
}

View File

@@ -766,8 +766,14 @@ Reflection.test("String.UnicodeScalarView/Mirror") {
var output = ""
dump("\u{61}\u{304b}\u{3099}\u{1f425}".unicodeScalars, &output)
// FIXME: the output is not pretty now.
//expectEqual(expected, output)
var expected = ""
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") {