Commit cb21d37e authored by Kamil Iskra's avatar Kamil Iskra

Add support for \ and '

Make single-delim-character split() use the string-delims version since
I'm too lazy to fix it separately.
parent 7852bc27
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
vector<string> &split(const string &str_in, char delim, vector<string> &tokens) vector<string> &split(const string &str_in, char delim, vector<string> &tokens)
{ {
#if 0
std::stringstream ss(str_in); std::stringstream ss(str_in);
string token; string token;
tokens.clear(); tokens.clear();
...@@ -32,6 +33,9 @@ vector<string> &split(const string &str_in, char delim, vector<string> &tokens) ...@@ -32,6 +33,9 @@ vector<string> &split(const string &str_in, char delim, vector<string> &tokens)
tokens.push_back(token); tokens.push_back(token);
} }
return tokens; return tokens;
#endif
string delims(1, delim);
return split(str_in, delims, tokens);
} }
vector<string> &split(const string &str_in, const string &delims, vector<string> &split(const string &str_in, const string &delims,
...@@ -49,12 +53,37 @@ vector<string> &split(const string &str_in, const string &delims, ...@@ -49,12 +53,37 @@ vector<string> &split(const string &str_in, const string &delims,
for(int i=0; i<(int)delims.size(); i++) for(int i=0; i<(int)delims.size(); i++)
{ {
for(int j=start; j<length; j++) for(int j=start; j<length; j++)
{
if(str_in[j] == '\\')
{
j++;
continue;
}
if(str_in[j] == '\'')
{
for (j++; j<length; j++)
{
if(str_in[j] == '\\')
{
j++;
continue;
}
if (str_in[j] == '\'')
break;
}
if (j == length) /* Parse error */
{
tokens.clear();
return tokens;
}
}
if(str_in[j] == delims[i]) if(str_in[j] == delims[i])
{ {
next_delim_pos = MIN(j,next_delim_pos); next_delim_pos = MIN(j,next_delim_pos);
found = true; found = true;
break; break;
} }
}
} }
if(found) if(found)
{ {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment