@member_group_name{numconv, Conversion to numbers}
The string provides functions for conversion to signed and unsigned integer and
- floating point numbers. All functions take a pointer to the variable to
- put the numeric value in and return @true if the @b entire string could be
- converted to a number.
- */
+ floating point numbers.
+
+ All functions take a pointer to the variable to put the numeric value
+ in and return @true if the @b entire string could be converted to a
+ number. Notice if there is a valid number in the beginning of the
+ string, it is returned in the output parameter even if the function
+ returns @false because there is more text following it.
+ */
//@{
/**
Returns @true on success (the number is stored in the location pointed to by
@a val) or @false if the string does not represent such number (the value of
- @a val is not modified in this case).
+ @a val may still be modified in this case).
Note that unlike ToCDouble() this function uses a localized version of
@c wxStrtod() and thus needs as decimal point (and thousands separator) the
bool ToDouble(double* val) const;
/**
+ Variant of ToDouble() always working in "C" locale.
+
Works like ToDouble() but unlike it this function expects the floating point
number to be formatted always with the rules dictated by the "C" locale
(in particular, the decimal point must be a dot), independently from the
Returns @true on success in which case the number is stored in the location
pointed to by @a val or @false if the string does not represent a
- valid number in the given base (the value of @a val is not modified
- in this case).
+ valid number in the given base (the value of @a val may still be
+ modified in this case).
The value of @a base must be comprised between 2 and 36, inclusive, or
be a special value 0 which means that the usual rules of @c C numbers are
bool ToLong(long* val, int base = 10) const;
/**
+ Variant of ToLong() always working in "C" locale.
+
Works like ToLong() but unlike it this function expects the integer
number to be formatted always with the rules dictated by the "C" locale,
independently from the current application-wide locale (see wxLocale).
Returns @true on success in which case the number is stored in the
location pointed to by @a val or @false if the string does not
- represent a valid number in the given base (the value of @a val is not
- modified in this case).
+ represent a valid number in the given base (the value of @a val may
+ still be modified in this case).
Please notice that this function behaves in the same way as the standard
@c strtoul() and so it simply converts negative numbers to unsigned
bool ToULong(unsigned long* val, int base = 10) const;
/**
+ Variant of ToULong() always working in "C" locale.
+
Works like ToULong() but unlike it this function expects the integer
number to be formatted always with the rules dictated by the "C" locale,
independently from the current application-wide locale (see wxLocale).
bool ToCULong(unsigned long* val, int base = 10) const;
/**
- This is exactly the same as ToULong() but works with 64
- bit integer numbers.
+ This is exactly the same as ToULong() but works with 64 bit integer
+ numbers.
+
Please see ToLongLong() for additional remarks.
*/
bool ToULongLong(wxULongLong_t* val, int base = 10) const;
const wxStringCharType *start = wx_str(); \
wxStringCharType *end;
+// notice that we return false without modifying the output parameter at all if
+// nothing could be parsed but we do modify it and return false then if we did
+// parse something successfully but not the entire string
#define WX_STRING_TO_X_TYPE_END \
- /* return true only if scan was stopped by the terminating NUL and */ \
- /* if the string was not empty to start with and no under/overflow */ \
- /* occurred: */ \
- if ( *end || end == start DO_IF_NOT_WINCE(|| errno == ERANGE) ) \
+ if ( end == start DO_IF_NOT_WINCE(|| errno == ERANGE) ) \
return false; \
*pVal = val; \
- return true;
+ return !*end;
bool wxString::ToLong(long *pVal, int base) const
{