Bug 466622. Replace nsCStringArray with nsTArray<nsCString> for more consistent code and fewer heap allocations. r+sr=roc,r=bsmedberg
This commit is contained in:
@@ -1146,3 +1146,35 @@ CaseInsensitiveCompare(const char *a, const char *b,
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
PRBool
|
||||
ParseString(const nsACString& aSource, char aDelimiter,
|
||||
nsTArray<nsCString>& aArray)
|
||||
{
|
||||
PRInt32 start = 0;
|
||||
PRInt32 end = aSource.Length();
|
||||
|
||||
PRUint32 oldLength = aArray.Length();
|
||||
|
||||
for (;;) {
|
||||
PRInt32 delimiter = aSource.FindChar(aDelimiter, start);
|
||||
if (delimiter < 0) {
|
||||
delimiter = end;
|
||||
}
|
||||
|
||||
if (delimiter != start) {
|
||||
if (!aArray.AppendElement(Substring(aSource, start, delimiter - start))) {
|
||||
aArray.RemoveElementsAt(oldLength, aArray.Length() - oldLength);
|
||||
return PR_FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
if (delimiter == end)
|
||||
break;
|
||||
start = ++delimiter;
|
||||
if (start == end)
|
||||
break;
|
||||
}
|
||||
|
||||
return PR_TRUE;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user