Go to the source code of this file.
◆ FAIL
◆ OOIsNumberLiteral()
| BOOL OOIsNumberLiteral |
( |
NSString * | string, |
|
|
BOOL | allowSpaces ) |
Definition at line 40 of file OOIsNumberLiteral.m.
41{
42 BOOL leadingSpace = allowSpaces,
43 trailingSpace = NO,
44 allowSign = YES,
45 allowE = NO,
46 hadE = NO,
47 hadExp = NO,
48 allowDec = YES,
49 hadNumber = NO;
51
53 return NO;
54
55 count = [string length];
56 for (i = 0; i !=
count; ++i) {
57 switch ([string characterAtIndex:i]) {
58
59 case '0':
60 case '1':
61 case '2':
62 case '3':
63 case '4':
64 case '5':
65 case '6':
66 case '7':
67 case '8':
68 case '9':
69 leadingSpace = NO;
70 if (trailingSpace)
71 FAIL(
"Digit after trailing whitespace");
72 if (!hadE)
73 allowE = YES;
74 else
75 hadExp = YES;
76 allowSign = NO;
77 hadNumber = YES;
78 break;
79
80
81 case ' ':
82 case '\t':
83 if (leadingSpace || trailingSpace)
84 break;
85 if (hadNumber && allowSpaces) {
86 trailingSpace = YES;
87 allowSign = allowE = allowDec = NO;
88 break;
89 }
90 FAIL(
"Space in unpermitted position");
91
92
93 case '-':
94 case '+':
95 leadingSpace = NO;
96 if (allowSign) {
97 allowSign = NO;
98 break;
99 }
100 FAIL(
"Sign (+ or -) in unpermitted position");
101
102
103 case '.':
104 leadingSpace = NO;
105 if (allowDec) {
106 allowDec = NO;
107 continue;
108 }
109 FAIL(
"Sign (+ or -) in unpermitted position");
110
111
112 case 'e':
113 case 'E':
114 leadingSpace = NO;
115 if (allowE) {
116 allowE = NO;
117 allowSign = YES;
118 allowDec = NO;
119 hadE = YES;
120 continue;
121 }
122 FAIL(
"E in unpermitted position");
123
124 default:
125 FAIL(
"Unpermitted character");
126 }
127 }
128
129 if (hadE && !hadExp)
130 FAIL(
"E with no exponent");
131 if (!hadNumber)
132 FAIL(
"No digits in string");
133
134 return YES;
135}
References count, FAIL, and nil.
Referenced by MissionVariablesGetProperty(), SystemInfoGetProperty(), SystemInfoGetSystemDataValue(), and ValueForMissionVariable().