Debian Codegraph @

Framework/Pantomime/NSScanner+Extensions.m

raw
1 /*
2 ** NSScanner+Extensions.m
3 **
4 ** Copyright (c) 2005 Ludovic Marcotte
5 **
6 ** Author: Ludovic Marcotte <[email protected]>
7 **
8 ** This library is free software; you can redistribute it and/or
9 ** modify it under the terms of the GNU Lesser General Public
10 ** License as published by the Free Software Foundation; either
11 ** version 2.1 of the License, or (at your option) any later version.
12 **
13 ** This library is distributed in the hope that it will be useful,
14 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
15 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 ** Lesser General Public License for more details.
17 **
18 ** You should have received a copy of the GNU General Public License
19 ** along with this program. If not, see <http://www.gnu.org/licenses/>.
20 */
21
22 #import <Pantomime/NSScanner+Extensions.h>
23
24 #import <Foundation/NSString.h>
25
26 #include <ctype.h>
27
28 //
29 //
30 //
31 @implementation NSScanner (PantomimeScannerExtensions)
32
33 - (BOOL) scanUnsignedInt: (unsigned int *) theValue
34 {
35 NSString *s;
36 NSUInteger l1, l2, len;
37 unsigned int d, v;
38
39 l1 = l2 = [self scanLocation];
40 s = [self string];
41 len = [s length];
42
43 while (l1 < len)
44 {
45 if (isdigit([s characterAtIndex: l1]))
46 {
47 l2 = l1;
48 while (l2 < len && isdigit([s characterAtIndex: l2]))
49 {
50 l2++;
51 }
52 break;
53 }
54 l1++;
55 }
56
57 if (l2 <= l1)
58 {
59 [self setScanLocation: l1+1];
60 return NO;
61 }
62
63 [self setScanLocation: (l2+1 > len ? len : l2+1)];
64
65 v = 0;
66 d = 1;
67 l2--;
68
69 while (l2 >= l1)
70 {
71 v += (([s characterAtIndex: l2]-48)*d);
72 d *= 10;
73 l2--;
74 }
75
76 *theValue = v;
77
78 return YES;
79 }
80
81 @end