Added String split method using a regular expression to match the delimiter.
git-svn-id: http://voip.null.ro/svn/yate@6382 acf43c95-373e-0410-b603-e72c3f656dc1
This commit is contained in:
parent
e1857cca07
commit
2775f7bec8
|
@ -1543,6 +1543,25 @@ ObjList* String::split(char separator, bool emptyOK) const
|
|||
return list;
|
||||
}
|
||||
|
||||
ObjList* String::split(const Regexp& reg, bool emptyOK) const
|
||||
{
|
||||
String s = *this;
|
||||
ObjList* list = new ObjList;
|
||||
ObjList* dest = list;
|
||||
while (true) {
|
||||
if (!(s && s.matches(reg))) {
|
||||
if (s || emptyOK)
|
||||
dest = dest->append(new String(s));
|
||||
break;
|
||||
}
|
||||
int pos = s.matchOffset(0);
|
||||
if (emptyOK || pos > 0)
|
||||
dest = dest->append(new String(s.c_str(),pos));
|
||||
s = s.substr(pos + s.matchLength(0));
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
String String::msgEscape(const char* str, char extraEsc)
|
||||
{
|
||||
String s;
|
||||
|
|
|
@ -2804,6 +2804,14 @@ public:
|
|||
*/
|
||||
ObjList* split(char separator, bool emptyOK = true) const;
|
||||
|
||||
/**
|
||||
* Splits the string at Regexp delimiter
|
||||
* @param reg Regexp describing the delimiter
|
||||
* @param emptyOK True if empty strings should be inserted in list
|
||||
* @return A newly allocated list of strings, must be deleted after use
|
||||
*/
|
||||
ObjList* split(const Regexp& reg, bool emptyOK = true) const;
|
||||
|
||||
/**
|
||||
* Create an escaped string suitable for use in messages
|
||||
* @param str String to convert to escaped format
|
||||
|
|
Loading…
Reference in New Issue