[:xdigit:] does not work with std::wstring in a Cygwin environment
Corinna Vinschen
corinna-cygwin@cygwin.com
Fri Feb 11 19:35:51 GMT 2022
On Feb 11 16:02, Gans, Markus wrote:
> This seems to be an internal Cygwin error:
>
> https://www.reddit.com/r/cpp_questions/comments/sp52gq/xdigit_does_not_work_with_stdwstring_in_a_cygwin/
>
> ------------------------------------------------------------------------------
> I have an unexpected behavior with Cygwin for the character class [:xdigit:]. The pattern matching for [:xdigit:] behaves like the pattern matching of [:digit:] when using a wide string. With `std::string` everything works fine.
>
> Example:
>
> #include <iostream>
> #include <string>
> #include <regex>
>
> int main ()
> {
> std::cout << "Wide character string\n";
> std::wstring w_character = L"a";
>
> if ( regex_match(w_character, std::wregex(L"[[:xdigit:]]")) )
> std::cout << "'" << char(w_character[0]) << "' is a hex digit\n";
> else
> std::cout << "'" << char(w_character[0]) << "' is not a hex digit\n";
>
> std::cout << "----------------------\n"
> << "String with 1 byte character\n";
> std::string character = "a";
>
> if ( regex_match(character, std::regex("[[:xdigit:]]")) )
> std::cout << "'" << char(w_character[0]) << "' is a hex digit\n";
> else
> std::cout << "'" << char(w_character[0]) << "' is not a hex digit\n";
>
> return 0;
> }
>
> Output in a Cygwin environment:
>
> Wide character string
> 'a' is not a hex digit
> ----------------------
> Character string
> 'a' is a hex digit
>
> Output on Linux:
>
> Wide character string
> 'a' is a hex digit
> ----------------------
> String with 1 byte character
> 'a' is a hex digit
>
> Question: Why does Cygwin not detect the letters a, b, c, d, e, and f as hexadecimal digits in a wide string?
> ------------------------------------------------------------------------------
This seems to be a bug in libstdc++. None of the above functions call
any internal library function which could affect the result. That means
regcomp(3), regexec(3), isxdigit{_l}(3) or iswxdigit{_l}(3).
Achim, any idea? Is wchar support broken in Cygwin's libstdc++, by any
chance?
Corinna
More information about the Cygwin
mailing list