Only handling decimal point in atod() and dtoa() if it differs from '.'

This commit is contained in:
Klaus Schmidinger 2012-12-07 09:00:00 +01:00
parent a94f45a1b3
commit bc0b67e630
1 changed files with 22 additions and 14 deletions

36
tools.c
View File

@ -4,7 +4,7 @@
* See the main source file 'vdr.c' for copyright information and * See the main source file 'vdr.c' for copyright information and
* how to reach the author. * how to reach the author.
* *
* $Id: tools.c 2.28 2012/12/06 09:40:02 kls Exp $ * $Id: tools.c 2.29 2012/12/07 09:00:00 kls Exp $
*/ */
#include "tools.h" #include "tools.h"
@ -303,21 +303,27 @@ cString AddDirectory(const char *DirName, const char *FileName)
return cString::sprintf("%s/%s", DirName && *DirName ? DirName : ".", FileName); return cString::sprintf("%s/%s", DirName && *DirName ? DirName : ".", FileName);
} }
#define DECIMAL_POINT_C '.'
double atod(const char *s) double atod(const char *s)
{ {
static lconv *loc = localeconv(); static lconv *loc = localeconv();
char buf[strlen(s) + 1]; if (*loc->decimal_point != DECIMAL_POINT_C) {
char *p = buf; char buf[strlen(s) + 1];
while (*s) { char *p = buf;
if (*s == '.') while (*s) {
*p = *loc->decimal_point; if (*s == DECIMAL_POINT_C)
else *p = *loc->decimal_point;
*p = *s; else
p++; *p = *s;
s++; p++;
} s++;
*p = 0; }
return atof(buf); *p = 0;
return atof(buf);
}
else
return atof(s);
} }
cString dtoa(double d, const char *Format) cString dtoa(double d, const char *Format)
@ -325,7 +331,9 @@ cString dtoa(double d, const char *Format)
static lconv *loc = localeconv(); static lconv *loc = localeconv();
char buf[16]; char buf[16];
snprintf(buf, sizeof(buf), Format, d); snprintf(buf, sizeof(buf), Format, d);
return strreplace(buf, *loc->decimal_point, '.'); if (*loc->decimal_point != DECIMAL_POINT_C)
strreplace(buf, *loc->decimal_point, DECIMAL_POINT_C);
return buf;
} }
cString itoa(int n) cString itoa(int n)