mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
[stdlib] Begin exposing the NSString API directly on String
Because we're using a "brute-force" combination of conversion to NSString and forwarding, this code will continue to work when String is replaced by NewString. It may not be fast yet, but at least it will flesh out the experience for Cocoa programmers Swift SVN r11034
This commit is contained in:
41
test/stdlib/NSStringAPI.swift
Normal file
41
test/stdlib/NSStringAPI.swift
Normal file
@@ -0,0 +1,41 @@
|
||||
// RUN: rm -rf %t/clang-module-cache
|
||||
// RUN: %swift -i -module-cache-path=%t/clang-module-cache -sdk=%sdk %s | FileCheck %s
|
||||
// REQUIRES: sdk
|
||||
// REQUIRES: swift_interpreter
|
||||
|
||||
import Foundation
|
||||
|
||||
func testClassMethods() {
|
||||
var encodings: NSStringEncoding[] = String.availableStringEncodings()
|
||||
// CHECK: available encodings found
|
||||
// CHECK-NOT: 0 available encodings
|
||||
println("\(encodings.count) available encodings found")
|
||||
|
||||
// CHECK-NEXT: defaultCStringEncoding is available
|
||||
var defaultCStringEncoding = String.defaultCStringEncoding()
|
||||
for e in encodings {
|
||||
if e == defaultCStringEncoding {
|
||||
println("defaultCStringEncoding is available")
|
||||
}
|
||||
}
|
||||
|
||||
// CHECK-NEXT: It is called
|
||||
println("It is called \"\(String.localizedNameOfStringEncoding(defaultCStringEncoding))\"")
|
||||
|
||||
var path = String.pathWithComponents(["flugelhorn", "baritone", "bass"])
|
||||
// CHECK-NEXT: <flugelhorn/baritone/bass>
|
||||
println("<\(path)>")
|
||||
|
||||
// CHECK-NEXT: true
|
||||
println(String.string() == "")
|
||||
|
||||
// CHECK-NEXT: <sox>
|
||||
var chars: unichar[] = [ unichar('s'.value), unichar('o'.value), unichar('x'.value) ]
|
||||
var sox: String = String.stringWithCharacters(chars.base, chars.count)
|
||||
println("<\(sox)>")
|
||||
}
|
||||
|
||||
|
||||
testClassMethods()
|
||||
// CHECK: done!
|
||||
println("done!")
|
||||
Reference in New Issue
Block a user