title: How to match unicode characters with boost::spirit?
body: <p>How can I match utf8 unicode characters using <code>boost::spirit</code>?</p>
  
  <p>For example, I want to recognize all characters in this string:</p>
  
  <pre><code>$ echo "На берегу пустынных волн" | ./a.out
  Н а б е р е гу п у с т ы н н ы х в о л н
  </code></pre>
  
  <p>When I try this simple <code>boost::spirit</code> program it will not match the unicode characters correctly:</p>
  
  <pre><code>#include &lt;boost/spirit/include/qi.hpp&gt;
  #include &lt;boost/spirit/include/support_istream_iterator.hpp&gt;
  #include &lt;boost/foreach.hpp&gt;
  namespace qi = boost::spirit::qi;
  
  int main() {
    std::cin.unsetf(std::ios::skipws);
    boost::spirit::istream_iterator begin(std::cin);
    boost::spirit::istream_iterator end;
  
    std::vector&lt;char&gt; letters;
    bool result = qi::phrase_parse(
        begin, end,  // input     
        +qi::char_,  // match every character
        qi::space,   // skip whitespace 
        letters);    // result    
  
    BOOST_FOREACH(char letter, letters) {
      std::cout &lt;&lt; letter &lt;&lt; " ";
    }
    std::cout &lt;&lt; std::endl;
  }
  </code></pre>
  
  <p>It behaves like this:</p>
  
  <pre><code>$ echo "На берегу пустынных волн" | ./a.out | less
  &lt;D0&gt; &lt;9D&gt; &lt;D0&gt; &lt;B0&gt; &lt;D0&gt; &lt;B1&gt; &lt;D0&gt; &lt;B5&gt; &lt;D1&gt; &lt;80&gt; &lt;D0&gt; &lt;B5&gt; &lt;D0&gt; &lt;B3&gt; &lt;D1&gt; &lt;83&gt; &lt;D0&gt; &lt;BF&gt; &lt;D1&gt; &lt;83&gt; &lt;D1&gt; &lt;81&gt; &lt;D1&gt; &lt;82&gt; &lt;D1&gt; &lt;8B&gt; &lt;D0&gt; &lt;BD&gt; &lt;D0&gt; &lt;BD&gt; &lt;D1&gt; &lt;8B&gt; &lt;D1&gt; &lt;85&gt; &lt;D0&gt; 
  &lt;B2&gt; &lt;D0&gt; &lt;BE&gt; &lt;D0&gt; &lt;BB&gt; &lt;D0&gt; &lt;BD&gt; 
  </code></pre>
  
  <p><strong>UPDATE:</strong></p>
  
  <p>Okay, I worked on this a bit more, and the following code is sort of working. It first converts the input into an iterator of 32-bit unicode characters (as recommended <a href="http://comments.gmane.org/gmane.comp.parsers.spirit.general/23490">here</a>):</p>
  
  <pre><code>#include &lt;boost/spirit/include/qi.hpp&gt;
  #include &lt;boost/spirit/include/support_istream_iterator.hpp&gt;
  #include &lt;boost/foreach.hpp&gt;
  #include &lt;boost/regex/pending/unicode_iterator.hpp&gt;
  namespace qi = boost::spirit::qi;
  
  int main() {
    std::string str = "На берегу пустынных волн";
    boost::u8_to_u32_iterator&lt;std::string::const_iterator&gt;
        begin(str.begin()), end(str.end());
    typedef boost::uint32_t uchar; // a unicode code point
    std::vector&lt;uchar&gt; letters;
    bool result = qi::phrase_parse(
        begin, end,             // input
        +qi::standard_wide::char_,  // match every character
        qi::space,              // skip whitespace
        letters);               // result
    BOOST_FOREACH(uchar letter, letters) {
      std::cout &lt;&lt; letter &lt;&lt; " ";
    }
    std::cout &lt;&lt; std::endl;
  }
  </code></pre>
  
  <p>The code prints the Unicode code points:</p>
  
  <pre><code>$ ./a.out 
  1053 1072 1073 1077 1088 1077 1075 1091 1087 1091 1089 1090 1099 1085 1085 1099 1093 1074 1086 1083 1085 
  </code></pre>
  
  <p>which seems to be correct, according to the official <a href="http://en.wikipedia.org/wiki/List_of_Unicode_characters">Unicode table</a>.</p>
  
  <p>Now, can anyone tell me how to print the actual characters instead, given this vector of Unicode code points? </p>