int value( CharT ch, int radix ) const;
(since C++11)Determines the value represented by the digit ch in the numeric base radix, given the currently imbued locale. This function is called by std::regex when processing Quantifiers such as {1
} or {2,5
}, Backreferences such as \1
, and hexadecimal and Unicode character escapes.
The numeric value if ch indeed represents a digit in the currently imbued locale that is valid for the numeric base radix, or -1 on error.
[edit] Example#include <iostream> #include <locale> #include <map> #include <regex> // This custom regex traits allows japanese numerals struct jnum_traits : std::regex_traits<wchar_t> { static std::map<wchar_t, int> data; int value(wchar_t ch, int radix) const { wchar_t up = std::toupper(ch, getloc()); return data.count(up) ? data[up] : regex_traits::value(ch, radix); } }; std::map<wchar_t, int> jnum_traits::data = {{L'ã',0}, {L'ä¸',1}, {L'äº',2}, {L'ä¸',3}, {L'å',4}, {L'äº',5}, {L'å ',6}, {L'ä¸',7}, {L'å «',8}, {L'ä¹',9}, {L'A',10}, {L'ï¼¢',11}, {L'ï¼£',12}, {L'D',13}, {L'ï¼¥',14}, {L'F',15}}; int main() { std::locale::global(std::locale("ja_JP.utf8")); std::wcout.sync_with_stdio(false); std::wcout.imbue(std::locale()); std::wstring in = L"風"; if (std::regex_match(in, std::wregex(L"\\u98a8"))) std::wcout << "\\u98a8 matched " << in << '\n'; if (std::regex_match(in, std::basic_regex<wchar_t, jnum_traits>(L"\\uä¹å «ï½å «"))) std::wcout << L"\\uä¹å «ï½å « with custom traits matched " << in << '\n'; }
Output:
\u98a8 matched 風 \uä¹å «ï½å « with custom traits matched 風
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4