-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNSString+SplitIntoLines.m
35 lines (27 loc) · 1.08 KB
/
NSString+SplitIntoLines.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
//
// NSString (SWSplitIntoLinesAddition).m
// This file is part of the "SWApplicationSupport" project, and is distributed under the MIT License.
//
// Created by Samuel Williams on 20/10/05.
// Copyright 2005 Samuel Williams. All rights reserved.
//
#import "NSString+SplitIntoLines.h"
@implementation NSString (SWSplitIntoLinesAddition)
- (NSMutableArray*) componentsSeparatedByCharactersInSet:(NSCharacterSet *)charSet {
NSMutableArray *components = [NSMutableArray arrayWithCapacity:[self length]/2];
NSScanner *scanner = [NSScanner scannerWithString:self];
[scanner setCharactersToBeSkipped:nil];
while (![scanner isAtEnd]) {
NSString *aString;
if ([scanner scanUpToCharactersFromSet:charSet intoString:&aString]) {
[components addObject:aString];
}
[scanner scanCharactersFromSet:charSet intoString:nil];
}
return components;
}
- (NSArray*) componentsSeparatedByLineBreaks {
NSCharacterSet *cs = [NSCharacterSet characterSetWithCharactersInString:@"\r\n"];
return [self componentsSeparatedByCharactersInSet:cs];
}
@end