mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
[stdlib] String internal API review changes
I had to XFAIL test/ClangModules/cf.swift, which is failing for reasons I can't understand. <rdar://problem/16911496> Swift SVN r18071
This commit is contained in:
@@ -99,8 +99,7 @@ extension String {
|
||||
func withCString<Result>(
|
||||
f: (CString)->Result
|
||||
) -> Result {
|
||||
var u8 = self.nulTerminatedUTF8()
|
||||
return u8.buffer.withUnsafePointerToElements {
|
||||
return self.nulTerminatedUTF8.withUnsafePointerToElements {
|
||||
f(CString($0))
|
||||
}
|
||||
}
|
||||
@@ -111,8 +110,7 @@ extension String {
|
||||
func withCString<Result>(
|
||||
f: (UnsafePointer<CChar>)->Result
|
||||
) -> Result {
|
||||
var u8 = self.nulTerminatedUTF8()
|
||||
return u8.buffer.withUnsafePointerToElements {
|
||||
return self.nulTerminatedUTF8.withUnsafePointerToElements {
|
||||
f(UnsafePointer($0))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -75,8 +75,7 @@ extension String {
|
||||
}
|
||||
|
||||
extension String {
|
||||
// FIXME: Locales make this interesting
|
||||
var uppercase : String {
|
||||
var uppercaseString : String {
|
||||
let end = utf8.endIndex
|
||||
var resultArray = NativeArray<UTF8.CodeUnit>(count: countElements(utf8),
|
||||
value: 0)
|
||||
@@ -112,7 +111,7 @@ extension String {
|
||||
return String(UTF8.self, input: resultArray)
|
||||
}
|
||||
|
||||
var lowercase : String {
|
||||
var lowercaseString : String {
|
||||
let end = utf8.endIndex
|
||||
var resultArray = NativeArray<UTF8.CodeUnit>(count: countElements(utf8),
|
||||
value: 0)
|
||||
@@ -158,17 +157,17 @@ extension String {
|
||||
return true
|
||||
}
|
||||
|
||||
func startsWith(prefix: String) -> Bool {
|
||||
func hasPrefix(prefix: String) -> Bool {
|
||||
return Swift.startsWith(self, prefix)
|
||||
}
|
||||
|
||||
func endsWith(suffix: String) -> Bool {
|
||||
func hasSuffix(suffix: String) -> Bool {
|
||||
return Swift.startsWith(Reverse(self), Reverse(suffix))
|
||||
}
|
||||
|
||||
func isAlpha() -> Bool { return _isAll({ $0.isAlpha() }) }
|
||||
func isDigit() -> Bool { return _isAll({ $0.isDigit() }) }
|
||||
func isSpace() -> Bool { return _isAll({ $0.isSpace() }) }
|
||||
func _isAlpha() -> Bool { return _isAll({ $0.isAlpha() }) }
|
||||
func _isDigit() -> Bool { return _isAll({ $0.isDigit() }) }
|
||||
func _isSpace() -> Bool { return _isAll({ $0.isSpace() }) }
|
||||
}
|
||||
|
||||
/// \brief Represent a positive integer value in the given radix,
|
||||
@@ -215,9 +214,9 @@ func _formatSignedInteger(
|
||||
// Conversions to string from other types.
|
||||
extension String {
|
||||
|
||||
init(_ v: Int64, radix: Int = 10, uppercase: Bool = false) {
|
||||
init(_ v: Int64, radix: Int = 10, _uppercase: Bool = false) {
|
||||
var format = _formatSignedInteger(v, UInt64(radix),
|
||||
ten: uppercase ? "A" : "a")
|
||||
ten: _uppercase ? "A" : "a")
|
||||
var asciiCount = 0
|
||||
format(stream: { _ in ++asciiCount;() })
|
||||
var buffer = _StringBuffer(
|
||||
@@ -228,9 +227,9 @@ extension String {
|
||||
}
|
||||
|
||||
// FIXME: This function assumes UTF16
|
||||
init(_ v: UInt64, radix: Int = 10, uppercase: Bool = false) {
|
||||
init(_ v: UInt64, radix: Int = 10, _uppercase: Bool = false) {
|
||||
var format = _formatPositiveInteger(v, UInt64(radix),
|
||||
ten: uppercase ? "A" : "a")
|
||||
ten: _uppercase ? "A" : "a")
|
||||
var asciiCount = v == 0 ? 1 : 0
|
||||
format(stream: { _ in ++asciiCount;() })
|
||||
var buffer = _StringBuffer(
|
||||
@@ -243,40 +242,44 @@ extension String {
|
||||
self = String(buffer)
|
||||
}
|
||||
|
||||
init(_ v : Int8, radix : Int = 10, uppercase : Bool = false) {
|
||||
self = String(Int64(v), radix: radix, uppercase: uppercase)
|
||||
init(_ v : Int8, radix : Int = 10, _uppercase : Bool = false) {
|
||||
self = String(Int64(v), radix: radix, _uppercase: _uppercase)
|
||||
}
|
||||
init(_ v : Int16, radix : Int = 10, uppercase : Bool = false) {
|
||||
self = String(Int64(v), radix: radix, uppercase: uppercase)
|
||||
init(_ v : Int16, radix : Int = 10, _uppercase : Bool = false) {
|
||||
self = String(Int64(v), radix: radix, _uppercase: _uppercase)
|
||||
}
|
||||
init(_ v : Int32, radix : Int = 10, uppercase : Bool = false) {
|
||||
self = String(Int64(v), radix: radix, uppercase: uppercase)
|
||||
init(_ v : Int32, radix : Int = 10, _uppercase : Bool = false) {
|
||||
self = String(Int64(v), radix: radix, _uppercase: _uppercase)
|
||||
}
|
||||
init(_ v : Int, radix : Int = 10, uppercase : Bool = false) {
|
||||
self = String(Int64(v), radix: radix, uppercase: uppercase)
|
||||
init(_ v : Int, radix : Int = 10, _uppercase : Bool = false) {
|
||||
self = String(Int64(v), radix: radix, _uppercase: _uppercase)
|
||||
}
|
||||
init(_ v : UInt8, radix : Int = 10, uppercase : Bool = false) {
|
||||
self = String(UInt64(v), radix: radix, uppercase: uppercase)
|
||||
init(_ v : UInt8, radix : Int = 10, _uppercase : Bool = false) {
|
||||
self = String(UInt64(v), radix: radix, _uppercase: _uppercase)
|
||||
}
|
||||
init(_ v : UInt16, radix : Int = 10, uppercase : Bool = false) {
|
||||
self = String(UInt64(v), radix: radix, uppercase: uppercase)
|
||||
init(_ v : UInt16, radix : Int = 10, _uppercase : Bool = false) {
|
||||
self = String(UInt64(v), radix: radix, _uppercase: _uppercase)
|
||||
}
|
||||
init(_ v : UInt32, radix : Int = 10, uppercase : Bool = false) {
|
||||
self = String(UInt64(v), radix: radix, uppercase: uppercase)
|
||||
init(_ v : UInt32, radix : Int = 10, _uppercase : Bool = false) {
|
||||
self = String(UInt64(v), radix: radix, _uppercase: _uppercase)
|
||||
}
|
||||
init(_ v : UInt, radix : Int = 10, uppercase : Bool = false) {
|
||||
self = String(UInt64(v), radix: radix, uppercase: uppercase)
|
||||
init(_ v : UInt, radix : Int = 10, _uppercase : Bool = false) {
|
||||
self = String(UInt64(v), radix: radix, _uppercase: _uppercase)
|
||||
}
|
||||
|
||||
init(_ v : Double) {
|
||||
typealias _Double = Double
|
||||
typealias _Float = Float
|
||||
typealias _Bool = Bool
|
||||
|
||||
init(_ v : _Double) {
|
||||
self = _doubleToString(v)
|
||||
}
|
||||
|
||||
init(_ v : Float) {
|
||||
init(_ v : _Float) {
|
||||
self = String(Double(v))
|
||||
}
|
||||
|
||||
init(_ b : Bool) {
|
||||
init(_ b : _Bool) {
|
||||
if b {
|
||||
self = "true"
|
||||
} else {
|
||||
@@ -344,7 +347,7 @@ extension String {
|
||||
extension String {
|
||||
/// \brief Produce a substring of the given string from the given character
|
||||
/// index to the end of the string.
|
||||
func substr(start: Int) -> String {
|
||||
func _substr(start: Int) -> String {
|
||||
var rng = unicodeScalars
|
||||
var startIndex = rng.startIndex
|
||||
for i in 0..start {
|
||||
@@ -356,7 +359,7 @@ extension String {
|
||||
/// \brief Split the given string at the given delimiter character, returning
|
||||
/// the strings before and after that character (neither includes the character
|
||||
/// found) and a boolean value indicating whether the delimiter was found.
|
||||
func splitFirst(delim: UnicodeScalar)
|
||||
func _splitFirst(delim: UnicodeScalar)
|
||||
-> (before: String, after: String, wasFound : Bool)
|
||||
{
|
||||
var rng = unicodeScalars
|
||||
@@ -372,7 +375,7 @@ extension String {
|
||||
/// predicate returns true. Returns the string before that character, the
|
||||
/// character that matches, the string after that character, and a boolean value
|
||||
/// indicating whether any character was found.
|
||||
func splitFirstIf(pred: (UnicodeScalar) -> Bool)
|
||||
func _splitFirstIf(pred: (UnicodeScalar) -> Bool)
|
||||
-> (before: String, found: UnicodeScalar, after: String, wasFound: Bool)
|
||||
{
|
||||
var rng = unicodeScalars
|
||||
@@ -387,7 +390,7 @@ extension String {
|
||||
/// \brief Split the given string at each occurrence of a character for which
|
||||
/// the given predicate evaluates true, returning an array of strings that
|
||||
/// before/between/after those delimiters.
|
||||
func splitIf(pred: (UnicodeScalar) -> Bool) -> String[] {
|
||||
func _splitIf(pred: (UnicodeScalar) -> Bool) -> String[] {
|
||||
var scalarSlices = Swift.split(unicodeScalars, pred)
|
||||
return scalarSlices.map { $0 as String }
|
||||
}
|
||||
|
||||
@@ -197,7 +197,7 @@ extension String {
|
||||
return core.elementWidth == 1 ? core.startASCII : nil
|
||||
}
|
||||
|
||||
func nulTerminatedUTF8() -> NativeArray<UTF8.CodeUnit> {
|
||||
var nulTerminatedUTF8: NativeArray<UTF8.CodeUnit> {
|
||||
var result = NativeArray<UTF8.CodeUnit>()
|
||||
result.reserve(countElements(utf8) + 1)
|
||||
result += utf8
|
||||
|
||||
@@ -10,158 +10,160 @@
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
func ==(lhs: UnicodeScalarView.IndexType, rhs: UnicodeScalarView.IndexType) -> Bool {
|
||||
func ==(lhs: String.UnicodeScalarView.IndexType, rhs: String.UnicodeScalarView.IndexType) -> Bool {
|
||||
return lhs._position == rhs._position
|
||||
}
|
||||
|
||||
struct UnicodeScalarView : Sliceable, Sequence {
|
||||
init(_ _base: _StringCore) {
|
||||
self._base = _base
|
||||
}
|
||||
|
||||
struct ScratchGenerator : Generator {
|
||||
var base :_StringCore
|
||||
var idx : Int
|
||||
init(_ core : _StringCore, _ pos : Int) {
|
||||
idx = pos
|
||||
base = core
|
||||
}
|
||||
mutating func next() -> UTF16.CodeUnit? {
|
||||
return self.base[idx++]
|
||||
}
|
||||
}
|
||||
|
||||
// FIXME: This index should probably become bidirectional, as UTF16
|
||||
// is traversable in either direction.
|
||||
struct IndexType : BidirectionalIndex {
|
||||
init(_ _position: Int, _ _base: _StringCore) {
|
||||
self._position = _position
|
||||
extension String {
|
||||
struct UnicodeScalarView : Sliceable, Sequence {
|
||||
init(_ _base: _StringCore) {
|
||||
self._base = _base
|
||||
}
|
||||
|
||||
func succ() -> IndexType {
|
||||
var scratch = ScratchGenerator(_base, _position)
|
||||
UTF16.decode(&scratch)
|
||||
return IndexType(scratch.idx, _base)
|
||||
struct ScratchGenerator : Generator {
|
||||
var base :_StringCore
|
||||
var idx : Int
|
||||
init(_ core : _StringCore, _ pos : Int) {
|
||||
idx = pos
|
||||
base = core
|
||||
}
|
||||
mutating func next() -> UTF16.CodeUnit? {
|
||||
return self.base[idx++]
|
||||
}
|
||||
}
|
||||
|
||||
func pred() -> IndexType {
|
||||
var i = _position
|
||||
let codeUnit = self._base[--i]
|
||||
if codeUnit >= 0xD800 && codeUnit <= 0xE000 {
|
||||
--i
|
||||
// FIXME: This index should probably become bidirectional, as UTF16
|
||||
// is traversable in either direction.
|
||||
struct IndexType : BidirectionalIndex {
|
||||
init(_ _position: Int, _ _base: _StringCore) {
|
||||
self._position = _position
|
||||
self._base = _base
|
||||
}
|
||||
return IndexType(i, _base)
|
||||
|
||||
func succ() -> IndexType {
|
||||
var scratch = ScratchGenerator(_base, _position)
|
||||
UTF16.decode(&scratch)
|
||||
return IndexType(scratch.idx, _base)
|
||||
}
|
||||
|
||||
func pred() -> IndexType {
|
||||
var i = _position
|
||||
let codeUnit = self._base[--i]
|
||||
if codeUnit >= 0xD800 && codeUnit <= 0xE000 {
|
||||
--i
|
||||
}
|
||||
return IndexType(i, _base)
|
||||
}
|
||||
|
||||
var _position: Int
|
||||
var _base: _StringCore
|
||||
}
|
||||
|
||||
var startIndex: IndexType {
|
||||
return IndexType(_base.startIndex, _base)
|
||||
}
|
||||
|
||||
var _position: Int
|
||||
var endIndex: IndexType {
|
||||
return IndexType(_base.endIndex, _base)
|
||||
}
|
||||
|
||||
subscript(i: IndexType) -> UnicodeScalar {
|
||||
var scratch = ScratchGenerator(_base, i._position)
|
||||
return UTF16.decode(&scratch)!
|
||||
}
|
||||
|
||||
func __slice__(start: IndexType, end: IndexType) -> UnicodeScalarView {
|
||||
return UnicodeScalarView(_base[start._position..end._position])
|
||||
}
|
||||
|
||||
subscript(r: Range<IndexType>) -> UnicodeScalarView {
|
||||
return UnicodeScalarView(_base[r.startIndex._position..r.endIndex._position])
|
||||
}
|
||||
|
||||
struct GeneratorType : Generator {
|
||||
init(_ _base: _StringCore.GeneratorType) {
|
||||
self._base = _base
|
||||
}
|
||||
|
||||
mutating func next() -> UnicodeScalar? {
|
||||
return UTF16.decode(&self._base)
|
||||
}
|
||||
var _base: _StringCore.GeneratorType
|
||||
}
|
||||
|
||||
func generate() -> GeneratorType {
|
||||
return GeneratorType(_base.generate())
|
||||
}
|
||||
|
||||
@conversion
|
||||
func __conversion() -> String {
|
||||
return String(_base)
|
||||
}
|
||||
|
||||
func compare(other : UnicodeScalarView) -> Int {
|
||||
// Try to compare the string without decoding
|
||||
// the UTF16 string.
|
||||
var AIdx = self._base.startIndex
|
||||
var BIdx = other._base.startIndex
|
||||
var AEnd = self._base.endIndex
|
||||
var BEnd = other._base.endIndex
|
||||
while true {
|
||||
if AIdx < AEnd {
|
||||
if BIdx < BEnd {
|
||||
let e1 = self._base[AIdx]
|
||||
let e2 = other._base[BIdx]
|
||||
if (e1 >= 0x80 || e2 >= 0x80) {
|
||||
// Use slow unicode comparator if
|
||||
// we found multi-byte scalar.
|
||||
return _compareUnicode(other)
|
||||
}
|
||||
|
||||
if e1 < e2 {
|
||||
return -1
|
||||
}
|
||||
if e2 < e1 {
|
||||
return 1
|
||||
}
|
||||
AIdx++
|
||||
BIdx++
|
||||
continue // equivalent
|
||||
}
|
||||
return 1
|
||||
}
|
||||
if BIdx < BEnd {
|
||||
return -1
|
||||
}
|
||||
return 0
|
||||
}
|
||||
}
|
||||
|
||||
func _compareUnicode(other : UnicodeScalarView) -> Int {
|
||||
var g1 = self.generate()
|
||||
var g2 = other.generate()
|
||||
while true {
|
||||
let e1_ = g1.next()
|
||||
let e2_ = g2.next()
|
||||
if let e1 = e1_ {
|
||||
if let e2 = e2_ {
|
||||
if e1 < e2 {
|
||||
return -1
|
||||
}
|
||||
if e2 < e1 {
|
||||
return 1
|
||||
}
|
||||
continue // equivalent
|
||||
}
|
||||
return 1
|
||||
}
|
||||
if e2_ {
|
||||
return -1
|
||||
}
|
||||
return 0
|
||||
}
|
||||
}
|
||||
|
||||
var _base: _StringCore
|
||||
}
|
||||
|
||||
var startIndex: IndexType {
|
||||
return IndexType(_base.startIndex, _base)
|
||||
}
|
||||
|
||||
var endIndex: IndexType {
|
||||
return IndexType(_base.endIndex, _base)
|
||||
}
|
||||
|
||||
subscript(i: IndexType) -> UnicodeScalar {
|
||||
var scratch = ScratchGenerator(_base, i._position)
|
||||
return UTF16.decode(&scratch)!
|
||||
}
|
||||
|
||||
func __slice__(start: IndexType, end: IndexType) -> UnicodeScalarView {
|
||||
return UnicodeScalarView(_base[start._position..end._position])
|
||||
}
|
||||
|
||||
subscript(r: Range<IndexType>) -> UnicodeScalarView {
|
||||
return UnicodeScalarView(_base[r.startIndex._position..r.endIndex._position])
|
||||
}
|
||||
|
||||
struct GeneratorType : Generator {
|
||||
init(_ _base: _StringCore.GeneratorType) {
|
||||
self._base = _base
|
||||
}
|
||||
|
||||
mutating func next() -> UnicodeScalar? {
|
||||
return UTF16.decode(&self._base)
|
||||
}
|
||||
var _base: _StringCore.GeneratorType
|
||||
}
|
||||
|
||||
func generate() -> GeneratorType {
|
||||
return GeneratorType(_base.generate())
|
||||
}
|
||||
|
||||
@conversion
|
||||
func __conversion() -> String {
|
||||
return String(_base)
|
||||
}
|
||||
|
||||
func compare(other : UnicodeScalarView) -> Int {
|
||||
// Try to compare the string without decoding
|
||||
// the UTF16 string.
|
||||
var AIdx = self._base.startIndex
|
||||
var BIdx = other._base.startIndex
|
||||
var AEnd = self._base.endIndex
|
||||
var BEnd = other._base.endIndex
|
||||
while true {
|
||||
if AIdx < AEnd {
|
||||
if BIdx < BEnd {
|
||||
let e1 = self._base[AIdx]
|
||||
let e2 = other._base[BIdx]
|
||||
if (e1 >= 0x80 || e2 >= 0x80) {
|
||||
// Use slow unicode comparator if
|
||||
// we found multi-byte scalar.
|
||||
return _compareUnicode(other)
|
||||
}
|
||||
|
||||
if e1 < e2 {
|
||||
return -1
|
||||
}
|
||||
if e2 < e1 {
|
||||
return 1
|
||||
}
|
||||
AIdx++
|
||||
BIdx++
|
||||
continue // equivalent
|
||||
}
|
||||
return 1
|
||||
}
|
||||
if BIdx < BEnd {
|
||||
return -1
|
||||
}
|
||||
return 0
|
||||
}
|
||||
}
|
||||
|
||||
func _compareUnicode(other : UnicodeScalarView) -> Int {
|
||||
var g1 = self.generate()
|
||||
var g2 = other.generate()
|
||||
while true {
|
||||
let e1_ = g1.next()
|
||||
let e2_ = g2.next()
|
||||
if let e1 = e1_ {
|
||||
if let e2 = e2_ {
|
||||
if e1 < e2 {
|
||||
return -1
|
||||
}
|
||||
if e2 < e1 {
|
||||
return 1
|
||||
}
|
||||
continue // equivalent
|
||||
}
|
||||
return 1
|
||||
}
|
||||
if e2_ {
|
||||
return -1
|
||||
}
|
||||
return 0
|
||||
}
|
||||
}
|
||||
|
||||
var _base: _StringCore
|
||||
}
|
||||
|
||||
extension String {
|
||||
|
||||
@@ -738,25 +738,6 @@ extension String {
|
||||
return _ns.hash
|
||||
}
|
||||
|
||||
// - (BOOL)hasPrefix:(NSString *)aString
|
||||
|
||||
/// \brief Returns a Boolean value that indicates whether a given
|
||||
/// string matches the beginning characters of the receiver.
|
||||
|
||||
func hasPrefix(aString: String) -> Bool {
|
||||
return _ns.hasPrefix(aString)
|
||||
}
|
||||
|
||||
// - (BOOL)hasSuffix:(NSString *)aString
|
||||
|
||||
/// \brief Returns a Boolean value that indicates whether a given
|
||||
/// string matches the ending characters of the receiver.
|
||||
|
||||
func hasSuffix(aString: String) -> Bool {
|
||||
return _ns.hasSuffix(aString)
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
Nothing to do here; already provided for String
|
||||
|
||||
@@ -1075,13 +1056,6 @@ extension String {
|
||||
return self.longLongValue
|
||||
}
|
||||
|
||||
// @property NSString * lowercaseString
|
||||
|
||||
/// \brief Returns lowercased representation of the receiver.
|
||||
var lowercaseString: String {
|
||||
return _ns.lowercaseString
|
||||
}
|
||||
|
||||
// - (NSString *)lowercaseStringWithLocale:(NSLocale *)locale
|
||||
|
||||
/// \brief Returns a version of the string with all letters
|
||||
@@ -1481,12 +1455,6 @@ extension String {
|
||||
return _ns.substringWithRange(aRange)
|
||||
}
|
||||
|
||||
// @property NSString* uppercaseString;
|
||||
|
||||
/// \brief Returns a uppercased representation of the receiver.
|
||||
var uppercaseString: String {
|
||||
return _ns.uppercaseString
|
||||
}
|
||||
|
||||
// - (NSString *)uppercaseStringWithLocale:(NSLocale *)locale
|
||||
|
||||
|
||||
@@ -66,9 +66,9 @@ extension Selector : Equatable, Hashable {
|
||||
|
||||
extension String {
|
||||
/// \brief Construct the C string representation of an Objective-C selector.
|
||||
init(_ sel: Selector) {
|
||||
init(_sel: Selector) {
|
||||
// FIXME: This misses the ASCII optimization.
|
||||
self = String.fromCString(sel_getName(sel))
|
||||
self = String.fromCString(sel_getName(_sel))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
// RUN: rm -rf %t/clang-module-cache
|
||||
// RUN: %swift -parse -verify -import-cf-types -module-cache-path %t/clang-module-cache -I %S/Inputs/custom-modules -target x86_64-apple-darwin13 %s
|
||||
// XFAIL: *
|
||||
|
||||
import CoreCooling
|
||||
|
||||
|
||||
@@ -182,7 +182,7 @@ var sub1Result : String = obj[5]!
|
||||
var sub2Result : Int = obj[A()]!
|
||||
|
||||
// Subscript then call without the '!'
|
||||
var sub1ResultNE = obj[5].startsWith("foo")
|
||||
var sub1ResultNE = obj[5].hasPrefix("foo")
|
||||
var sub2ResultNE = obj[A()].hashValue
|
||||
|
||||
// Property/function ambiguities.
|
||||
|
||||
@@ -35,7 +35,7 @@ yf.f1(i, y: 1)
|
||||
Swift.print(3)
|
||||
|
||||
var format : String
|
||||
format.splitFirstIf({ $0.isAlpha() })
|
||||
format._splitFirstIf({ $0.isAlpha() })
|
||||
|
||||
// Archetypes
|
||||
func doGetLogicValue<T : LogicValue>(t: T) {
|
||||
@@ -80,7 +80,7 @@ struct GZ<T> {
|
||||
// Members of literals
|
||||
// FIXME: Crappy diagnostic
|
||||
"foo".lower() // expected-error{{could not find member 'lower'}}
|
||||
var tmp = "foo".lowercase
|
||||
var tmp = "foo".lowercaseString
|
||||
|
||||
// Members of modules
|
||||
var myTrue = Swift.true
|
||||
|
||||
@@ -28,6 +28,6 @@ println(xxx)
|
||||
|
||||
// FIXME: compilation fails without the temporary yyy
|
||||
var yyy = sort(["apple", "Banana", "cherry"],
|
||||
{ $0.lowercase > $1.lowercase })
|
||||
{ $0.lowercaseString > $1.lowercaseString })
|
||||
println(yyy)
|
||||
// CHECK-NEXT: [cherry, Banana, apple]
|
||||
|
||||
@@ -15,6 +15,6 @@ println("Nested \"\(HW)\" with Pi = \(pi)!")
|
||||
|
||||
// CHECK: value = 1099226349619 hex = 0xFFEEFF0033 oct = 0o17775677600063
|
||||
var someval = 0xFFeeFF0033
|
||||
println("value = \(someval) hex = 0x\(someval, radix:16, uppercase : true) oct = 0o\(someval, radix:8)")
|
||||
println("value = \(someval) hex = 0x\(someval, radix:16, _uppercase : true) oct = 0o\(someval, radix:8)")
|
||||
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
// String Splits
|
||||
//===----------------------------------------------------------------------===//
|
||||
if true {
|
||||
var (before, after, found) = "foo.bar".splitFirst(".")
|
||||
var (before, after, found) = "foo.bar"._splitFirst(".")
|
||||
assert(found)
|
||||
assert(before == "foo")
|
||||
assert(after == "bar")
|
||||
@@ -18,7 +18,7 @@ println("OKAY")
|
||||
//===----------------------------------------------------------------------===//
|
||||
if true {
|
||||
// CHECK-NEXT: {{^}}FOOBAR.WIBBLE{{$}}
|
||||
println("FooBar.Wibble".uppercase)
|
||||
println("FooBar.Wibble".uppercaseString)
|
||||
// CHECK-NEXT: {{^}}foobar.wibble{{$}}
|
||||
println("FooBar.Wibble".lowercase)
|
||||
println("FooBar.Wibble".lowercaseString)
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// RUN: %target-run-simple-swift | FileCheck %s
|
||||
|
||||
typealias CodePoints = UnicodeScalarView
|
||||
typealias CodePoints = String.UnicodeScalarView
|
||||
|
||||
extension CodePoints {
|
||||
init(_ x: String) {
|
||||
@@ -39,7 +39,7 @@ func testSplit() {
|
||||
|
||||
// FIXME: Disabled pending <rdar://problem/15736729> and <rdar://problem/15733855>
|
||||
// CHECK-NEXT-DISABLED: [ "", "", "foo bar baz " ]
|
||||
// println(split(CodePoints(" foo bar baz "), { $0.isSpace() }, true, maxSplit:2))
|
||||
// println(split(CodePoints(" foo bar baz "), { $0._isSpace() }, true, maxSplit:2))
|
||||
|
||||
println("done.")
|
||||
}
|
||||
|
||||
@@ -208,9 +208,11 @@ println("so < tocks => \(so < tocks)")
|
||||
// CHECK-NEXT: true
|
||||
println("sox < tocks => \(sox < tocks)")
|
||||
|
||||
let qqq = nonASCIILiteral.hasPrefix("🏂☃")
|
||||
let rrr = nonASCIILiteral.hasPrefix("☃")
|
||||
let zz = (
|
||||
nonASCIILiteral.startsWith("🏂☃"), nonASCIILiteral.startsWith("☃"),
|
||||
nonASCIILiteral.endsWith("⛄️❄️"), nonASCIILiteral.endsWith("☃"))
|
||||
nonASCIILiteral.hasPrefix("🏂☃"), nonASCIILiteral.hasPrefix("☃"),
|
||||
nonASCIILiteral.hasSuffix("⛄️❄️"), nonASCIILiteral.hasSuffix("☃"))
|
||||
|
||||
// CHECK-NEXT: <true, false, true, false>
|
||||
println("<\(zz.0), \(zz.1), \(zz.2), \(zz.3)>")
|
||||
|
||||
Reference in New Issue
Block a user