Added String method that converts to long integer.
git-svn-id: http://voip.null.ro/svn/yate@4899 acf43c95-373e-0410-b603-e72c3f656dc1
This commit is contained in:
parent
4503260a9d
commit
e88762e14f
|
@ -444,6 +444,27 @@ int String::toInteger(const TokenDict* tokens, int defvalue, int base) const
|
|||
return toInteger(defvalue,base);
|
||||
}
|
||||
|
||||
long int String::toLong(long int defvalue, int base, long int minvalue, long int maxvalue,
|
||||
bool clamp) const
|
||||
{
|
||||
if (!m_string)
|
||||
return defvalue;
|
||||
char *eptr = 0;
|
||||
|
||||
errno = 0;
|
||||
long int val = ::strtol(m_string,&eptr,base);
|
||||
// on overflow/underflow mark the entire string as unreadable
|
||||
if ((errno == ERANGE) && eptr)
|
||||
eptr = m_string;
|
||||
if (!eptr || *eptr)
|
||||
return defvalue;
|
||||
if (val >= minvalue && val <= maxvalue)
|
||||
return val;
|
||||
if (clamp)
|
||||
return (val < minvalue) ? minvalue : maxvalue;
|
||||
return defvalue;
|
||||
}
|
||||
|
||||
double String::toDouble(double defvalue) const
|
||||
{
|
||||
if (!m_string)
|
||||
|
|
13
yateclass.h
13
yateclass.h
|
@ -1734,6 +1734,19 @@ public:
|
|||
*/
|
||||
int toInteger(const TokenDict* tokens, int defvalue = 0, int base = 0) const;
|
||||
|
||||
/**
|
||||
* Convert the string to an long integer value.
|
||||
* @param defvalue Default to return if the string is not a number
|
||||
* @param base Numeration base, 0 to autodetect
|
||||
* @param minvalue Minimum value allowed
|
||||
* @param maxvalue Maximum value allowed
|
||||
* @param clamp Control the out of bound values: true to adjust to the nearest
|
||||
* bound, false to return the default value
|
||||
* @return The long integer interpretation or defvalue.
|
||||
*/
|
||||
long int toLong(long int defvalue = 0, int base = 0, long int minvalue = LONG_MIN,
|
||||
long int maxvalue = LONG_MAX, bool clamp = true) const;
|
||||
|
||||
/**
|
||||
* Convert the string to a floating point value.
|
||||
* @param defvalue Default to return if the string is not a number
|
||||
|
|
Loading…
Reference in New Issue