template< class CharT >
bool isdigit( CharT ch, const locale& loc );
Checks if the given character is classified as a digit by the given locale's std::ctype facet.
[edit] Parameters ch - character loc - locale [edit] Return valueReturns true if the character is classified as a digit, false otherwise.
[edit] Possible implementation [edit] Example#include <iostream> #include <locale> #include <string> #include <unordered_set> struct jdigit_ctype : std::ctype<wchar_t> { std::unordered_set<wchar_t> jdigits{ L'ä¸', L'äº', L'ä¸', L'å', L'äº', L'å ', L'ä¸', L'å «', L'ä¹', L'å' }; bool do_is(mask m, char_type c) const override { return (m & digit) && jdigits.contains(c) ? true // Japanese digits will be classified as digits : ctype::do_is(m, c); // leave the rest to the parent class } }; int main() { std::wstring text = L"123ä¸äºä¸ï¼ï¼ï¼"; std::locale loc(std::locale(""), new jdigit_ctype); std::locale::global(std::locale("en_US.utf8")); std::wcout.imbue(std::locale()); for (const wchar_t c : text) if (std::isdigit(c, loc)) std::wcout << c << " is a digit\n"; else std::wcout << c << " is NOT a digit\n"; }
Possible output:
1 is a digit 2 is a digit 3 is a digit ä¸ is a digit äº is a digit ä¸ is a digit ï¼ is NOT a digit ï¼ is NOT a digit ï¼ is NOT a digit[edit] See also
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