Note that there are some explanatory texts on larger screens.

plurals
  1. POUsing escaped_list_separator with boost split
    primarykey
    data
    text
    <p>I am playing around with the boost strings library and have just come across the awesome simplicity of the split method. </p> <pre><code> string delimiters = ","; string str = "string, with, comma, delimited, tokens, \"and delimiters, inside a quote\""; // If we didn't care about delimiter characters within a quoted section we could us vector&lt;string&gt; tokens; boost::split(tokens, str, boost::is_any_of(delimiters)); // gives the wrong result: tokens = {"string", " with", " comma", " delimited", " tokens", "\"and delimiters", " inside a quote\""} </code></pre> <p>Which would be nice and concise... however it doesn't seem to work with quotes and instead I have to do something like the following</p> <pre><code>string delimiters = ","; string str = "string, with, comma, delimited, tokens, \"and delimiters, inside a quote\""; vector&lt;string&gt; tokens; escaped_list_separator&lt;char&gt; separator("\\",delimiters, "\""); typedef tokenizer&lt;escaped_list_separator&lt;char&gt; &gt; Tokeniser; Tokeniser t(str, separator); for (Tokeniser::iterator it = t.begin(); it != t.end(); ++it) tokens.push_back(*it); // gives the correct result: tokens = {"string", " with", " comma", " delimited", " tokens", "\"and delimiters, inside a quote\""} </code></pre> <p>My question is can split or another standard algorithm be used when you have quoted delimiters? Thanks to purpledog but I already have a non-deprecated way of achieving the desired outcome, I just think that it's quite cumbersome and unless I could replace it with a simpler more elegant solution I wouldn't use it in general without first wrapping it in yet another method.</p> <p>EDIT: Updated code to show results and clarify question. </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload