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