Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 60 lines (48 sloc) 1.465 kb
dc5be1c Initial check-in.
uli authored
1 //
2 // NSString+FetchNextLine.m
3 // MayaFTP
4 //
5 // Created by Uli Kusterer on Fri Aug 27 2004.
6 // Copyright (c) 2004 M. Uli Kusterer. All rights reserved.
7 //
8
9 #import "NSString+FetchNextLine.h"
10
11
12 @implementation NSMutableString (UKFetchNextLine)
13
14 -(NSString*) nextLine
15 {
16 NSRange range = [self rangeOfString: @"\n"];
17 NSString* firstline = nil;
18
19 if( range.location != NSNotFound && range.length != 0 )
20 {
21 firstline = [self substringToIndex: (range.location)];
22 [self deleteCharactersInRange: NSMakeRange(0,range.location +range.length)];
23 }
24
25 return firstline;
26 }
27
28 -(NSString*) nextFullLine
29 {
30 NSString* string = nil;
31 unsigned int start = 0,
32 end = 0,
33 nextStart = 1;
34 NSRange range, oldRange, lineRange;
35
36 oldRange = NSMakeRange(0,0);
37 if( (nextStart+1) < [self length] )
38 {
39 range = NSMakeRange(nextStart, 1);
40 [self getLineStart: &start end:&nextStart contentsEnd:&end forRange:range];
41 lineRange = NSMakeRange( start, nextStart-start );
42 string = [self substringWithRange:lineRange];
43 if( [string characterAtIndex:([string length] -1)] != '\n'
44 && [string characterAtIndex:([string length] -1)] != '\r' )
45 string = nil;
46 else
47 {
48 oldRange = lineRange;
49 lineRange.length--;
50 }
51 }
52
53 range = NSMakeRange( 0, oldRange.length +oldRange.location );
54 [self deleteCharactersInRange:range];
55
56 return string;
57 }
58
59 @end
Something went wrong with that request. Please try again.