/****************************************************************************** * This program demonstrates basic string functions. * * Copyright © 2020 Richard Lesh. All rights reserved. *****************************************************************************/ #undef NDEBUG #include #include #include #include std::locale utf8loc(std::locale(), new std::codecvt_utf8); using namespace std; int main(int argc, char **argv) { setlocale(LC_ALL, "en_US.UTF-8"); wcout.imbue(utf8loc); wcin.imbue(utf8loc); wstring const ALPHABET = L"abcdefghijklmnopqrstuvwxyzabc"; wstring const GREEK_ALPHABET = L"αβγδεζηθικλμνξοπρσςτυφχψωαβγ"; wstring const EMOJI = L"😃😇🥰🤪🤑😴🤒🥵🥶🤯🥳😎😥😱😡🤬💀👽🤖😺🙈🙉🙊😃😇🥰"; wcout << L"Length: " << ALPHABET.length() << endl; wcout << L"charAt(17): " << ALPHABET[17] << endl; wcout << L"codePointAt(17): " << (int)(ALPHABET[17]) << endl; wcout << L"substr(23, 26): " << ALPHABET.substr(23, 3) << endl; wcout << L"prefix(6): " << ALPHABET.substr(0, 6) << endl; wcout << L"right_tail(6): " << ALPHABET.substr(6) << endl; wcout << L"suffix(6): " << ALPHABET.substr(ALPHABET.length() - 6) << endl; wcout << L"find(\'def\'): " << ALPHABET.find(L"def") << endl; wcout << L"find(\'def\') is not found: " << (ALPHABET.find(L"def") == string::npos) << endl; wcout << L"find(\'bug\'): " << ALPHABET.find(L"bug") << endl; wcout << L"find(\'bug\') is not found: " << (ALPHABET.find(L"bug") == string::npos) << endl; wcout << L"rfind(\'abc\'): " << ALPHABET.rfind(L"abc") << endl; wcout << L"rfind(\'abc\') is not found: " << (ALPHABET.rfind(L"abc") == string::npos) << endl; wcout << L"rfind(\'bug\'): " << ALPHABET.rfind(L"bug") << endl; wcout << L"rfind(\'bug\') is not found: " << (ALPHABET.rfind(L"bug") == string::npos) << endl; wcout << L"Length: " << GREEK_ALPHABET.length() << endl; wcout << L"charAt(17): " << GREEK_ALPHABET[17] << endl; wcout << L"codePointAt(17): " << (int)(GREEK_ALPHABET[17]) << endl; wcout << L"substr(23, 26): " << GREEK_ALPHABET.substr(23, 3) << endl; wcout << L"prefix(6): " << GREEK_ALPHABET.substr(0, 6) << endl; wcout << L"right_tail(6): " << GREEK_ALPHABET.substr(6) << endl; wcout << L"suffix(6): " << GREEK_ALPHABET.substr(GREEK_ALPHABET.length() - 6) << endl; wcout << L"find(\'δεζ\'): " << GREEK_ALPHABET.find(L"δεζ") << endl; wcout << L"find(\'δεζ\') is not found: " << (GREEK_ALPHABET.find(L"δεζ") == string::npos) << endl; wcout << L"find(\'bug\'): " << GREEK_ALPHABET.find(L"bug") << endl; wcout << L"find(\'bug\') is not found: " << (GREEK_ALPHABET.find(L"bug") == string::npos) << endl; wcout << L"rfind(\'αβγ\'): " << GREEK_ALPHABET.rfind(L"αβγ") << endl; wcout << L"rfind(\'αβγ\') is not found: " << (GREEK_ALPHABET.rfind(L"αβγ") == string::npos) << endl; wcout << L"rfind(\'bug\'): " << GREEK_ALPHABET.rfind(L"bug") << endl; wcout << L"rfind(\'bug\') is not found: " << (GREEK_ALPHABET.rfind(L"bug") == string::npos) << endl; wcout << L"Length: " << EMOJI.length() << endl; wcout << L"charAt(16): " << EMOJI[16] << endl; wcout << L"codePointAt(16): " << (int)(EMOJI[16]) << endl; wcout << L"substr(20, 24): " << EMOJI.substr(20, 4) << endl; wcout << L"prefix(6): " << EMOJI.substr(0, 6) << endl; wcout << L"right_tail(6): " << EMOJI.substr(6) << endl; wcout << L"suffix(6): " << EMOJI.substr(EMOJI.length() - 6) << endl; wcout << L"find(\'😱😡🤬\'): " << EMOJI.find(L"😱😡🤬") << endl; wcout << L"find(\'😱😡🤬\') is not found: " << (EMOJI.find(L"😱😡🤬") == string::npos) << endl; wcout << L"find(\'bug\'): " << EMOJI.find(L"bug") << endl; wcout << L"find(\'bug\') is not found: " << (EMOJI.find(L"bug") == string::npos) << endl; wcout << L"rfind(\'😃😇🥰\'): " << EMOJI.rfind(L"😃😇🥰") << endl; wcout << L"rfind(\'😃😇🥰\') is not found: " << (EMOJI.rfind(L"😃😇🥰") == string::npos) << endl; wcout << L"rfind(\'bug\'): " << EMOJI.rfind(L"bug") << endl; wcout << L"rfind(\'bug\') is not found: " << (EMOJI.rfind(L"bug") == string::npos) << endl; return 0; }