New indexing model: updated NSStringAPI

This commit is contained in:
Shawn Erickson
2016-03-10 08:09:47 -08:00
parent b097b55f1a
commit e6f3f35869
2 changed files with 23 additions and 9 deletions

View File

@@ -336,14 +336,19 @@ extension String {
// dispatching to the minimal selector for the supplied options.
// So let's do that; the switch should compile away anyhow.
return locale != nil ? _ns.compare(
aString, options: mask,
range: _toNSRange(range ?? self.characters.indices),
locale: locale)
aString,
options: mask,
range: _toNSRange(
range ?? self.characters.startIndex..<self.characters.endIndex
),
locale: locale
)
: range != nil ? _ns.compare(
aString,
options: mask,
range: _toNSRange(range ?? self.characters.indices))
range: _toNSRange(range!)
)
: !mask.isEmpty ? _ns.compare(aString, options: mask)
@@ -1185,8 +1190,13 @@ extension String {
) -> Range<Index>? {
return _optionalRange(
_ns.rangeOfCharacter(
from: aSet, options: mask,
range: _toNSRange(aRange ?? self.characters.indices)))
from: aSet,
options: mask,
range: _toNSRange(
aRange ?? self.characters.startIndex..<self.characters.endIndex
)
)
)
}
// - (NSRange)rangeOfComposedCharacterSequenceAtIndex:(NSUInteger)anIndex
@@ -1245,7 +1255,9 @@ extension String {
locale != nil ? _ns.range(
of: aString,
options: mask,
range: _toNSRange(searchRange ?? self.characters.indices),
range: _toNSRange(
searchRange ?? self.characters.startIndex..<self.characters.endIndex
),
locale: locale
)
: searchRange != nil ? _ns.range(
@@ -1493,7 +1505,9 @@ extension String {
of: target,
with: replacement,
options: options,
range: _toNSRange(searchRange ?? self.characters.indices)
range: _toNSRange(
searchRange ?? self.characters.startIndex..<self.characters.endIndex
)
)
: _ns.replacingOccurrences(of: target, with: replacement)
}