-
Notifications
You must be signed in to change notification settings - Fork 1.2k
implement NSString.rangeOfCharacterFromSet #75
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -405,15 +405,39 @@ extension NSString { | |
} | ||
|
||
public func rangeOfCharacterFromSet(searchSet: NSCharacterSet) -> NSRange { | ||
NSUnimplemented() | ||
return rangeOfCharacterFromSet(searchSet, options: []) | ||
} | ||
|
||
public func rangeOfCharacterFromSet(searchSet: NSCharacterSet, options mask: NSStringCompareOptions) -> NSRange { | ||
NSUnimplemented() | ||
return rangeOfCharacterFromSet(searchSet, options: mask, range: NSMakeRange(0, length)) | ||
} | ||
|
||
public func rangeOfCharacterFromSet(searchSet: NSCharacterSet, options mask: NSStringCompareOptions, range searchRange: NSRange) -> NSRange { | ||
NSUnimplemented() | ||
if mask.contains(.RegularExpressionSearch) { | ||
NSUnimplemented() | ||
} | ||
if searchRange.length == 0 { | ||
return NSMakeRange(NSNotFound, 0) | ||
} | ||
|
||
#if os(Linux) | ||
var cfflags = CFStringCompareFlags(mask.rawValue) | ||
if mask.contains(.LiteralSearch) { | ||
cfflags |= UInt(kCFCompareNonliteral) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. probably these constants would be good to expose as a uniform re-export on OS X/iOS targets so that the linux (and potentially other platforms) would all have a similar interface. |
||
} | ||
#else | ||
var cfflags = CFStringCompareFlags(rawValue: mask.rawValue) | ||
if mask.contains(.LiteralSearch) { | ||
cfflags.unionInPlace(.CompareNonliteral) | ||
} | ||
#endif | ||
var result = CFRangeMake(kCFNotFound, 0) | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. there probably should be a precondition here but overall the implementation looks good to me. |
||
if CFStringFindCharacterFromSet(_cfObject, searchSet._cfObject, CFRangeMake(searchRange.location, searchRange.length), cfflags, &result) { | ||
return NSMakeRange(result.location, result.length) | ||
} else { | ||
return NSMakeRange(NSNotFound, 0) | ||
} | ||
} | ||
|
||
public func rangeOfComposedCharacterSequenceAtIndex(index: Int) -> NSRange { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
from my understanding this is actually ignored for character set searches