Initial community commit
This commit is contained in:
parent
537bcbc862
commit
fc06254474
16440 changed files with 4239995 additions and 2 deletions
54
Src/Wasabi/bfc/parse/pathparse.cpp
Normal file
54
Src/Wasabi/bfc/parse/pathparse.cpp
Normal file
|
@ -0,0 +1,54 @@
|
|||
#include "precomp_wasabi_bfc.h"
|
||||
#include <bfc/wasabi_std.h>
|
||||
#include "pathparse.h"
|
||||
|
||||
PathParser::PathParser(const char *_str, const char *sep, int uniquestrs) :
|
||||
processed(FALSE), str(_str ? _str : ""), separators(sep), uniques(uniquestrs)
|
||||
{
|
||||
ASSERT(sep != NULL);
|
||||
}
|
||||
|
||||
int PathParser::getNumStrings() {
|
||||
process();
|
||||
return strings.getNumItems();
|
||||
}
|
||||
|
||||
char *PathParser::enumString(int i) {
|
||||
process();
|
||||
return strings[i];
|
||||
}
|
||||
|
||||
char *PathParser::enumStringSafe(int i, char *def_val) {
|
||||
char *ret = enumString(i);
|
||||
if (ret == NULL) ret = def_val;
|
||||
return ret;
|
||||
}
|
||||
|
||||
void PathParser::process() {
|
||||
if (processed) return;
|
||||
processed = 1;
|
||||
preProcess(str);
|
||||
char *nonconst = str.getNonConstVal();
|
||||
|
||||
char *pt = strtok(nonconst, separators);
|
||||
if (pt == NULL) return;
|
||||
postProcess(pt);
|
||||
strings.addItem(pt);
|
||||
for (;;) {
|
||||
char *pt = strtok(NULL, separators);
|
||||
if (pt == NULL) break;
|
||||
postProcess(pt);
|
||||
if (uniques) {
|
||||
int exists = 0;
|
||||
foreach(strings)
|
||||
if (STRCASEEQL(strings.getfor(), pt)) {
|
||||
exists=1;
|
||||
break;
|
||||
}
|
||||
endfor;
|
||||
if (exists) continue;
|
||||
}
|
||||
strings.addItem(pt);
|
||||
}
|
||||
}
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue