std::isxdigit(std::locale)(3)
π std::isxdigit(std::locale)(3) π
okay so this page is from the C++ Standard Libary manual (yes, that's the spelling up top, bestie), section 3. It's all about the locale-flavored std::isxdigit check. iconic behavior, honestly. β¨
πΈ NAME πΈ
std::isxdigit(std::locale) β std::isxdigit(std::locale) π
(the name really is the thing twice, periodt).
β¨ Synopsis β¨
Defined in header <locale>
template< class CharT >
bool isxdigit( CharT ch, const locale& loc );
It checks if the given character is classified as a hexadecimal digit by the given locale's std::ctype facet. That's the whole vibe.
π Parameters π
chβ characterlocβ locale
π« Return value π«
Returns true if the character is classified as a hexadecimal digit, false otherwise. Simple slay.
π οΈ Possible implementation π οΈ
Here's one way it could look under the hood, no cap:
template<class CharT>
bool isxdigit(CharT ch, const std::locale& loc)
{
return std::use_facet<std::ctype<CharT>>(loc).is(std::ctype_base::xdigit, ch);
}
π Example π
okay bestie, run this code if you wanna see it in action:
// Run this code
#include <iostream>
#include <locale>
#include <string>
#include <unordered_set>
struct gxdigit_ctype : std::ctype<wchar_t>
{
std::unordered_set<wchar_t> greek_digits{L'Ξ±', L'Ξ²', L'Ξ³', L'Ξ΄', L'Ξ΅', L'ΞΆ'};
bool do_is(mask m, char_type c) const override
{
return (m & xdigit) && greek_digits.contains(c)
? true // 6 first Greek small letters will be classified as digits
: ctype::do_is(m, c); // leave the rest to the parent class
}
};
int main()
{
std::wstring text = L"0123456789abcdefABCDEFαβγδΡ΢ηθικλμ";
std::locale loc(std::locale(""), new gxdigit_ctype);
std::locale::global(std::locale("en_US.utf8"));
std::wcout.imbue(std::locale());
std::wcout << "Hexadecimal digits in text: ";
for (const wchar_t c : text)
if (std::isxdigit(c, loc))
std::wcout << c << L' ';
std::wcout << L'\n';
std::wcout << "Not hexadecimal digits in text: ";
for (const wchar_t c : text)
if (not std::isxdigit(c, loc))
std::wcout << c << L' ';
std::wcout << L'\n';
}
π Output π
Hexadecimal digits in text: 0 1 2 3 4 5 6 7 8 9 a b c d e f A B C D E F Ξ± Ξ² Ξ³ Ξ΄ Ξ΅ ΞΆ
Not hexadecimal digits in text: Ξ· ΞΈ ΞΉ ΞΊ Ξ» ΞΌ
π See also π
go peek at these too:
isxdigitβ checks if a character is a hexadecimal character (function)iswxdigitβ checks if a wide character is a hexadecimal character (function)
mwah π β source/version/date tea: http://cppreference.com, 2024.06.10, page tag std::isxdigit(std::locale)(3). byeee bestie π«Άβ¨
π¦ where this page comes from
- nixpkgs unstable: stdman 2024.07.05
- opensuse-leap 16.0: stdman 2024.07.05-bp160.1.9 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms