diff --git a/format.cc b/format.cc index ddfa4858..df6efa66 100644 --- a/format.cc +++ b/format.cc @@ -612,13 +612,13 @@ FMT_FUNC void fmt::internal::report_unknown_type(char code, const char *type) { FMT_FUNC fmt::internal::UTF8ToUTF16::UTF8ToUTF16(fmt::StringRef s) { int length = MultiByteToWideChar( - CP_UTF8, MB_ERR_INVALID_CHARS, s.c_str(), -1, 0, 0); + CP_UTF8, MB_ERR_INVALID_CHARS, s.data(), s.size(), 0, 0); static const char ERROR_MSG[] = "cannot convert string from UTF-8 to UTF-16"; if (length == 0) FMT_THROW(WindowsError(GetLastError(), ERROR_MSG)); buffer_.resize(length); length = MultiByteToWideChar( - CP_UTF8, MB_ERR_INVALID_CHARS, s.c_str(), -1, &buffer_[0], length); + CP_UTF8, MB_ERR_INVALID_CHARS, s.data(), s.size(), &buffer_[0], length); if (length == 0) FMT_THROW(WindowsError(GetLastError(), ERROR_MSG)); } @@ -631,19 +631,19 @@ FMT_FUNC fmt::internal::UTF16ToUTF8::UTF16ToUTF8(fmt::WStringRef s) { } FMT_FUNC int fmt::internal::UTF16ToUTF8::convert(fmt::WStringRef s) { - int length = WideCharToMultiByte(CP_UTF8, 0, s.c_str(), -1, 0, 0, 0, 0); + int length = WideCharToMultiByte(CP_UTF8, 0, s.data(), s.size(), 0, 0, 0, 0); if (length == 0) return GetLastError(); buffer_.resize(length); length = WideCharToMultiByte( - CP_UTF8, 0, s.c_str(), -1, &buffer_[0], length, 0, 0); + CP_UTF8, 0, s.data(), s.size(), &buffer_[0], length, 0, 0); if (length == 0) return GetLastError(); return 0; } FMT_FUNC void fmt::WindowsError::init( - int err_code, StringRef format_str, ArgList args) { + int err_code, CStringRef format_str, ArgList args) { error_code_ = err_code; MemoryWriter w; internal::format_windows_error(w, err_code, format(format_str, args)); diff --git a/format.h b/format.h index 2156b3d3..dfe95a77 100644 --- a/format.h +++ b/format.h @@ -2557,7 +2557,7 @@ void report_system_error(int error_code, StringRef message) FMT_NOEXCEPT; /** A Windows error. */ class WindowsError : public SystemError { private: - void init(int error_code, StringRef format_str, ArgList args); + void init(int error_code, CStringRef format_str, ArgList args); public: /** @@ -2588,10 +2588,10 @@ class WindowsError : public SystemError { } \endrst */ - WindowsError(int error_code, StringRef message) { + WindowsError(int error_code, CStringRef message) { init(error_code, message, ArgList()); } - FMT_VARIADIC_CTOR(WindowsError, init, int, StringRef) + FMT_VARIADIC_CTOR(WindowsError, init, int, CStringRef) }; // Reports a Windows error without throwing an exception.