Oolite 1.91.0.7646-241128-10e222e
Loading...
Searching...
No Matches
OOIsNumberLiteral.h File Reference
import "OOCocoa.h"
+ Include dependency graph for OOIsNumberLiteral.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

BOOL OOIsNumberLiteral (NSString *string, BOOL allowSpaces)
 

Function Documentation

◆ OOIsNumberLiteral()

BOOL OOIsNumberLiteral ( NSString * string,
BOOL allowSpaces )

Definition at line 35 of file OOIsNumberLiteral.m.

36{
37 BOOL leadingSpace = allowSpaces,
38 trailingSpace = NO,
39 allowSign = YES,
40 allowE = NO,
41 hadE = NO,
42 hadExp = NO,
43 allowDec = YES,
44 hadNumber = NO;
45 NSUInteger i, count;
46
47 if (string == nil) return NO;
48
49 count = [string length];
50 for (i = 0; i != count; ++i)
51 {
52 switch ([string characterAtIndex:i])
53 {
54 // <digit>
55 case '0':
56 case '1':
57 case '2':
58 case '3':
59 case '4':
60 case '5':
61 case '6':
62 case '7':
63 case '8':
64 case '9':
65 leadingSpace = NO;
66 if (trailingSpace) FAIL("Digit after trailing whitespace");
67 if (!hadE) allowE = YES;
68 else hadExp = YES;
69 allowSign = NO;
70 hadNumber = YES;
71 break;
72
73 // <whitespaceChar>
74 case ' ':
75 case '\t':
76 if (leadingSpace || trailingSpace) break;
77 if (hadNumber && allowSpaces)
78 {
79 trailingSpace = YES;
80 allowSign = allowE = allowDec = NO;
81 break;
82 }
83 FAIL("Space in unpermitted position");
84
85 // <sign>
86 case '-':
87 case '+':
88 leadingSpace = NO;
89 if (allowSign)
90 {
91 allowSign = NO;
92 break;
93 }
94 FAIL("Sign (+ or -) in unpermitted position");
95
96 // <decimalPoint>
97 case '.':
98 leadingSpace = NO;
99 if (allowDec)
100 {
101 allowDec = NO;
102 continue;
103 }
104 FAIL("Sign (+ or -) in unpermitted position");
105
106 // <e>
107 case 'e':
108 case 'E':
109 leadingSpace = NO;
110 if (allowE)
111 {
112 allowE = NO;
113 allowSign = YES;
114 allowDec = NO;
115 hadE = YES;
116 continue;
117 }
118 FAIL("E in unpermitted position");
119
120 default:
121 FAIL ("Unpermitted character");
122 }
123 }
124
125 if (hadE && !hadExp) FAIL("E with no exponent");
126 if (!hadNumber) FAIL("No digits in string");
127
128 return YES;
129}
#define FAIL(s)
unsigned count
return nil

References count, FAIL, and nil.

Referenced by MissionVariablesGetProperty(), and SystemInfoGetProperty().

+ Here is the caller graph for this function: