| 392 | */ |
| 393 | |
| 394 | double /* O - Number */ |
| 395 | _cupsStrScand(const char *buf, /* I - Pointer to number */ |
| 396 | char **bufptr, /* O - New pointer or NULL on error */ |
| 397 | struct lconv *loc) /* I - Locale data */ |
| 398 | { |
| 399 | char temp[1024], /* Temporary buffer */ |
| 400 | *tempptr; /* Pointer into temporary buffer */ |
| 401 | |
| 402 | |
| 403 | /* |
| 404 | * Range check input... |
| 405 | */ |
| 406 | |
| 407 | if (!buf) |
| 408 | return (0.0); |
| 409 | |
| 410 | /* |
| 411 | * Skip leading whitespace... |
| 412 | */ |
| 413 | |
| 414 | while (_cups_isspace(*buf)) |
| 415 | buf ++; |
| 416 | |
| 417 | /* |
| 418 | * Copy leading sign, numbers, period, and then numbers... |
| 419 | */ |
| 420 | |
| 421 | tempptr = temp; |
| 422 | if (*buf == '-' || *buf == '+') |
| 423 | *tempptr++ = *buf++; |
| 424 | |
| 425 | while (isdigit(*buf & 255)) |
| 426 | if (tempptr < (temp + sizeof(temp) - 1)) |
| 427 | *tempptr++ = *buf++; |
| 428 | else |
| 429 | { |
| 430 | if (bufptr) |
| 431 | *bufptr = NULL; |
| 432 | |
| 433 | return (0.0); |
| 434 | } |
| 435 | |
| 436 | if (*buf == '.') |
| 437 | { |
| 438 | /* |
| 439 | * Read fractional portion of number... |
| 440 | */ |
| 441 | |
| 442 | buf ++; |
| 443 | |
| 444 | if (loc && loc->decimal_point) |
| 445 | { |
| 446 | strlcpy(tempptr, loc->decimal_point, sizeof(temp) - (size_t)(tempptr - temp)); |
| 447 | tempptr += strlen(tempptr); |
| 448 | } |
| 449 | else if (tempptr < (temp + sizeof(temp) - 1)) |
| 450 | *tempptr++ = '.'; |
| 451 | else |