1234567891011121314151617181920212223242526272829303132333435363738394041424344 |
- #include "common/utils/SplitString.h"
- SplitString::SplitString(const char* str) : entries(0) {
- for(uint i = 0; str[i] != '\0'; i++) {
- if(str[i] == '"') {
- if(i >= 1 && str[i - 1] != ' ') {
- return;
- }
- data.append('"');
- i++;
- while(str[i] != '"') {
- if(str[i] == '\0') {
- return;
- }
- data.append(str[i++]);
- }
- if(str[i + 1] != '\0' && str[i + 1] != ' ') {
- return;
- }
- data.append('\0');
- continue;
- }
- data.append(str[i] == ' ' ? '\0' : str[i]);
- }
- uint last = 0;
- for(uint i = 0; i < data.getLength() + 1; i++) {
- if(data[i] != '\0' && data[i] != '"') {
- continue;
- }
- if(i - last > 0 || (i >= 1 && data[i - 1] == '"')) {
- starts[entries++] = last;
- }
- last = i + 1;
- }
- }
- uint SplitString::getLength() const {
- return entries;
- }
- const char* SplitString::operator[](uint index) const {
- return data + starts[index];
- }
|