~ubuntu-branches/debian/experimental/mednafen/experimental

« back to all changes in this revision

Viewing changes to src/snes_perf/src/nall/string/split.hpp

  • Committer: Package Import Robot
  • Author(s): Stephen Kitt
  • Date: 2014-11-08 11:36:07 UTC
  • mfrom: (1.2.18) (10.1.16 sid)
  • Revision ID: package-import@ubuntu.com-20141108113607-3lbwsamqqhrso4hp
Tags: 0.9.36.5-1
* New upstream release, uploaded to expermiental for the Jessie freeze.
* Standards-Version 3.9.6, no change required.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#ifndef NALL_STRING_SPLIT_HPP
2
 
#define NALL_STRING_SPLIT_HPP
3
 
 
4
 
namespace nall {
5
 
 
6
 
void lstring::split(const char *key, const char *src, unsigned limit) {
7
 
  reset();
8
 
 
9
 
  int ssl = strlen(src), ksl = strlen(key);
10
 
  int lp = 0, split_count = 0;
11
 
 
12
 
  for(int i = 0; i <= ssl - ksl;) {
13
 
    if(!memcmp(src + i, key, ksl)) {
14
 
      strlcpy(operator[](split_count++), src + lp, i - lp + 1);
15
 
      i += ksl;
16
 
      lp = i;
17
 
      if(!--limit) break;
18
 
    } else i++;
19
 
  }
20
 
 
21
 
  operator[](split_count++) = src + lp;
22
 
}
23
 
 
24
 
void lstring::qsplit(const char *key, const char *src, unsigned limit) {
25
 
  reset();
26
 
 
27
 
  int ssl = strlen(src), ksl = strlen(key);
28
 
  int lp = 0, split_count = 0;
29
 
 
30
 
  for(int i = 0; i <= ssl - ksl;) {
31
 
    uint8_t x = src[i];
32
 
 
33
 
    if(x == '\"' || x == '\'') {
34
 
      int z = i++;                        //skip opening quote
35
 
      while(i < ssl && src[i] != x) i++;
36
 
      if(i >= ssl) i = z;                 //failed match, rewind i
37
 
      else {
38
 
        i++;                              //skip closing quote
39
 
        continue;                         //restart in case next char is also a quote
40
 
      }
41
 
    }
42
 
 
43
 
    if(!memcmp(src + i, key, ksl)) {
44
 
      strlcpy(operator[](split_count++), src + lp, i - lp + 1);
45
 
      i += ksl;
46
 
      lp = i;
47
 
      if(!--limit) break;
48
 
    } else i++;
49
 
  }
50
 
 
51
 
  operator[](split_count++) = src + lp;
52
 
}
53
 
 
54
 
};
55
 
 
56
 
#endif