Skip to content
Newer
Older
100644 82 lines (62 sloc) 1.68 KB
05eedb5 @itod initial add
authored Jan 25, 2010
1 // Copyright 2010 Todd Ditchendorf
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 #import <ParseKit/PKReader.h>
16
17 @implementation PKReader
18
19 - (id)init {
20 return [self initWithString:nil];
21 }
22
23
24 - (id)initWithString:(NSString *)s {
25 if (self = [super init]) {
26 self.string = s;
27 }
28 return self;
29 }
30
31
32 - (void)dealloc {
33 self.string = nil;
eb778c5 @itod merging changes from Google Code SVN repo
authored Aug 10, 2012
34 //if (buff) free(buff);
05eedb5 @itod initial add
authored Jan 26, 2010
35 [super dealloc];
36 }
37
38
39 - (NSString *)string {
40 return [[string retain] autorelease];
41 }
42
43
44 - (void)setString:(NSString *)s {
45 if (string != s) {
46 [string autorelease];
47 string = [s copy];
48 length = [string length];
eb778c5 @itod merging changes from Google Code SVN repo
authored Aug 10, 2012
49
50 // if (buff) free(buff);
51 // buff = malloc(sizeof(unichar)*length + 1);
52 // [s getCharacters:buff range:NSMakeRange(0, length)];
05eedb5 @itod initial add
authored Jan 26, 2010
53 }
54 // reset cursor
55 offset = 0;
56 }
57
58
59 - (PKUniChar)read {
60 if (0 == length || offset > length - 1) {
61 return PKEOF;
62 }
63 return [string characterAtIndex:offset++];
eb778c5 @itod merging changes from Google Code SVN repo
authored Aug 10, 2012
64 //return buff[offset++];
05eedb5 @itod initial add
authored Jan 26, 2010
65 }
66
67
68 - (void)unread {
69 offset = (0 == offset) ? 0 : offset - 1;
70 }
71
72
73 - (void)unread:(NSUInteger)count {
74 NSUInteger i = 0;
75 for ( ; i < count; i++) {
76 [self unread];
77 }
78 }
79
80 @synthesize offset;
81 @end
Something went wrong with that request. Please try again.