Changeset 4300
- Timestamp:
- 03/09/10 20:43:13 (6 months ago)
- Location:
- trunk/showtime/src
- Files:
-
- 3 modified
-
htsmsg/htsmsg_json.c (modified) (3 diffs)
-
misc/string.c (modified) (2 diffs)
-
misc/string.h (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/showtime/src/htsmsg/htsmsg_json.c
r3591 r4300 26 26 #include "htsmsg_json.h" 27 27 #include "htsbuf.h" 28 #include "misc/string.h" 28 29 29 30 /** … … 331 332 } 332 333 333 /*334 * locale independent strtod.335 * does not support hex floats as the standard strtod336 */337 static double338 _strntod(const char *s, char decimal_point_char, char **ep)339 {340 static char locale_decimal_point_char = 0;341 char buf[64];342 const char *c;343 double d;344 345 /* ugly but very portable way to get decimal point char */346 if(locale_decimal_point_char == 0) {347 snprintf(buf, sizeof(buf), "%f", 0.0);348 locale_decimal_point_char = buf[1];349 assert(locale_decimal_point_char != 0);350 }351 352 for(c = s;353 *c != '\0' &&354 ((*c > 0 && *c < 33) || /* skip whitespace */355 (*c == decimal_point_char || strchr("+-0123456789", *c) != NULL)); c++)356 ;357 358 strncpy(buf, s, c - s);359 buf[c - s] = '\0';360 361 /* replace if specified char is not same as current locale */362 if(decimal_point_char != locale_decimal_point_char) {363 char *r = strchr(buf, decimal_point_char);364 if(r != NULL)365 *r = locale_decimal_point_char;366 }367 368 d = strtod(buf, ep);369 370 /* figure out offset in original string */371 if(ep != NULL)372 *ep = (char *)s + (*ep - buf);373 374 return d;375 }376 377 334 /** 378 335 * … … 382 339 { 383 340 char *ep; 384 double d = _strntod(s, '.', &ep);341 double d = strtod_ex(s, '.', &ep); 385 342 386 343 if(ep == s) -
trunk/showtime/src/misc/string.c
r4296 r4300 21 21 #include <stdlib.h> 22 22 #include <string.h> 23 #include <assert.h> 23 24 24 25 #include <libavutil/avstring.h> … … 489 490 } 490 491 492 /* 493 * locale independent strtod. 494 * does not support hex floats as the standard strtod 495 */ 496 double 497 strtod_ex(const char *s, char decimal_point_char, char **ep) 498 { 499 static char locale_decimal_point_char = 0; 500 char buf[64]; 501 const char *c; 502 double d; 503 504 /* ugly but very portable way to get local decimal point char */ 505 if(locale_decimal_point_char == 0) { 506 snprintf(buf, sizeof(buf), "%f", 0.0); 507 locale_decimal_point_char = buf[1]; 508 assert(locale_decimal_point_char != 0); 509 } 510 511 for(c = s; 512 *c != '\0' && 513 ((*c > 0 && *c < 33) || /* skip whitespace */ 514 (*c == decimal_point_char || strchr("+-0123456789", *c) != NULL)); c++) 515 ; 516 517 int n = MIN(sizeof(buf) - 1, c - s); 518 strncpy(buf, s, n); 519 buf[n] = '\0'; 520 521 /* replace if specified char is not same as current locale */ 522 if(decimal_point_char != locale_decimal_point_char) { 523 char *r = strchr(buf, decimal_point_char); 524 if(r != NULL) 525 *r = locale_decimal_point_char; 526 } 527 528 d = strtod(buf, ep); 529 530 /* figure out offset in original string */ 531 if(ep != NULL) 532 *ep = (char *)s + (*ep - buf); 533 534 return d; 535 } 536 -
trunk/showtime/src/misc/string.h
r4296 r4300 18 18 const char *url); 19 19 20 double strtod_ex(const char *s, char decimal_point_char, char **ep); 21 22 20 23 #endif