Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to split the css file on tokens using C++11 regex?
    primarykey
    data
    text
    <p>I'd like to know how to split the css file on tokens using <a href="http://en.cppreference.com/w/cpp/regex" rel="nofollow">C11++ regex</a> and insert into std::map as key/value? </p> <p>CSS file:</p> <pre><code>#id1 { border: 1px; color: red; } #id2 { border: 2px; color: green; }; </code></pre> <p>C++ code:</p> <pre><code>#include &lt;iostream&gt; #include &lt;fstream&gt; #include &lt;map&gt; #include &lt;regex&gt; using namespace std; int main() { ifstream file("file.css", ios::binary); if(!file.is_open()) return 1; //... how to split file on tokens? //and insert tokens probably like this (but only in a loop and dynamically): map&lt;string, string&gt; array; array.insert(make_pair("#id1", "border: 1px; color: red;")); array.insert(make_pair("#id2", "border: 1px; color: green;")); //... map&lt;string, string&gt;::iterator i = array.begin(); while(i != array.end()) { cout &lt;&lt; "key: " &lt;&lt; i-&gt;first &lt;&lt; " | value: " &lt;&lt; i-&gt;second &lt;&lt; endl; i++; } //out: /* key: #id1 | value: border: 1px; color: red; key: #id2 | value: border: 2px; color: green; */ return 0; } </code></pre> <p>What i need in JavaScript implementation:</p> <pre><code>var css = "\ #id1 {\ border: 1px;\ color: red;\ }\ #id2 {\ border: 2px;\ color: green;\ }"; //remove tabulation and split on tokens var array = css.replace(/[\t\n\r]*/g, '').replace(/\s{2}/g, ' ').split('}'), i = array.length-1, stack = []; //close right brace and insert into stack[] while(i--) { stack.unshift(array[i] + "}"); } i = stack.length; var map = {}; //fill map (key/value) while(i--) { map[stack[i].match(/(.*){.*}/)[1]] = stack[i].match(/.*{(.*)}/)[1]; } //out for(i in map) { document.write('key: ' + i + ' | value: ' + map[i] + '&lt;br /&gt;') } </code></pre> <p><a href="http://jsfiddle.net/kV6Wr/" rel="nofollow">Please see working example</a></p> <p>In fact, I just need a simple example of a splitting css file using regex</p>
    singulars
    1. This table or related slice is empty.
    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.
 

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