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 @@
vector<string> &split(const string &str_in, char delim, vector<string> &tokens)
{
#if 0
std::stringstream ss(str_in);
string token;
tokens.clear();
......@@ -32,6 +33,9 @@ vector<string> &split(const string &str_in, char delim, vector<string> &tokens)
tokens.push_back(token);
}
return tokens;
#endif
string delims(1, delim);
return split(str_in, delims, tokens);
}
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 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])
{
next_delim_pos = MIN(j,next_delim_pos);
found = true;
break;
}
}
}
}
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