int qspSplitStr(QSP_CHAR *str, const QSP_CHAR *delim, QSP_CHAR ***res) {
int allocChars, count = 0, bufSize = (10 * 1024 * 1024), delimLen = qspStrLen(delim);
QSP_CHAR *newStr, **ret, *curPos = str, *found = qspStrStr(str, delim);
ret = (QSP_CHAR **)malloc(bufSize * sizeof(QSP_CHAR *));
while (found) {
allocChars = (int)(found - curPos);
newStr = (QSP_CHAR *)malloc((allocChars + 1) * sizeof(QSP_CHAR));
qspStrNCopy(newStr, curPos, allocChars);
newStr[allocChars] = 0;
if (++count > bufSize) {
bufSize += 1024;
ret = (QSP_CHAR **)realloc(ret, bufSize * sizeof(QSP_CHAR *));
}
ret[count - 1] = newStr;
curPos = found + delimLen;
found = qspStrStr(curPos, delim);
}
newStr = (QSP_CHAR *)malloc((qspStrLen(curPos) + 1) * sizeof(QSP_CHAR));
qspStrCopy(newStr, curPos);
if (++count > bufSize)
ret = (QSP_CHAR **)realloc(ret, count * sizeof(QSP_CHAR *));
ret[count - 1] = newStr;
*res = ret;
return count;
}