Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

x3::standard_wide::bool_ parser does not work with standard_wide string #706

Open
drocheam opened this issue Dec 22, 2021 · 1 comment
Open

Comments

@drocheam
Copy link

It seems the bool parser is not working with wchar_t although being included in the x3::standard_wide namespace.

Minimal Example:

#include <string>
#include <boost/spirit/home/x3.hpp>


int main()
{
	namespace x3 = boost::spirit::x3;

	std::wstring test = L"true";
	bool res = 0;

	x3::phrase_parse(test.begin(), test.end(), x3::standard_wide::bool_, x3::standard_wide::space, res);

	return 0;
}

Compiled With:
g++ -I -lboost main.cpp

On Manjaro Linux 21.2 and boost 1.76

Error (condensed):

/usr/include/boost/spirit/home/x3/string/detail/string_parse.hpp:24:38: error: no match for call to ‘(const boost::spirit::x3::case_compare<boost::spirit::char_encoding::standard_wide>) (char&, wchar_t&)’
   24 |             if (i == last || (compare(ch, *i) != 0))
      |                               ~~~~~~~^~~~~~~~

@Kojoley
Copy link
Collaborator

Kojoley commented Dec 27, 2021

Thanks for the bug report.

There was a PR targeting the issue in case_compare #655 but it has an issue.
Maybe a better way to resolve this is to convert the char string in the default bool policy via case_compare encoding somehow

struct bool_policies
{
template <typename Iterator, typename Attribute, typename CaseCompare>
static bool
parse_true(Iterator& first, Iterator const& last, Attribute& attr_, CaseCompare const& case_compare)
{
if (detail::string_parse("true", first, last, unused, case_compare))
{
traits::move_to(T(true), attr_); // result is true
return true;
}
return false;
}
template <typename Iterator, typename Attribute, typename CaseCompare>
static bool
parse_false(Iterator& first, Iterator const& last, Attribute& attr_, CaseCompare const& case_compare)
{
if (detail::string_parse("false", first, last, unused, case_compare))
{
traits::move_to(T(false), attr_); // result is false
return true;
}
return false;
}
};

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants