diff options
| author | Adam Ierymenko <adam.ierymenko@gmail.com> | 2016-11-18 15:49:28 -0800 |
|---|---|---|
| committer | Adam Ierymenko <adam.ierymenko@gmail.com> | 2016-11-18 15:49:28 -0800 |
| commit | ccdd4ffda70a35219fae1cdce1306f3d4ebd8dc9 (patch) | |
| tree | dabf33f54a180293cd44961a9b9b557fe8fae4de /osdep/OSUtils.cpp | |
| parent | 673c0c811ea443c217b3a4ca17eeaed3ab596501 (diff) | |
| download | infinitytier-ccdd4ffda70a35219fae1cdce1306f3d4ebd8dc9.tar.gz infinitytier-ccdd4ffda70a35219fae1cdce1306f3d4ebd8dc9.zip | |
Move split() to OSUtils since it is not used in core.
Diffstat (limited to 'osdep/OSUtils.cpp')
| -rw-r--r-- | osdep/OSUtils.cpp | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/osdep/OSUtils.cpp b/osdep/OSUtils.cpp index 4a81625b..65704fa3 100644 --- a/osdep/OSUtils.cpp +++ b/osdep/OSUtils.cpp @@ -315,6 +315,50 @@ bool OSUtils::writeFile(const char *path,const void *buf,unsigned int len) return false; } +std::vector<std::string> OSUtils::split(const char *s,const char *const sep,const char *esc,const char *quot) +{ + std::vector<std::string> fields; + std::string buf; + + if (!esc) + esc = ""; + if (!quot) + quot = ""; + + bool escapeState = false; + char quoteState = 0; + while (*s) { + if (escapeState) { + escapeState = false; + buf.push_back(*s); + } else if (quoteState) { + if (*s == quoteState) { + quoteState = 0; + fields.push_back(buf); + buf.clear(); + } else buf.push_back(*s); + } else { + const char *quotTmp; + if (strchr(esc,*s)) + escapeState = true; + else if ((buf.size() <= 0)&&((quotTmp = strchr(quot,*s)))) + quoteState = *quotTmp; + else if (strchr(sep,*s)) { + if (buf.size() > 0) { + fields.push_back(buf); + buf.clear(); + } // else skip runs of seperators + } else buf.push_back(*s); + } + ++s; + } + + if (buf.size()) + fields.push_back(buf); + + return fields; +} + std::string OSUtils::platformDefaultHomePath() { #ifdef __UNIX_LIKE__ |
