pathparse.cpp 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #include "precomp_wasabi_bfc.h"
  2. #include <bfc/wasabi_std.h>
  3. #include "pathparse.h"
  4. PathParser::PathParser(const char *_str, const char *sep, int uniquestrs) :
  5. processed(FALSE), str(_str ? _str : ""), separators(sep), uniques(uniquestrs)
  6. {
  7. ASSERT(sep != NULL);
  8. }
  9. int PathParser::getNumStrings() {
  10. process();
  11. return strings.getNumItems();
  12. }
  13. char *PathParser::enumString(int i) {
  14. process();
  15. return strings[i];
  16. }
  17. char *PathParser::enumStringSafe(int i, char *def_val) {
  18. char *ret = enumString(i);
  19. if (ret == NULL) ret = def_val;
  20. return ret;
  21. }
  22. void PathParser::process() {
  23. if (processed) return;
  24. processed = 1;
  25. preProcess(str);
  26. char *nonconst = str.getNonConstVal();
  27. char *pt = strtok(nonconst, separators);
  28. if (pt == NULL) return;
  29. postProcess(pt);
  30. strings.addItem(pt);
  31. for (;;) {
  32. char *pt = strtok(NULL, separators);
  33. if (pt == NULL) break;
  34. postProcess(pt);
  35. if (uniques) {
  36. int exists = 0;
  37. foreach(strings)
  38. if (STRCASEEQL(strings.getfor(), pt)) {
  39. exists=1;
  40. break;
  41. }
  42. endfor;
  43. if (exists) continue;
  44. }
  45. strings.addItem(pt);
  46. }
  47. }