summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/IcyMetaDataParser.cxx2
-rw-r--r--src/decoder/plugins/SidplayDecoderPlugin.cxx5
-rw-r--r--src/fs/Charset.cxx5
-rw-r--r--src/lib/icu/Converter.cxx6
-rw-r--r--src/lib/icu/Converter.hxx4
-rw-r--r--test/TestIcu.cxx5
6 files changed, 11 insertions, 16 deletions
diff --git a/src/IcyMetaDataParser.cxx b/src/IcyMetaDataParser.cxx
index 2c8f1c9db..a9630bdc8 100644
--- a/src/IcyMetaDataParser.cxx
+++ b/src/IcyMetaDataParser.cxx
@@ -32,7 +32,7 @@
void
IcyMetaDataParser::SetCharset(const char *charset)
{
- icu_converter.reset(IcuConverter::Create(charset));
+ icu_converter = IcuConverter::Create(charset);
}
#endif
diff --git a/src/decoder/plugins/SidplayDecoderPlugin.cxx b/src/decoder/plugins/SidplayDecoderPlugin.cxx
index ca527ee6a..625962f86 100644
--- a/src/decoder/plugins/SidplayDecoderPlugin.cxx
+++ b/src/decoder/plugins/SidplayDecoderPlugin.cxx
@@ -456,10 +456,7 @@ Windows1252ToUTF8(const char *s) noexcept
{
#ifdef HAVE_ICU_CONVERTER
try {
- std::unique_ptr<IcuConverter>
- converter(IcuConverter::Create("windows-1252"));
-
- return converter->ToUTF8(s);
+ return IcuConverter::Create("windows-1252")->ToUTF8(s);
} catch (...) { }
#endif
diff --git a/src/fs/Charset.cxx b/src/fs/Charset.cxx
index 941021fa7..880a0101c 100644
--- a/src/fs/Charset.cxx
+++ b/src/fs/Charset.cxx
@@ -38,7 +38,7 @@
static std::string fs_charset;
-static IcuConverter *fs_converter;
+static std::unique_ptr<IcuConverter> fs_converter;
void
SetFSCharset(const char *charset)
@@ -59,8 +59,7 @@ void
DeinitFSCharset() noexcept
{
#ifdef HAVE_ICU_CONVERTER
- delete fs_converter;
- fs_converter = nullptr;
+ fs_converter.reset();
#endif
}
diff --git a/src/lib/icu/Converter.cxx b/src/lib/icu/Converter.cxx
index 7c46c726c..60b7da2d7 100644
--- a/src/lib/icu/Converter.cxx
+++ b/src/lib/icu/Converter.cxx
@@ -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
}
diff --git a/src/lib/icu/Converter.hxx b/src/lib/icu/Converter.hxx
index 29cdab7aa..41d45cbe6 100644
--- a/src/lib/icu/Converter.hxx
+++ b/src/lib/icu/Converter.hxx
@@ -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.
diff --git a/test/TestIcu.cxx b/test/TestIcu.cxx
index d5345556d..adda08ac5 100644
--- a/test/TestIcu.cxx
+++ b/test/TestIcu.cxx
@@ -30,8 +30,7 @@ TEST(IcuConverter, InvalidCharset)
TEST(IcuConverter, Latin1)
{
- IcuConverter *const converter =
- IcuConverter::Create("iso-8859-1");
+ const auto converter = IcuConverter::Create("iso-8859-1");
ASSERT_NE(converter, nullptr);
for (const auto i : invalid_utf8) {
@@ -45,8 +44,6 @@ TEST(IcuConverter, Latin1)
auto t = converter->ToUTF8(i.other);
EXPECT_STREQ(t.c_str(), i.utf8);
}
-
- delete converter;
}
#endif