Fixing bug 122309. Adding a new routine that can take a string and parse it on a delimiter to add elements to the nsCStringArray. r=dougt, sr=jag
This commit is contained in:
Родитель
8d57d8c401
Коммит
38678fcafb
|
@ -934,6 +934,27 @@ nsCStringArray::nsCStringArray(void)
|
|||
{
|
||||
}
|
||||
|
||||
// Parses a given string using the delimiter passed in and appends items
|
||||
// parsed to the array.
|
||||
void
|
||||
nsCStringArray::ParseString(const char* string, const char* delimiter)
|
||||
{
|
||||
if (string && *string && delimiter && *delimiter) {
|
||||
char *newStr;
|
||||
char *rest = nsCRT::strdup(string);
|
||||
char *token = nsCRT::strtok(rest, delimiter, &newStr);
|
||||
|
||||
while (token) {
|
||||
if (*token) {
|
||||
/* calling AppendElement(void*) to avoid extra nsCString copy */
|
||||
AppendElement(new nsCString(token));
|
||||
}
|
||||
token = nsCRT::strtok(newStr, delimiter, &newStr);
|
||||
}
|
||||
PR_FREEIF(rest);
|
||||
}
|
||||
}
|
||||
|
||||
nsCStringArray::nsCStringArray(PRInt32 aCount)
|
||||
: nsVoidArray(aCount)
|
||||
{
|
||||
|
|
|
@ -270,6 +270,13 @@ public:
|
|||
|
||||
nsCStringArray& operator=(const nsCStringArray& other);
|
||||
|
||||
// Parses a given string using the delimiter passed in. If the array
|
||||
// already has some elements, items parsed from string will be appended
|
||||
// to array. For example, array.ParseString("a,b,c", ","); will add strings
|
||||
// "a", "b" and "c" to the array. Parsing process has the same tokenizing
|
||||
// behavior as strtok().
|
||||
void ParseString(const char* string, const char* delimiter);
|
||||
|
||||
#ifdef DEBUG
|
||||
void SizeOf(nsISizeOfHandler* aHandler, PRUint32* aResult) const;
|
||||
#endif
|
||||
|
|
Загрузка…
Ссылка в новой задаче