stdlib/String: use the Unicode collation algorithm in String's and Character's conformance to Comparable

rdar://17498444


Swift SVN r20554
This commit is contained in:
Dmitri Hrybenko
2014-07-25 18:32:36 +00:00
parent 61f3cd9e6e
commit ed855afb68
7 changed files with 253 additions and 114 deletions

View File

@@ -184,13 +184,13 @@ extension String {
/// The behavior is equivalent to `NSString.compare()` with default options.
///
/// :returns:
/// * -1 if `lhs < rhs`,
/// * 0 if `lhs == rhs`,
/// * 1 if `lhs > rhs`.
/// * an unspecified value less than zero if `lhs < rhs`,
/// * zero if `lhs == rhs`,
/// * an unspecified value greater than zero if `lhs > rhs`.
@asmname("swift_stdlib_compareNSStringDeterministicUnicodeCollation")
public func _stdlib_compareNSStringDeterministicUnicodeCollation(
lhs: AnyObject, rhs: AnyObject
)-> Int
)-> Int32
extension String: Equatable {
}
@@ -202,11 +202,12 @@ public func ==(lhs: String, rhs: String) -> Bool {
lhs._bridgeToObjectiveCImpl(), rhs._bridgeToObjectiveCImpl()) == 0
}
extension String : Comparable {
}
public func <(lhs: String, rhs: String) -> Bool {
// FIXME: Does lexicographical ordering on component UnicodeScalars,
// but should eventually do a proper unicode String collation. See
// the comment on == for more information.
return lexicographicalCompare(lhs.unicodeScalars, rhs.unicodeScalars)
return _stdlib_compareNSStringDeterministicUnicodeCollation(
lhs._bridgeToObjectiveCImpl(), rhs._bridgeToObjectiveCImpl()) < 0
}
// Support for copy-on-write