Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 79 lines (67 sloc) 2.328 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.
720b0e7 @uliwitness Added licensing information to the source files.
authored
6 // Copyright (c) 2004 M. Uli Kusterer.
7 //
8 // This software is provided 'as-is', without any express or implied
9 // warranty. In no event will the authors be held liable for any damages
10 // arising from the use of this software.
11 //
12 // Permission is granted to anyone to use this software for any purpose,
13 // including commercial applications, and to alter it and redistribute it
14 // freely, subject to the following restrictions:
15 //
16 // 1. The origin of this software must not be misrepresented; you must not
17 // claim that you wrote the original software. If you use this software
18 // in a product, an acknowledgment in the product documentation would be
19 // appreciated but is not required.
20 //
21 // 2. Altered source versions must be plainly marked as such, and must not be
22 // misrepresented as being the original software.
23 //
24 // 3. This notice may not be removed or altered from any source
25 // distribution.
dc5be1c Initial check-in.
uli authored
26 //
27
28 #import "NSString+FetchNextLine.h"
29
30
31 @implementation NSMutableString (UKFetchNextLine)
32
33 -(NSString*) nextLine
34 {
35 NSRange range = [self rangeOfString: @"\n"];
36 NSString* firstline = nil;
37
38 if( range.location != NSNotFound && range.length != 0 )
39 {
40 firstline = [self substringToIndex: (range.location)];
41 [self deleteCharactersInRange: NSMakeRange(0,range.location +range.length)];
42 }
43
44 return firstline;
45 }
46
47 -(NSString*) nextFullLine
48 {
49 NSString* string = nil;
351717c @uliwitness Make this build on 10.6.
authored
50 NSUInteger start = 0,
dc5be1c Initial check-in.
uli authored
51 end = 0,
52 nextStart = 1;
53 NSRange range, oldRange, lineRange;
54
55 oldRange = NSMakeRange(0,0);
56 if( (nextStart+1) < [self length] )
57 {
58 range = NSMakeRange(nextStart, 1);
59 [self getLineStart: &start end:&nextStart contentsEnd:&end forRange:range];
60 lineRange = NSMakeRange( start, nextStart-start );
61 string = [self substringWithRange:lineRange];
62 if( [string characterAtIndex:([string length] -1)] != '\n'
63 && [string characterAtIndex:([string length] -1)] != '\r' )
64 string = nil;
65 else
66 {
67 oldRange = lineRange;
68 lineRange.length--;
69 }
70 }
71
72 range = NSMakeRange( 0, oldRange.length +oldRange.location );
73 [self deleteCharactersInRange:range];
74
75 return string;
76 }
77
78 @end
Something went wrong with that request. Please try again.