| 38 | const string String::Empty; |
| 39 | |
| 40 | size_t String::Split(const char* value, const char* separators, const String::ForEach& forEach, int options) { |
| 41 | const char* it1(value); |
| 42 | const char* it2(NULL); |
| 43 | const char* it3(NULL); |
| 44 | size_t count(0); |
| 45 | |
| 46 | for(;;) { |
| 47 | if (options & SPLIT_TRIM) { |
| 48 | while (*it1 && isspace(*it1)) |
| 49 | ++it1; |
| 50 | } |
| 51 | it2 = it1; |
| 52 | while (*it2 && !strchr(separators,*it2)) |
| 53 | ++it2; |
| 54 | it3 = it2; |
| 55 | if ((options & SPLIT_TRIM) && it3 != it1) { |
| 56 | --it3; |
| 57 | while (it3 != it1 && isspace(*it3)) |
| 58 | --it3; |
| 59 | if (!isspace(*it3)) |
| 60 | ++it3; |
| 61 | } |
| 62 | if (it3 != it1 || !(options&SPLIT_IGNORE_EMPTY)) { |
| 63 | bool result(false); |
| 64 | SCOPED_STRINGIFY(it3, 0, result = forEach(count++,&*it1)) |
| 65 | if (!result) |
| 66 | return string::npos; |
| 67 | } |
| 68 | it1 = it2; |
| 69 | if (!*it1) |
| 70 | break; |
| 71 | ++it1; |
| 72 | }; |
| 73 | return count; |
| 74 | } |
| 75 | |
| 76 | vector<string>& String::Split(const char* value, const char* separators, vector<string>& values, int options) { |
| 77 | ForEach forEach([&values](UInt32 index,const char* value){ |