Changeset 326 for cpp/frams/util
- Timestamp:
- 02/06/15 00:15:08 (10 years ago)
- Location:
- cpp/frams/util
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
cpp/frams/util/extvalue.cpp
r325 r326 610 610 } 611 611 612 bool ExtValue::parseInt(const char* s, paInt &result, bool strict )612 bool ExtValue::parseInt(const char* s, paInt &result, bool strict, bool error) 613 613 { 614 614 ExtValue tmp; 615 615 const char* after = tmp.parseNumber(s, strict ? TInt : TUnknown); 616 if (after == NULL) return false; 617 if (after[0] != 0) return false; 616 if ((after == NULL) || (after[0] != 0)) 617 { 618 if (error) 619 FMprintf("ExtValue", "parseInt", FMLV_ERROR, "Could not parse '%s'%s", s, strict?" (strict)":""); 620 return false; 621 } 618 622 result = tmp.getInt(); 619 623 return true; 620 624 } 621 625 622 bool ExtValue::parseDouble(const char* s, double &result )626 bool ExtValue::parseDouble(const char* s, double &result, bool error) 623 627 { 624 628 ExtValue tmp; 625 629 const char* after = tmp.parseNumber(s, TDouble); 626 if (after == NULL) return false; 627 if (after[0] != 0) return false; 630 if ((after == NULL) || (after[0] != 0)) 631 { 632 if (error) 633 FMprintf("ExtValue", "parseDouble", FMLV_ERROR, "Could not parse '%s'", s); 634 return false; 635 } 628 636 result = tmp.getDouble(); 629 637 return true; … … 633 641 { 634 642 paInt result; 635 if (parseInt(s, result, strict ))643 if (parseInt(s, result, strict, true)) 636 644 return result; 637 FMprintf("ExtValue", "getInt", FMLV_ERROR, "Could not parse '%s'%s", s, strict?" (strict)":"");638 645 return 0; 639 646 } … … 642 649 { 643 650 double result; 644 if (parseDouble(s, result ))651 if (parseDouble(s, result, true)) 645 652 return result; 646 FMprintf("ExtValue", "getDouble", FMLV_ERROR, "Could not parse '%s'", s);647 653 return 0; 648 654 } … … 729 735 if (in[0] == 0) return NULL; 730 736 while (isspace(*in)) in++; 731 bool minus = false; 732 if (((in[0] == '0') && (in[1] == 'x')) 733 || (((minus = (in[0] == '-')) && (in[1] == '0') && (in[2] == 'x')))) 734 { 735 in += minus ? 3 : 2; 737 bool minus = (in[0] == '-'); 738 bool plus = (in[0] == '+'); 739 if (((in[0] == '0') && ((in[1] == 'x') || (in[1]=='X'))) 740 || (((minus || plus) && (in[1] == '0') && ((in[2] == 'x') || (in[2] == 'X'))))) 741 { 742 in += (minus || plus) ? 3 : 2; 736 743 if (isspace(*in)) return NULL; 737 744 errno = 0; -
cpp/frams/util/extvalue.h
r325 r326 160 160 void setString(const SString &v) { if (type != TString) setrs(v); else sdata() = v; } 161 161 void setObject(const ExtObject &src) { if (type != TObj) setro(src); else odata() = src; } 162 static bool parseInt(const char* s, paInt &result, bool strict = false);163 static bool parseDouble(const char* s, double &result );162 static bool parseInt(const char* s, paInt &result, bool strict, bool error); 163 static bool parseDouble(const char* s, double &result, bool error); 164 164 static paInt getInt(const char* s, bool strict = false);//< @param strict=true will fail on floating point 165 165 static double getDouble(const char* s);
Note: See TracChangeset
for help on using the changeset viewer.