From eab26882e1e2215b85d4bfc1cefb219719e4a428 Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Fri, 21 Jul 2023 14:01:24 +0100 Subject: [PATCH] [Minor] Use unique ptr --- src/libutil/cxx/utf8_util.cxx | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/libutil/cxx/utf8_util.cxx b/src/libutil/cxx/utf8_util.cxx index 4be7e9c58..8bb709abf 100644 --- a/src/libutil/cxx/utf8_util.cxx +++ b/src/libutil/cxx/utf8_util.cxx @@ -165,9 +165,9 @@ rspamd_utf8_transliterate(const gchar *start, gsize len, gsize *target_len) { UErrorCode uc_err = U_ZERO_ERROR; - static const icu::Transliterator *transliterator = nullptr; + static std::unique_ptr transliterator; - if (transliterator == nullptr) { + if (!transliterator) { UParseError parse_err; static const auto rules = icu::UnicodeString{":: Any-Latin;" ":: [:Nonspacing Mark:] Remove;" @@ -179,9 +179,10 @@ rspamd_utf8_transliterate(const gchar *start, gsize len, gsize *target_len) ":: NULL;" "[:Space Separator:] > ' '" }; - transliterator = icu::Transliterator::createFromRules("RspamdTranslit", rules, UTRANS_FORWARD, parse_err, uc_err); + transliterator = std::unique_ptr( + icu::Transliterator::createFromRules("RspamdTranslit", rules, UTRANS_FORWARD, parse_err, uc_err)); - if (U_FAILURE(uc_err) || transliterator == nullptr) { + if (U_FAILURE(uc_err) || !transliterator) { auto context = icu::UnicodeString(parse_err.postContext, sizeof(parse_err.preContext) / sizeof(UChar)); g_error ("fatal error: cannot init libicu transliteration engine: %s, line: %d, offset: %d", u_errorName(uc_err), parse_err.line, parse_err.offset); -- 2.39.5