| OLD | NEW |
| 1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ | 1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
| 2 /* This Source Code Form is subject to the terms of the Mozilla Public | 2 /* This Source Code Form is subject to the terms of the Mozilla Public |
| 3 * License, v. 2.0. If a copy of the MPL was not distributed with this | 3 * License, v. 2.0. If a copy of the MPL was not distributed with this |
| 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
| 5 | 5 |
| 6 /* | 6 /* |
| 7 * Scan functions for NSPR types | 7 * Scan functions for NSPR types |
| 8 * | 8 * |
| 9 * Author: Wan-Teh Chang | 9 * Author: Wan-Teh Chang |
| 10 * | 10 * |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 187 * (may be more than necessary) to represent a 64-bit integer or | 187 * (may be more than necessary) to represent a 64-bit integer or |
| 188 * floating point number. | 188 * floating point number. |
| 189 */ | 189 */ |
| 190 #define FMAX 31 | 190 #define FMAX 31 |
| 191 #define DECIMAL_POINT '.' | 191 #define DECIMAL_POINT '.' |
| 192 | 192 |
| 193 static PRStatus | 193 static PRStatus |
| 194 GetInt(ScanfState *state, int code) | 194 GetInt(ScanfState *state, int code) |
| 195 { | 195 { |
| 196 char buf[FMAX + 1], *p; | 196 char buf[FMAX + 1], *p; |
| 197 int ch; | 197 int ch = 0; |
| 198 static const char digits[] = "0123456789abcdefABCDEF"; | 198 static const char digits[] = "0123456789abcdefABCDEF"; |
| 199 PRBool seenDigit = PR_FALSE; | 199 PRBool seenDigit = PR_FALSE; |
| 200 int base; | 200 int base; |
| 201 int dlen; | 201 int dlen; |
| 202 | 202 |
| 203 switch (code) { | 203 switch (code) { |
| 204 case 'd': case 'u': | 204 case 'd': case 'u': |
| 205 base = 10; | 205 base = 10; |
| 206 break; | 206 break; |
| 207 case 'i': | 207 case 'i': |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 297 } | 297 } |
| 298 state->converted = PR_TRUE; | 298 state->converted = PR_TRUE; |
| 299 } | 299 } |
| 300 return PR_SUCCESS; | 300 return PR_SUCCESS; |
| 301 } | 301 } |
| 302 | 302 |
| 303 static PRStatus | 303 static PRStatus |
| 304 GetFloat(ScanfState *state) | 304 GetFloat(ScanfState *state) |
| 305 { | 305 { |
| 306 char buf[FMAX + 1], *p; | 306 char buf[FMAX + 1], *p; |
| 307 int ch; | 307 int ch = 0; |
| 308 PRBool seenDigit = PR_FALSE; | 308 PRBool seenDigit = PR_FALSE; |
| 309 | 309 |
| 310 if (state->width == 0 || state->width > FMAX) { | 310 if (state->width == 0 || state->width > FMAX) { |
| 311 state->width = FMAX; | 311 state->width = FMAX; |
| 312 } | 312 } |
| 313 p = buf; | 313 p = buf; |
| 314 GET_IF_WITHIN_WIDTH(state, ch); | 314 GET_IF_WITHIN_WIDTH(state, ch); |
| 315 if (WITHIN_WIDTH(state) && (ch == '+' || ch == '-')) { | 315 if (WITHIN_WIDTH(state) && (ch == '+' || ch == '-')) { |
| 316 *p++ = ch; | 316 *p++ = ch; |
| 317 GET_IF_WITHIN_WIDTH(state, ch); | 317 GET_IF_WITHIN_WIDTH(state, ch); |
| (...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 625 ScanfState state; | 625 ScanfState state; |
| 626 | 626 |
| 627 state.get = &StringGetChar; | 627 state.get = &StringGetChar; |
| 628 state.unget = &StringUngetChar; | 628 state.unget = &StringUngetChar; |
| 629 state.stream = (void *) &buf; | 629 state.stream = (void *) &buf; |
| 630 va_start(state.ap, fmt); | 630 va_start(state.ap, fmt); |
| 631 rv = DoScanf(&state, fmt); | 631 rv = DoScanf(&state, fmt); |
| 632 va_end(state.ap); | 632 va_end(state.ap); |
| 633 return rv; | 633 return rv; |
| 634 } | 634 } |
| OLD | NEW |