Added methods to extract a fragment of a String up to a separator.
git-svn-id: http://voip.null.ro/svn/yate@4229 acf43c95-373e-0410-b603-e72c3f656dc1
This commit is contained in:
parent
0a848c7fb1
commit
dcadd1f961
|
@ -870,6 +870,52 @@ bool String::endsWith(const char* what, bool wordBreak, bool caseInsensitive) co
|
|||
return (::strncmp(m_string+m_length-l,what,l) == 0);
|
||||
}
|
||||
|
||||
String& String::extractTo(const char* sep, String& str)
|
||||
{
|
||||
int pos = find(sep);
|
||||
if (pos >= 0) {
|
||||
str = substr(0,pos);
|
||||
assign(m_string+pos+::strlen(sep));
|
||||
}
|
||||
else {
|
||||
str = *this;
|
||||
clear();
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
String& String::extractTo(const char* sep, bool& store)
|
||||
{
|
||||
String str;
|
||||
extractTo(sep,str);
|
||||
store = str.toBoolean(store);
|
||||
return *this;
|
||||
}
|
||||
|
||||
String& String::extractTo(const char* sep, int& store, int base)
|
||||
{
|
||||
String str;
|
||||
extractTo(sep,str);
|
||||
store = str.toInteger(store,base);
|
||||
return *this;
|
||||
}
|
||||
|
||||
String& String::extractTo(const char* sep, int& store, const TokenDict* tokens, int base)
|
||||
{
|
||||
String str;
|
||||
extractTo(sep,str);
|
||||
store = str.toInteger(tokens,store,base);
|
||||
return *this;
|
||||
}
|
||||
|
||||
String& String::extractTo(const char* sep, double& store)
|
||||
{
|
||||
String str;
|
||||
extractTo(sep,str);
|
||||
store = str.toDouble(store);
|
||||
return *this;
|
||||
}
|
||||
|
||||
bool String::matches(const Regexp& rexp)
|
||||
{
|
||||
if (m_matches)
|
||||
|
|
43
yateclass.h
43
yateclass.h
|
@ -1884,6 +1884,49 @@ public:
|
|||
*/
|
||||
bool startSkip(const char* what, bool wordBreak = true, bool caseInsensitive = false);
|
||||
|
||||
/**
|
||||
* Extract a substring up to a separator
|
||||
* @param sep Separator string to match after extracted fragment
|
||||
* @param store Reference to String variable to store extracted fragment
|
||||
* @return Reference to this string
|
||||
*/
|
||||
String& extractTo(const char* sep, String& store);
|
||||
|
||||
/**
|
||||
* Extract a boolean substring up to a separator
|
||||
* @param sep Separator string to match after extracted fragment
|
||||
* @param store Reference to boolean variable to store extracted fragment
|
||||
* @return Reference to this string
|
||||
*/
|
||||
String& extractTo(const char* sep, bool& store);
|
||||
|
||||
/**
|
||||
* Extract an integer value substring up to a separator
|
||||
* @param sep Separator string to match after extracted fragment
|
||||
* @param store Reference to integer variable to store extracted fragment
|
||||
* @param base Numeration base, 0 to autodetect
|
||||
* @return Reference to this string
|
||||
*/
|
||||
String& extractTo(const char* sep, int& store, int base = 0);
|
||||
|
||||
/**
|
||||
* Extract an integer or token value substring up to a separator
|
||||
* @param sep Separator string to match after extracted fragment
|
||||
* @param store Reference to integer variable to store extracted fragment
|
||||
* @param tokens Pointer to an array of tokens to lookup first
|
||||
* @param base Numeration base, 0 to autodetect
|
||||
* @return Reference to this string
|
||||
*/
|
||||
String& extractTo(const char* sep, int& store, const TokenDict* tokens, int base = 0);
|
||||
|
||||
/**
|
||||
* Extract a double value substring up to a separator
|
||||
* @param sep Separator string to match after extracted fragment
|
||||
* @param store Reference to double variable to store extracted fragment
|
||||
* @return Reference to this string
|
||||
*/
|
||||
String& extractTo(const char* sep, double& store);
|
||||
|
||||
/**
|
||||
* Checks if matches another string
|
||||
* @param value String to check for match
|
||||
|
|
Loading…
Reference in New Issue