mirror of
https://github.com/gnustep/libs-base.git
synced 2025-05-30 08:21:25 +00:00
Implement -[NSString enumerateLinesUsingBlock:] (#407)
* Implement -[NSString enumerateLinesUsingBlock:] * Fix formatting * Use GNUstep CALL_BLOCK macro
This commit is contained in:
parent
c498475110
commit
4d3926d250
5 changed files with 133 additions and 1 deletions
|
@ -6271,6 +6271,39 @@ static NSFileManager *fm = nil;
|
|||
return [self rangeOfString: string].location != NSNotFound;
|
||||
}
|
||||
|
||||
- (void) enumerateLinesUsingBlock: (GSNSStringLineEnumerationBlock)block
|
||||
{
|
||||
NSUInteger length;
|
||||
NSUInteger lineStart, lineEnd, contentsEnd;
|
||||
NSRange currentLocationRange;
|
||||
BOOL stop;
|
||||
|
||||
length = [self length];
|
||||
lineStart = lineEnd = contentsEnd = 0;
|
||||
stop = NO;
|
||||
|
||||
// Enumerate through the string line by line
|
||||
while (lineStart < length && !stop) {
|
||||
NSString *line;
|
||||
NSRange lineRange;
|
||||
|
||||
currentLocationRange = NSMakeRange(lineStart, 0);
|
||||
[self getLineStart: &lineStart
|
||||
end: &lineEnd
|
||||
contentsEnd: &contentsEnd
|
||||
forRange: currentLocationRange];
|
||||
|
||||
lineRange = NSMakeRange(lineStart, contentsEnd - lineStart);
|
||||
line = [self substringWithRange: lineRange];
|
||||
|
||||
// Execute the block
|
||||
CALL_BLOCK(block, line, &stop);
|
||||
|
||||
// Move to the next line
|
||||
lineStart = lineEnd;
|
||||
}
|
||||
}
|
||||
|
||||
- (void) enumerateSubstringsInRange: (NSRange)range
|
||||
options: (NSStringEnumerationOptions)opts
|
||||
usingBlock: (GSNSStringEnumerationBlock)block
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue