Skip to content

[Foundation] Ensure _SwiftNSCharacterSet overrides all abstract metho… #4168

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 17, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion stdlib/public/SDK/Foundation/CharacterSet.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
//===----------------------------------------------------------------------===//

@_exported import Foundation // Clang module
import CoreFoundation

private func _utfRangeToNSRange(_ inRange : Range<UnicodeScalar>) -> NSRange {
return NSMakeRange(Int(inRange.lowerBound.value), Int(inRange.upperBound.value - inRange.lowerBound.value))
Expand Down Expand Up @@ -483,28 +484,37 @@ extension _SwiftNSCharacterSet {

// Immutable

@objc(bitmapRepresentation)
var bitmapRepresentation: Data {
return _mapUnmanaged { $0.bitmapRepresentation }
}

@objc(invertedSet)
var inverted : CharacterSet {
return _mapUnmanaged { $0.inverted }
}

@objc(hasMemberInPlane:)
func hasMember(inPlane plane: UInt8) -> Bool {
return _mapUnmanaged {$0.hasMemberInPlane(plane) }
}

@objc(characterIsMember:)
func characterIsMember(_ member: unichar) -> Bool {
return _mapUnmanaged { $0.characterIsMember(member) }
}

@objc(longCharacterIsMember:)
func longCharacterIsMember(_ member: UTF32Char) -> Bool {
return _mapUnmanaged { $0.longCharacterIsMember(member) }
}

@objc(isSupersetOfSet:)
func isSuperset(of other: CharacterSet) -> Bool {
return _mapUnmanaged { $0.isSuperset(of: other) }
return _mapUnmanaged {
// this is a work around for <rdar://problem/27768939>
return CFCharacterSetIsSupersetOfSet($0 as CFCharacterSet, (other as NSCharacterSet).copy() as! CFCharacterSet)
}
}

}
26 changes: 26 additions & 0 deletions test/1_stdlib/TestCharacterSet.swift
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,28 @@ class TestCharacterSet : TestCharacterSetSuper {
expectNotEqual(anyHashables[0], anyHashables[1])
expectEqual(anyHashables[1], anyHashables[2])
}

func test_superSet() {
let a = CharacterSet.letters.isSuperset(of: CharacterSet(charactersIn: "ab"))
expectTrue(a)
}

func test_union() {
let union = CharacterSet(charactersIn: "ab").union(CharacterSet(charactersIn: "cd"))
let expected = CharacterSet(charactersIn: "abcd")
expectEqual(expected, union)
}

func test_hasMember() {
let contains = CharacterSet.letters.hasMember(inPlane: 1)
expectTrue(contains)
}

func test_bitmap() {
let bitmap = CharacterSet(charactersIn: "ab").bitmapRepresentation
expectEqual(0x6, bitmap[12])
expectEqual(8192, bitmap.count)
}
}


Expand All @@ -195,6 +217,10 @@ CharacterSetTests.test("testBasics") { TestCharacterSet().testBasics() }
CharacterSetTests.test("test_classForCoder") { TestCharacterSet().test_classForCoder() }
CharacterSetTests.test("test_AnyHashableContainingCharacterSet") { TestCharacterSet().test_AnyHashableContainingCharacterSet() }
CharacterSetTests.test("test_AnyHashableCreatedFromNSCharacterSet") { TestCharacterSet().test_AnyHashableCreatedFromNSCharacterSet() }
CharacterSetTests.test("test_superSet") { TestCharacterSet().test_superSet() }
CharacterSetTests.test("test_union") { TestCharacterSet().test_union() }
CharacterSetTests.test("test_hasMember") { TestCharacterSet().test_hasMember() }
CharacterSetTests.test("test_bitmap") { TestCharacterSet().test_bitmap() }
runAllTests()
#endif