Skip to content

Commit a583b38

Browse files
committed
TestFoundation: use bridging for CFStringGetLength
Rather than use CoreFoundation interfaces, use bridging more aggressively to call the CoreFoundation methods. This reduces the dependency on CoreFoundation for the test suite.
1 parent ac845c4 commit a583b38

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

Foundation/String.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@
1212

1313
import CoreFoundation
1414

15+
extension String {
16+
public static let transformStripCombiningMarks: CFString = kCFStringTransformStripCombiningMarks
17+
}
18+
1519
extension String : _ObjectiveCBridgeable {
1620

1721
public typealias _ObjectType = NSString

TestFoundation/TestNSString.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -606,7 +606,7 @@ class TestNSString: LoopbackServerTest {
606606
buf.reserveCapacity(reservedLength)
607607
var usedLen : CFIndex = 0
608608
let _ = buf.withUnsafeMutableBufferPointer { p in
609-
CFStringGetBytes(cfString, CFRangeMake(0, CFStringGetLength(cfString)), CFStringEncoding(kCFStringEncodingUTF16), 0, false, p.baseAddress, reservedLength, &usedLen)
609+
CFStringGetBytes(cfString, CFRangeMake(0, (cfString as! NSString).length), CFStringEncoding(kCFStringEncodingUTF16), 0, false, p.baseAddress, reservedLength, &usedLen)
610610
}
611611

612612
// Make a new string out of it
@@ -1299,11 +1299,11 @@ class TestNSString: LoopbackServerTest {
12991299
}
13001300

13011301
func test_substringFromCFString() {
1302-
let cfString = kCFStringTransformStripCombiningMarks!
1303-
let range = NSRange(location: 0, length: CFStringGetLength(cfString))
1302+
let cfString = String.transformStripCombiningMarks
1303+
let range = NSRange(location: 0, length: unsafeBitCast(cfString, to: NSString.self).length)
13041304
let substring = unsafeBitCast(cfString, to: NSString.self).substring(with: range)
13051305

1306-
XCTAssertEqual(CFStringGetLength(cfString), substring.utf16.count)
1306+
XCTAssertEqual(unsafeBitCast(cfString, to: NSString.self).length, substring.utf16.count)
13071307
}
13081308

13091309
func test_createCopy() {

0 commit comments

Comments
 (0)