-
Notifications
You must be signed in to change notification settings - Fork 284
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
Implement +[NSRegularExpression escapedPatternForString:] and -[NSString enumerateSubstringsInRange:options:usingBlock] #370
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
567e957
Fix .gitignore
ethanc8 7862434
Implement +[NSRegularExpression escapedPatternForString:]
ethanc8 b8239f6
Implement -[NSString enumerateSubstringsInRange:options:usingBlock]
ethanc8 a15fa66
Stylistic changes in -[NSString enumerateSubstringsInRange:options:us…
ethanc8 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
#import "ObjectTesting.h" | ||
#import <Foundation/NSAutoreleasePool.h> | ||
#import <Foundation/NSString.h> | ||
|
||
#if defined(__has_extension) && __has_extension(blocks) | ||
int main (int argc, const char * argv[]) | ||
{ | ||
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; | ||
START_SET("Enumerate substrings by lines"); | ||
|
||
NSString* s1 = @"Line 1\nLine 2"; | ||
__block NSUInteger currentIteration = 0; | ||
[s1 enumerateSubstringsInRange:(NSRange){ | ||
.location = 0, | ||
.length = [s1 length] | ||
} options: NSStringEnumerationByLines | ||
usingBlock: ^(NSString *substring, NSRange substringRange, NSRange enclosingRange, BOOL *stop) { | ||
NSLog(@"Substring range: {.location=%ld, .length=%ld}", substringRange.location, substringRange.length); | ||
NSLog(@"Enclosing range: {.location=%ld, .length=%ld}", enclosingRange.location, enclosingRange.length); | ||
NSLog(@"Substring: %@", substring); | ||
// *stop = YES; | ||
if(currentIteration == 0) PASS([substring isEqual: @"Line 1"], "First line of \"Line 1\\nLine 2\" is \"Line 1\""); | ||
if(currentIteration == 1) PASS([substring isEqual: @"Line 2"], "Second line of \"Line 1\\nLine 2\" is \"Line 2\""); | ||
currentIteration++; | ||
}]; | ||
PASS(currentIteration == 2, "There are only two lines in \"Line 1\\nLine 2\""); | ||
END_SET("Enumerate substrings by lines"); | ||
|
||
START_SET("Enumerate substrings by paragraphs"); | ||
|
||
NSString* s1 = @"Paragraph 1\nParagraph 2"; | ||
__block NSUInteger currentIteration = 0; | ||
[s1 enumerateSubstringsInRange:(NSRange){ | ||
.location = 0, | ||
.length = [s1 length] | ||
} options: NSStringEnumerationByParagraphs | ||
usingBlock: ^(NSString *substring, NSRange substringRange, NSRange enclosingRange, BOOL *stop) { | ||
NSLog(@"Substring range: {.location=%ld, .length=%ld}", substringRange.location, substringRange.length); | ||
NSLog(@"Enclosing range: {.location=%ld, .length=%ld}", enclosingRange.location, enclosingRange.length); | ||
NSLog(@"Substring: %@", substring); | ||
// *stop = YES; | ||
if(currentIteration == 0) PASS([substring isEqual: @"Paragraph 1"], "First paragraph of \"Paragraph 1\\nParagraph 2\" is \"Paragraph 1\""); | ||
if(currentIteration == 1) PASS([substring isEqual: @"Paragraph 2"], "Second paragraph of \"Paragraph 1\\nParagraph 2\" is \"Paragraph 2\""); | ||
currentIteration++; | ||
}]; | ||
PASS(currentIteration == 2, "There are only two paragraphs in \"Paragraph 1\\nParagraph 2\""); | ||
END_SET("Enumerate substrings by paragraphs"); | ||
|
||
START_SET("Enumerate substrings by words"); | ||
|
||
NSString* s1 = @"Word1 word2."; | ||
__block NSUInteger currentIteration = 0; | ||
[s1 enumerateSubstringsInRange:(NSRange){ | ||
.location = 0, | ||
.length = [s1 length] | ||
} options: NSStringEnumerationByWords | ||
usingBlock: ^(NSString *substring, NSRange substringRange, NSRange enclosingRange, BOOL *stop) { | ||
NSLog(@"Substring range: {.location=%ld, .length=%ld}", substringRange.location, substringRange.length); | ||
NSLog(@"Enclosing range: {.location=%ld, .length=%ld}", enclosingRange.location, enclosingRange.length); | ||
NSLog(@"Substring: %@", substring); | ||
// *stop = YES; | ||
if(currentIteration == 0) PASS([substring isEqual: @"Word1"], "First word of \"Word1 word2.\" is \"Word1\""); | ||
if(currentIteration == 1) PASS([substring isEqual: @"word2"], "Second word of \"Word1 word2.\" is \"word2\""); | ||
currentIteration++; | ||
}]; | ||
PASS(currentIteration == 2, "There are only two words in \"Word1 word2.\""); | ||
END_SET("Enumerate substrings by words"); | ||
|
||
START_SET("Enumerate substrings by sentences"); | ||
|
||
NSString* s1 = @"Sentence 1. Sentence 2."; | ||
__block NSUInteger currentIteration = 0; | ||
[s1 enumerateSubstringsInRange:(NSRange){ | ||
.location = 0, | ||
.length = [s1 length] | ||
} options: NSStringEnumerationBySentences | ||
usingBlock: ^(NSString *substring, NSRange substringRange, NSRange enclosingRange, BOOL *stop) { | ||
NSLog(@"Substring range: {.location=%ld, .length=%ld}", substringRange.location, substringRange.length); | ||
NSLog(@"Enclosing range: {.location=%ld, .length=%ld}", enclosingRange.location, enclosingRange.length); | ||
NSLog(@"Substring: %@", substring); | ||
// *stop = YES; | ||
if(currentIteration == 0) PASS([substring isEqual: @"Sentence 1. "], "First sentence of \"Sentence 1. Sentence 2.\" is \"Sentence 1. \""); | ||
if(currentIteration == 1) PASS([substring isEqual: @"Sentence 2."], "Second sentence of \"Sentence 1. Sentence 2.\" is \"Sentence 2.\""); | ||
currentIteration++; | ||
}]; | ||
PASS(currentIteration == 2, "There are only two sentences in \"Sentence 1. Sentence 2."); | ||
END_SET("Enumerate substrings by sentences"); | ||
|
||
[pool drain]; | ||
|
||
return 0; | ||
} | ||
#else | ||
int main (int argc, const char * argv[]) | ||
{ | ||
return 0; | ||
} | ||
#endif |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Are you planing to leave these log statements in? In that case you should turn them into debug logs.