Files
swift-mirror/stdlib/objc/Foundation/MixedStringNSStringOperations.swift.gyb
Maxwell Swadling 2eb96bafee [stdlib] reverted removal of mixed string type operators
Fixes rdar://problem/19656287

This reverts changes from r24931, r24911, r24760 and r24536.

Swift SVN r24938
2015-02-04 04:01:32 +00:00

73 lines
2.1 KiB
Swift

//===--- MixedStringNSStringOperations.swift.gyb --------------*- swift -*-===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2015 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See http://swift.org/LICENSE.txt for license information
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//
//
// Mixed-type comparisons between String and NSString.
//
% for op in [ '==', '!=', '<', '<=', '>=', '>' ]:
@transparent
public func ${op} (lhs: String, rhs: NSString) -> Bool {
// FIXME(performance): constructing a temporary string is extremely
// wasteful and inefficient.
return lhs ${op} (rhs as String)
}
@transparent
public func ${op} (lhs: NSString, rhs: String) -> Bool {
// FIXME(performance): constructing a temporary string is extremely
// wasteful and inefficient.
return (lhs as String) ${op} rhs
}
% end
public func != (lhs: String, rhs: String) -> Bool {
// FIXME(performance): constructing a temporary string is extremely
// wasteful and inefficient.
return !(lhs == rhs)
}
public func <= (lhs: String, rhs: String) -> Bool {
// FIXME(performance): constructing a temporary string is extremely
// wasteful and inefficient.
return !(rhs < lhs)
}
public func >= (lhs: String, rhs: String) -> Bool {
// FIXME(performance): constructing a temporary string is extremely
// wasteful and inefficient.
return !(lhs < rhs)
}
public func > (lhs: String, rhs: String) -> Bool {
// FIXME(performance): constructing a temporary string is extremely
// wasteful and inefficient.
return rhs < lhs
}
// This overload is required to disambiguate homogeneous NSString/NSString
// comparisons in non-generic code.
@transparent
public func == (lhs: NSString, rhs: NSString) -> Bool {
return lhs as NSObject == rhs as NSObject
}
// This overload is required to disambiguate homogeneous NSString/NSString
// comparisons in non-generic code.
@transparent
public func != (lhs: NSString, rhs: NSString) -> Bool {
return !(lhs == rhs)
}