160 {
161 if (!str) {
162 if (endptr) {
163 *endptr = const_cast<char*>(str);
164 }
165 return 0;
166 }
167
168 const char* p = str;
170
171
172 while (*p == ' ' || *p == '\t' || *p == '\n' || *p == '\r' || *p == '\f' || *p == '\v') {
173 p++;
174 }
175
176
177 if (*p == '+') {
178 p++;
179 } else if (*p == '-') {
180
181 p++;
182 }
183
184
185 if (base == 0) {
186 if (*p == '0') {
187 if (*(p + 1) == 'x' || *(p + 1) == 'X') {
188 base = 16;
189 p += 2;
190 } else {
191 base = 8;
192 p++;
193 }
194 } else {
195 base = 10;
196 }
197 } else if (base == 16) {
198
199 if (*p == '0' && (*(p + 1) == 'x' || *(p + 1) == 'X')) {
200 p += 2;
201 }
202 }
203
204
205 if (base < 2 || base > 36) {
206 if (endptr) {
207 *endptr = const_cast<char*>(str);
208 }
209 return 0;
210 }
211
212
213 const char* start = p;
216 p++;
217 }
218
219
220 if (endptr) {
221 if (p == start) {
222
223 *endptr = const_cast<char*>(str);
224 } else {
225 *endptr = const_cast<char*>(p);
226 }
227 }
228
230}
static int charToDigit(char c)
static bool isDigitInBase(char c, int base)
expected< T, E > result
Alias for expected (Rust-style naming)