Added String constructor from double. Added assignment and append operators from double.

git-svn-id: http://yate.null.ro/svn/yate/trunk@5962 acf43c95-373e-0410-b603-e72c3f656dc1
This commit is contained in:
marian 2015-03-19 13:11:45 +00:00
parent c7a98797a2
commit b19d0a8e8e
2 changed files with 50 additions and 0 deletions

View File

@ -405,6 +405,18 @@ String::String(bool value)
changed();
}
String::String(double value)
: m_string(0), m_length(0), m_hash(YSTRING_INIT_HASH), m_matches(0)
{
XDebug(DebugAll,"String::String(%g) [%p]",value,this);
char buf[80];
::sprintf(buf,"%g",value);
m_string = ::strdup(buf);
if (!m_string)
Debug("String",DebugFail,"strdup() returned NULL!");
changed();
}
String::String(const String* value)
: m_string(0), m_length(0), m_hash(YSTRING_INIT_HASH), m_matches(0)
{
@ -782,6 +794,13 @@ String& String::operator=(uint64_t value)
return operator=(buf);
}
String& String::operator=(double value)
{
char buf[80];
::sprintf(buf,"%g",value);
return operator=(buf);
}
String& String::operator+=(char value)
{
char buf[2] = {value,0};
@ -816,6 +835,13 @@ String& String::operator+=(uint64_t value)
return operator+=(buf);
}
String& String::operator+=(double value)
{
char buf[80];
::sprintf(buf,"%g",value);
return operator+=(buf);
}
String& String::operator>>(const char* skip)
{
if (m_string && skip && *skip) {

View File

@ -1878,6 +1878,12 @@ public:
*/
explicit String(bool value);
/**
* Creates a new initialized string from a double value.
* @param value Value to convert to string
*/
explicit String(double value);
/**
* Copy constructor.
* @param value Initial value of the string
@ -2262,6 +2268,12 @@ public:
inline String& operator=(bool value)
{ return operator=(boolText(value)); }
/**
* Assignment operator for double.
* @param value Value to assign to the string
*/
String& operator=(double value);
/**
* Appending operator for strings.
* @param value Value to assign to the string
@ -2307,6 +2319,12 @@ public:
inline String& operator+=(bool value)
{ return operator+=(boolText(value)); }
/**
* Appending operator for double.
* @param value Value to append to the string
*/
String& operator+=(double value);
/**
* Equality operator.
*/
@ -2381,6 +2399,12 @@ public:
inline String& operator<<(bool value)
{ return operator+=(value); }
/**
* Stream style appending operator for double
*/
inline String& operator<<(double value)
{ return operator+=(value); }
/**
* Stream style substring skipping operator.
* It eats all characters up to and including the skip string