| 91 | } |
| 92 | |
| 93 | CLI11_INLINE std::wstring widen_impl(const char *str, std::size_t str_size) { |
| 94 | #if CLI11_HAS_CODECVT |
| 95 | #ifdef _WIN32 |
| 96 | return std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>>().from_bytes(str, str + str_size); |
| 97 | |
| 98 | #else |
| 99 | return std::wstring_convert<std::codecvt_utf8<wchar_t>>().from_bytes(str, str + str_size); |
| 100 | |
| 101 | #endif // _WIN32 |
| 102 | #else // CLI11_HAS_CODECVT |
| 103 | (void)str_size; |
| 104 | std::mbstate_t state = std::mbstate_t(); |
| 105 | const char *it = str; |
| 106 | |
| 107 | std::string old_locale = std::setlocale(LC_ALL, nullptr); |
| 108 | auto sg = scope_guard([&] { std::setlocale(LC_ALL, old_locale.c_str()); }); |
| 109 | set_unicode_locale(); |
| 110 | |
| 111 | std::size_t new_size = std::mbsrtowcs(nullptr, &it, 0, &state); |
| 112 | if(new_size == static_cast<std::size_t>(-1)) { |
| 113 | throw std::runtime_error("CLI::widen: conversion error in std::mbsrtowcs at offset " + |
| 114 | std::to_string(it - str)); |
| 115 | } |
| 116 | std::wstring result(new_size, L'\0'); |
| 117 | std::mbsrtowcs(const_cast<wchar_t *>(result.data()), &str, new_size, &state); |
| 118 | |
| 119 | return result; |
| 120 | |
| 121 | #endif // CLI11_HAS_CODECVT |
| 122 | } |
| 123 | |
| 124 | CLI11_DIAGNOSTIC_POP |
| 125 |
nothing calls this directly
no test coverage detected