unicode_to_utf8 -> to_utf8 since both sides of conversion are Unicode

This commit is contained in:
Victor Zverovich
2023-05-10 10:58:09 -07:00
parent a08196b149
commit 93a30a0746
6 changed files with 20 additions and 21 deletions

View File

@@ -110,9 +110,9 @@ class utf8_system_category final : public std::error_category {
public:
const char* name() const noexcept override { return "system"; }
std::string message(int error_code) const override {
system_message msg(error_code);
auto&& msg = system_message(error_code);
if (msg) {
unicode_to_utf8<wchar_t> utf8_message;
auto utf8_message = to_utf8<wchar_t>();
if (utf8_message.convert(msg)) {
return utf8_message.str();
}
@@ -137,12 +137,12 @@ std::system_error vwindows_error(int err_code, string_view format_str,
void detail::format_windows_error(detail::buffer<char>& out, int error_code,
const char* message) noexcept {
FMT_TRY {
system_message msg(error_code);
auto&& msg = system_message(error_code);
if (msg) {
unicode_to_utf8<wchar_t> utf8_message;
auto utf8_message = to_utf8<wchar_t>();
if (utf8_message.convert(msg)) {
fmt::format_to(buffer_appender<char>(out), FMT_STRING("{}: {}"),
message, string_view(utf8_message));
fmt::format_to(appender(out), FMT_STRING("{}: {}"), message,
string_view(utf8_message));
return;
}
}
@@ -337,9 +337,8 @@ file file::open_windows_file(wcstring_view path, int oflag) {
int fd = -1;
auto err = _wsopen_s(&fd, path.c_str(), oflag, _SH_DENYNO, default_open_mode);
if (fd == -1) {
FMT_THROW(
system_error(err, FMT_STRING("cannot open file {}"),
detail::unicode_to_utf8<wchar_t>(path.c_str()).c_str()));
FMT_THROW(system_error(err, FMT_STRING("cannot open file {}"),
detail::to_utf8<wchar_t>(path.c_str()).c_str()));
}
return file(fd);
}