mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-25 22:01:30 +00:00
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:
parent
8e7e7a12be
commit
7b10e797f3
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user