ScanDouble/Int now scans prefix, postfix checked in StrDbl/IntValue

git-svn-id: svn://ultimatepp.org/upp/trunk@7564 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
cxl 2014-08-05 17:20:20 +00:00
parent a53e24f364
commit e045e729cd

View file

@ -121,6 +121,8 @@ double ScanDoubleT(const T *p, const T **endptr, bool accept_comma)
while(*p && (byte)*p <= ' ')
p++;
bool neg = false;
if(endptr)
*endptr = p;
if(*p == '+' || *p == '-')
neg = (*p++ == '-');
if((byte)(*p - '0') >= 10 && !((*p == '.' || accept_comma && *p == ',') && (byte)(p[1] - '0') < 10)) {
@ -160,11 +162,6 @@ double ScanDoubleT(const T *p, const T **endptr, bool accept_comma)
return Null;
exp += vexp;
}
while(*p) {
if((byte)*p > ' ')
return Null;
p++;
}
if(endptr) *endptr = p;
if(exp) {
double e = ipow10(tabs(exp));
@ -188,7 +185,14 @@ double ScanDouble(const wchar *p, const wchar **endptr, bool accept_comma)
Value StrIntValue(const char *s)
{
if(s && *s) {
const char *p;
int64 q = ScanInt64(s);
if(!IsNull(q))
while(*p) {
if((byte)*p > ' ')
return ErrorValue(t_("Invalid number !"));
p++;
}
return IsNull(q) ? ErrorValue(t_("Invalid number !")) : Value(q);
}
return (int)Null;
@ -197,7 +201,14 @@ Value StrIntValue(const char *s)
Value StrDblValue(const char *s)
{
if(s && *s) {
double q = ScanDouble(s);
const char *p;
double q = ScanDouble(s, &p);
if(!IsNull(q))
while(*p) {
if((byte)*p > ' ')
return ErrorValue(t_("Invalid number !"));
p++;
}
return IsNull(q) ? ErrorValue(t_("Invalid number !")) : Value(q);
}
return (double)Null;