[stdlib] Conversions to String.Index

Also, hide an initializer on String.Index that was unintentionally
public/visible by giving it an underscored keyword argument.

Testing comes next.

Swift SVN r24069
This commit is contained in:
Dave Abrahams
2014-12-22 15:30:56 +00:00
parent d6bdfc1cfe
commit f78b6b125a
3 changed files with 74 additions and 7 deletions

View File

@@ -399,4 +399,31 @@ extension String.UnicodeScalarIndex {
) -> String.UTF16View.Index {
return String.UTF16View.Index(self, within: otherView)
}
public func samePositionIn(characters: String) -> String.Index? {
return String.Index(self, within: characters)
}
internal var _isOnGraphemeClusterBoundary: Bool {
let scalars = String.UnicodeScalarView(_core)
if self == scalars.startIndex || self == scalars.endIndex {
return true
}
let precedingScalar = scalars[self.predecessor()]
let graphemeClusterBreakProperty =
_UnicodeGraphemeClusterBreakPropertyTrie()
let segmenter = _UnicodeExtendedGraphemeClusterSegmenter()
let gcb0 = graphemeClusterBreakProperty.getPropertyRawValue(
precedingScalar.value)
if segmenter.isBoundaryAfter(gcb0) {
return true
}
let gcb1 = graphemeClusterBreakProperty.getPropertyRawValue(
scalars[self].value)
return segmenter.isBoundary(gcb0, gcb1)
}
}