| 57 | #endif // !CLI11_HAS_CODECVT |
| 58 | |
| 59 | CLI11_DIAGNOSTIC_PUSH |
| 60 | CLI11_DIAGNOSTIC_IGNORE_DEPRECATED |
| 61 | |
| 62 | CLI11_INLINE std::string narrow_impl(const wchar_t *str, std::size_t str_size) { |
| 63 | #if CLI11_HAS_CODECVT |
| 64 | #ifdef _WIN32 |
| 65 | return std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>>().to_bytes(str, str + str_size); |
| 66 | |
| 67 | #else |
| 68 | return std::wstring_convert<std::codecvt_utf8<wchar_t>>().to_bytes(str, str + str_size); |
| 69 | |
| 70 | #endif // _WIN32 |
| 71 | #else // CLI11_HAS_CODECVT |
| 72 | (void)str_size; |
| 73 | std::mbstate_t state = std::mbstate_t(); |
| 74 | const wchar_t *it = str; |
| 75 | |
| 76 | std::string old_locale = std::setlocale(LC_ALL, nullptr); |
| 77 | auto sg = scope_guard([&] { std::setlocale(LC_ALL, old_locale.c_str()); }); |
| 78 | set_unicode_locale(); |
| 79 | |
| 80 | std::size_t new_size = std::wcsrtombs(nullptr, &it, 0, &state); |
| 81 | if(new_size == static_cast<std::size_t>(-1)) { |
| 82 | throw std::runtime_error("CLI::narrow: conversion error in std::wcsrtombs at offset " + |
| 83 | std::to_string(it - str)); |
| 84 | } |
| 85 | std::string result(new_size, '\0'); |
| 86 | std::wcsrtombs(const_cast<char *>(result.data()), &str, new_size, &state); |
| 87 | |
| 88 | return result; |
| 89 | |
| 90 | #endif // CLI11_HAS_CODECVT |
| 91 | } |
| 92 | |
| 93 | CLI11_INLINE std::wstring widen_impl(const char *str, std::size_t str_size) { |
| 94 | #if CLI11_HAS_CODECVT |
nothing calls this directly
no test coverage detected