Parse one specific unicode character

Stephan Menzel <[email protected]> Wed, 24 Oct 2018 07:19:08 +0200
Newsgroups gmane.comp.parsers.spirit.general
Message-ID <CAEQ568tgv3b=_TipnfDo+b1pFhK1kKTBtC+NMZ2Uc=i1UYnKag@mail.gmail.com>
Hello all,

for quite some time now I have been using a set of qi parsers to verify
user input, which can also contain unicode characters specific to a
language. Like people suggest, I used the regex iterators like this
(example) to allow regular characters and punctuation:

template <typename Iterator>
struct input_text_parser : qi::grammar<Iterator, std::string()> {

    input_text_parser() : input_text_parser ::base_type(m_start) {
        m_start %= *(qi::unicode::alnum | qi::unicode::punct |
qi::unicode::char_(" "));
    }

    qi::rule<Iterator, std::string()> m_start;
};

input_text_parser<boost::u8_to_u32_iterator<std::string::const_iterator> >
p;
boost::u8_to_u32_iterator<std::string::const_iterator> begin(str.begin());
const boost::u8_to_u32_iterator<std::string::const_iterator> end(str.end());
qi::parse(begin, end, p);
...

This worked well so far. Now I need to add an additional character to the
set of allowed chars that is apparently now included in qi::unicode::alnum.
Namely the '€' sign. My naive approach was that:

template <typename Iterator>
struct input_text_parser : qi::grammar<Iterator, std::string()> {

    input_text_parser() : input_text_parser ::base_type(m_start) {
        m_start %= *(qi::unicode::alnum | qi::unicode::punct |
qi::unicode::char_(u8"\u20AC") | qi::unicode::char_(" "));
    }

    qi::rule<Iterator, std::string()> m_start;
};

But this doesn't work. It fails to parse a test string with a € in it. What
am I doing wrong? How can I specify an utf8 character to add to the allowed
set within char_?

Any suggestions?

Cheers,
Stephan

_______________________________________________
Spirit-general mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/spirit-general