aboutsummaryrefslogtreecommitdiff
path: root/Src/Wasabi/bfc/parse/pathparse.cpp
diff options
context:
space:
mode:
authorJef <jef@targetspot.com>2024-09-24 08:54:57 -0400
committerJef <jef@targetspot.com>2024-09-24 08:54:57 -0400
commit20d28e80a5c861a9d5f449ea911ab75b4f37ad0d (patch)
tree12f17f78986871dd2cfb0a56e5e93b545c1ae0d0 /Src/Wasabi/bfc/parse/pathparse.cpp
parent537bcbc86291b32fc04ae4133ce4d7cac8ebe9a7 (diff)
downloadwinamp-20d28e80a5c861a9d5f449ea911ab75b4f37ad0d.tar.gz
Initial community commit
Diffstat (limited to 'Src/Wasabi/bfc/parse/pathparse.cpp')
-rw-r--r--Src/Wasabi/bfc/parse/pathparse.cpp54
1 files changed, 54 insertions, 0 deletions
diff --git a/Src/Wasabi/bfc/parse/pathparse.cpp b/Src/Wasabi/bfc/parse/pathparse.cpp
new file mode 100644
index 00000000..a6653d5d
--- /dev/null
+++ b/Src/Wasabi/bfc/parse/pathparse.cpp
@@ -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);
+ }
+}
+