lib/icu/Converter: use libfmt
This commit is contained in:
parent
792411384d
commit
262e1957b7
|
@ -19,10 +19,10 @@
|
|||
|
||||
#include "Converter.hxx"
|
||||
#include "util/AllocatedString.hxx"
|
||||
#include "util/AllocatedArray.hxx"
|
||||
#include "util/FormatString.hxx"
|
||||
#include "config.h"
|
||||
|
||||
#include <fmt/format.h>
|
||||
|
||||
#include <iterator>
|
||||
#include <stdexcept>
|
||||
|
||||
|
@ -30,6 +30,7 @@
|
|||
|
||||
#ifdef HAVE_ICU
|
||||
#include "Util.hxx"
|
||||
#include "util/AllocatedArray.hxx"
|
||||
#include <unicode/ucnv.h>
|
||||
#elif defined(HAVE_ICONV)
|
||||
#include "system/Error.hxx"
|
||||
|
@ -53,8 +54,8 @@ IcuConverter::Create(const char *charset)
|
|||
UErrorCode code = U_ZERO_ERROR;
|
||||
UConverter *converter = ucnv_open(charset, &code);
|
||||
if (converter == nullptr)
|
||||
throw std::runtime_error(FormatString("Failed to initialize charset '%s': %s",
|
||||
charset, u_errorName(code)).c_str());
|
||||
throw std::runtime_error(fmt::format(FMT_STRING("Failed to initialize charset '{}': {}"),
|
||||
charset, u_errorName(code)));
|
||||
|
||||
return std::unique_ptr<IcuConverter>(new IcuConverter(converter));
|
||||
#elif defined(HAVE_ICONV)
|
||||
|
@ -66,8 +67,8 @@ IcuConverter::Create(const char *charset)
|
|||
iconv_close(to);
|
||||
if (from != (iconv_t)-1)
|
||||
iconv_close(from);
|
||||
throw FormatErrno(e, "Failed to initialize charset '%s'",
|
||||
charset);
|
||||
throw MakeErrno(e, fmt::format(FMT_STRING("Failed to initialize charset '{}'"),
|
||||
charset).c_str());
|
||||
}
|
||||
|
||||
return std::unique_ptr<IcuConverter>(new IcuConverter(to, from));
|
||||
|
@ -118,8 +119,8 @@ IcuConverter::ToUTF8(std::string_view s) const
|
|||
&source, source + s.size(),
|
||||
nullptr, true, &code);
|
||||
if (code != U_ZERO_ERROR)
|
||||
throw std::runtime_error(FormatString("Failed to convert to Unicode: %s",
|
||||
u_errorName(code)).c_str());
|
||||
throw std::runtime_error(fmt::format(FMT_STRING("Failed to convert to Unicode: {}"),
|
||||
u_errorName(code)));
|
||||
|
||||
const size_t target_length = target - buffer;
|
||||
return UCharToUTF8({buffer, target_length});
|
||||
|
@ -148,8 +149,8 @@ IcuConverter::FromUTF8(std::string_view s) const
|
|||
nullptr, true, &code);
|
||||
|
||||
if (code != U_ZERO_ERROR)
|
||||
throw std::runtime_error(FormatString("Failed to convert from Unicode: %s",
|
||||
u_errorName(code)).c_str());
|
||||
throw std::runtime_error(fmt::format(FMT_STRING("Failed to convert from Unicode: {}"),
|
||||
u_errorName(code)));
|
||||
|
||||
return AllocatedString({buffer, size_t(target - buffer)});
|
||||
|
||||
|
|
|
@ -31,6 +31,7 @@ icu = static_library(
|
|||
include_directories: inc,
|
||||
dependencies: [
|
||||
icu_dep,
|
||||
fmt_dep,
|
||||
],
|
||||
)
|
||||
|
||||
|
|
Loading…
Reference in New Issue