char* nsCRT::strtok(char* string, const char* delims, char* *newStr) { NS_ASSERTION(string, "Unlike regular strtok, the first argument cannot be null."); char delimTable[DELIM_TABLE_SIZE]; PRUint32 i; char* result; char* str = string; for (i = 0; i < DELIM_TABLE_SIZE; i++) delimTable[i] = '\0'; for (i = 0; delims[i]; i++) { SET_DELIM(delimTable, static_cast<PRUint8>(delims[i])); } NS_ASSERTION(delims[i] == '\0', "too many delimiters"); // skip to beginning while (*str && IS_DELIM(delimTable, static_cast<PRUint8>(*str))) { str++; } result = str; // fix up the end of the token while (*str) { if (IS_DELIM(delimTable, static_cast<PRUint8>(*str))) { *str++ = '\0'; break; } str++; } *newStr = str; return str == result ? NULL : result; }
char* nsCRT::strtok(char* aString, const char* aDelims, char** aNewStr) { NS_ASSERTION(aString, "Unlike regular strtok, the first argument cannot be null."); char delimTable[DELIM_TABLE_SIZE]; uint32_t i; char* result; char* str = aString; for (i = 0; i < DELIM_TABLE_SIZE; ++i) { delimTable[i] = '\0'; } for (i = 0; aDelims[i]; i++) { SET_DELIM(delimTable, static_cast<uint8_t>(aDelims[i])); } NS_ASSERTION(aDelims[i] == '\0', "too many delimiters"); // skip to beginning while (*str && IS_DELIM(delimTable, static_cast<uint8_t>(*str))) { str++; } result = str; // fix up the end of the token while (*str) { if (IS_DELIM(delimTable, static_cast<uint8_t>(*str))) { *str++ = '\0'; break; } str++; } *aNewStr = str; return str == result ? nullptr : result; }