Skip to content

Commit 6a8845a

Browse files
committed
Merge pull request #2 from apple/master
Pulling latest changes
2 parents 8ef9ba7 + a946561 commit 6a8845a

File tree

7 files changed

+93
-5
lines changed

7 files changed

+93
-5
lines changed

Foundation.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,7 @@
196196
5BF7AEBF1BCD51F9008F214A /* NSURL.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5BDC3F4A1BCC5DCB00ED97BB /* NSURL.swift */; };
197197
5BF7AEC01BCD51F9008F214A /* NSUUID.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5BDC3F4B1BCC5DCB00ED97BB /* NSUUID.swift */; };
198198
5BF7AEC11BCD51F9008F214A /* NSValue.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5BDC3F4C1BCC5DCB00ED97BB /* NSValue.swift */; };
199+
84BA558E1C16F90900F48C54 /* TestNSTimeZone.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84BA558D1C16F90900F48C54 /* TestNSTimeZone.swift */; };
199200
C93559291C12C49F009FD6A9 /* TestNSAffineTransform.swift in Sources */ = {isa = PBXBuildFile; fileRef = C93559281C12C49F009FD6A9 /* TestNSAffineTransform.swift */; };
200201
E876A73E1C1180E000F279EC /* TestNSRange.swift in Sources */ = {isa = PBXBuildFile; fileRef = E876A73D1C1180E000F279EC /* TestNSRange.swift */; };
201202
EA66F6361BEED03E00136161 /* TargetConditionals.h in Headers */ = {isa = PBXBuildFile; fileRef = EA66F6351BEED03E00136161 /* TargetConditionals.h */; settings = {ATTRIBUTES = (Public, ); }; };
@@ -519,6 +520,7 @@
519520
5BDC3FCF1BCF17E600ED97BB /* NSCFSet.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NSCFSet.swift; sourceTree = "<group>"; };
520521
5BDC405C1BD6D83B00ED97BB /* TestFoundation.app */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = TestFoundation.app; sourceTree = BUILT_PRODUCTS_DIR; };
521522
5BF7AEC21BCD568D008F214A /* ForSwiftFoundationOnly.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ForSwiftFoundationOnly.h; sourceTree = "<group>"; };
523+
84BA558D1C16F90900F48C54 /* TestNSTimeZone.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TestNSTimeZone.swift; sourceTree = "<group>"; };
522524
C93559281C12C49F009FD6A9 /* TestNSAffineTransform.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TestNSAffineTransform.swift; sourceTree = "<group>"; };
523525
E876A73D1C1180E000F279EC /* TestNSRange.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TestNSRange.swift; sourceTree = "<group>"; };
524526
EA313DFC1BE7F2E90060A403 /* CFURLComponents_Internal.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CFURLComponents_Internal.h; sourceTree = "<group>"; };
@@ -1024,6 +1026,7 @@
10241026
525AECEB1BF2C96400D15BB0 /* TestNSFileManager.swift */,
10251027
5B40F9F11C125187000E72E3 /* TestNSXMLParser.swift */,
10261028
22B9C1E01C165D7A00DECFF9 /* TestNSDate.swift */,
1029+
84BA558D1C16F90900F48C54 /* TestNSTimeZone.swift */,
10271030
);
10281031
name = Tests;
10291032
sourceTree = "<group>";
@@ -1711,6 +1714,7 @@
17111714
E876A73E1C1180E000F279EC /* TestNSRange.swift in Sources */,
17121715
EA66F6521BF1619600136161 /* TestNSPropertyList.swift in Sources */,
17131716
4DC1D0801C12EEEF00B5948A /* TestNSPipe.swift in Sources */,
1717+
84BA558E1C16F90900F48C54 /* TestNSTimeZone.swift in Sources */,
17141718
52829AD71C160D64003BC4EF /* TestNSCalendar.swift in Sources */,
17151719
C93559291C12C49F009FD6A9 /* TestNSAffineTransform.swift in Sources */,
17161720
EA66F64E1BF1619600136161 /* TestNSIndexSet.swift in Sources */,

Foundation/NSObject.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,3 +127,9 @@ extension NSObject : Equatable, Hashable {
127127
public func ==(lhs: NSObject, rhs: NSObject) -> Bool {
128128
return lhs.isEqual(rhs)
129129
}
130+
131+
extension NSObject : CustomDebugStringConvertible {
132+
}
133+
134+
extension NSObject : CustomStringConvertible {
135+
}

Foundation/NSString.swift

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -405,15 +405,39 @@ extension NSString {
405405
}
406406

407407
public func rangeOfCharacterFromSet(searchSet: NSCharacterSet) -> NSRange {
408-
NSUnimplemented()
408+
return rangeOfCharacterFromSet(searchSet, options: [])
409409
}
410410

411411
public func rangeOfCharacterFromSet(searchSet: NSCharacterSet, options mask: NSStringCompareOptions) -> NSRange {
412-
NSUnimplemented()
412+
return rangeOfCharacterFromSet(searchSet, options: mask, range: NSMakeRange(0, length))
413413
}
414414

415415
public func rangeOfCharacterFromSet(searchSet: NSCharacterSet, options mask: NSStringCompareOptions, range searchRange: NSRange) -> NSRange {
416-
NSUnimplemented()
416+
if mask.contains(.RegularExpressionSearch) {
417+
NSUnimplemented()
418+
}
419+
if searchRange.length == 0 {
420+
return NSMakeRange(NSNotFound, 0)
421+
}
422+
423+
#if os(Linux)
424+
var cfflags = CFStringCompareFlags(mask.rawValue)
425+
if mask.contains(.LiteralSearch) {
426+
cfflags |= UInt(kCFCompareNonliteral)
427+
}
428+
#else
429+
var cfflags = CFStringCompareFlags(rawValue: mask.rawValue)
430+
if mask.contains(.LiteralSearch) {
431+
cfflags.unionInPlace(.CompareNonliteral)
432+
}
433+
#endif
434+
var result = CFRangeMake(kCFNotFound, 0)
435+
436+
if CFStringFindCharacterFromSet(_cfObject, searchSet._cfObject, CFRangeMake(searchRange.location, searchRange.length), cfflags, &result) {
437+
return NSMakeRange(result.location, result.length)
438+
} else {
439+
return NSMakeRange(NSNotFound, 0)
440+
}
417441
}
418442

419443
public func rangeOfComposedCharacterSequenceAtIndex(index: Int) -> NSRange {

Foundation/NSTimeZone.swift

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,15 @@ extension NSTimeZone {
162162
public class func timeZoneDataVersion() -> String { NSUnimplemented() }
163163

164164
public var secondsFromGMT: Int { NSUnimplemented() }
165-
public var abbreviation: String? { NSUnimplemented() }
165+
166+
/// The abbreviation for the receiver, such as "EDT" (Eastern Daylight Time). (read-only)
167+
///
168+
/// This invokes `abbreviationForDate:` with the current date as the argument.
169+
public var abbreviation: String? {
170+
let currentDate = NSDate()
171+
return abbreviationForDate(currentDate)
172+
}
173+
166174
public var daylightSavingTime: Bool { NSUnimplemented() }
167175
public var daylightSavingTimeOffset: NSTimeInterval { NSUnimplemented() }
168176
/*@NSCopying*/ public var nextDaylightSavingTimeTransition: NSDate? { NSUnimplemented() }

TestFoundation/TestNSString.swift

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ class TestNSString : XCTestCase {
3434
("test_FromNullTerminatedCStringInASCII", test_FromNullTerminatedCStringInASCII ),
3535
("test_FromNullTerminatedCStringInUTF8", test_FromNullTerminatedCStringInUTF8 ),
3636
("test_FromMalformedNullTerminatedCStringInUTF8", test_FromMalformedNullTerminatedCStringInUTF8 ),
37+
("test_rangeOfCharacterFromSet", test_rangeOfCharacterFromSet ),
3738
]
3839
}
3940

@@ -141,4 +142,14 @@ class TestNSString : XCTestCase {
141142
let string = NSString(CString: bytes.map { Int8(bitPattern: $0) }, encoding: NSUTF8StringEncoding)
142143
XCTAssertNil(string)
143144
}
144-
}
145+
146+
func test_rangeOfCharacterFromSet() {
147+
let string: NSString = "0Az"
148+
let letters = NSCharacterSet.letterCharacterSet()
149+
let decimalDigits = NSCharacterSet.decimalDigitCharacterSet()
150+
XCTAssertEqual(string.rangeOfCharacterFromSet(letters).location, 1)
151+
XCTAssertEqual(string.rangeOfCharacterFromSet(decimalDigits).location, 0)
152+
XCTAssertEqual(string.rangeOfCharacterFromSet(letters, options: [.BackwardsSearch]).location, 2)
153+
XCTAssertEqual(string.rangeOfCharacterFromSet(letters, options: [], range: NSMakeRange(2, 1)).location, 2)
154+
}
155+
}

TestFoundation/TestNSTimeZone.swift

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// This source file is part of the Swift.org open source project
2+
//
3+
// Copyright (c) 2014 - 2015 Apple Inc. and the Swift project authors
4+
// Licensed under Apache License v2.0 with Runtime Library Exception
5+
//
6+
// See http://swift.org/LICENSE.txt for license information
7+
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
8+
//
9+
10+
11+
12+
#if DEPLOYMENT_RUNTIME_OBJC || os(Linux)
13+
import Foundation
14+
import XCTest
15+
#else
16+
import SwiftFoundation
17+
import SwiftXCTest
18+
#endif
19+
20+
21+
22+
class TestNSTimeZone: XCTestCase {
23+
24+
var allTests : [(String, () -> ())] {
25+
return [
26+
("test_abbreviation", test_abbreviation),
27+
]
28+
}
29+
30+
func test_abbreviation() {
31+
let tz = NSTimeZone.systemTimeZone()
32+
XCTAssertEqual(tz.abbreviation, tz.abbreviationForDate(NSDate()))
33+
}
34+
}

TestFoundation/main.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,5 @@ XCTMain([
3737
TestNSRange(),
3838
TestNSXMLParser(),
3939
TestNSDate(),
40+
TestNSTimeZone(),
4041
])

0 commit comments

Comments
 (0)