aboutsummaryrefslogtreecommitdiff
path: root/Src/Wasabi/bfc/parse/pathparse.cpp
blob: a6653d5d7e60955e1fa6be4d8834267915f5b829 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
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);
  }
}