lib/icu/Converter: Create() returns std::unique_ptr

This commit is contained in:
Max Kellermann
2019-11-04 15:44:06 +01:00
parent 496f43e25d
commit ed327c597a
6 changed files with 11 additions and 16 deletions

View File

@@ -46,7 +46,7 @@ IcuConverter::~IcuConverter()
#ifdef HAVE_ICU_CONVERTER
IcuConverter *
std::unique_ptr<IcuConverter>
IcuConverter::Create(const char *charset)
{
#ifdef HAVE_ICU
@@ -56,7 +56,7 @@ IcuConverter::Create(const char *charset)
throw std::runtime_error(FormatString("Failed to initialize charset '%s': %s",
charset, u_errorName(code)).c_str());
return new IcuConverter(converter);
return std::unique_ptr<IcuConverter>(new IcuConverter(converter));
#elif defined(HAVE_ICONV)
iconv_t to = iconv_open("utf-8", charset);
iconv_t from = iconv_open(charset, "utf-8");
@@ -70,7 +70,7 @@ IcuConverter::Create(const char *charset)
charset);
}
return new IcuConverter(to, from);
return std::unique_ptr<IcuConverter>(new IcuConverter(to, from));
#endif
}

View File

@@ -33,6 +33,8 @@
#ifdef HAVE_ICU_CONVERTER
#include <memory>
#ifdef HAVE_ICU
struct UConverter;
#endif
@@ -74,7 +76,7 @@ public:
/**
* Throws std::runtime_error on error.
*/
static IcuConverter *Create(const char *charset);
static std::unique_ptr<IcuConverter> Create(const char *charset);
/**
* Convert the string to UTF-8.