/****************************************************************************** * This program demonstrates how to use the character typing functions. * * Copyright © 2020 Richard Lesh. All rights reserved. *****************************************************************************/ #undef NDEBUG #include "Utils.hpp" #include #include #include #include #include #include std::locale utf8loc(std::locale(), new std::codecvt_utf8); using namespace Utils; using namespace std; int main(int argc, char **argv) { setlocale(LC_ALL, "en_US.UTF-8"); wcout.imbue(utf8loc); wcin.imbue(utf8loc); wstring s = L"Hello, world!\nΓειά σου Κόσμε!\n3.14159\t\x01\x02\t🤯🦊🦄🇺🇸🇬🇧"; for (auto c : s) { bool add_space = false; if (iswcntrl(c) || iswspace(c)) { wcout << L"Processing: 0x" << Utils::toBase(int(c), 16) << L" "; } else { wcout << L"Processing: " << c << L" "; } if (iswalpha(c)) { wcout << L"isalpha " << (wchar_t)towupper(c) << (wchar_t)towlower(c); add_space = true; } if (iswalnum(c)) { if (add_space == true) { wcout << L" "; } wcout << L"isalnum"; add_space = true; } if (iswdigit(c)) { if (add_space == true) { wcout << L" "; } wcout << L"isdigit"; add_space = true; } if (iswspace(c)) { if (add_space == true) { wcout << L" "; } wcout << L"isspace"; add_space = true; } if (iswpunct(c)) { if (add_space == true) { wcout << L" "; } wcout << L"ispunct"; add_space = true; } if (iswcntrl(c)) { if (add_space == true) { wcout << L" "; } wcout << L"isctrl"; add_space = true; } wcout << endl; } return 0; }