From 9fefa1aab83a0642b285dc7e580f4d6d07db1957 Mon Sep 17 00:00:00 2001 From: Frank Tang Date: Thu, 20 Jul 2023 23:00:12 -0700 Subject: [PATCH] Use Macro --- icu4c/source/common/uloc.cpp | 42 ++++++++++++------------------------ 1 file changed, 14 insertions(+), 28 deletions(-) diff --git a/icu4c/source/common/uloc.cpp b/icu4c/source/common/uloc.cpp index 9c1b22b238aa..1b2e2d282ae0 100644 --- a/icu4c/source/common/uloc.cpp +++ b/icu4c/source/common/uloc.cpp @@ -2227,53 +2227,46 @@ uloc_toLegacyType(const char* keyword, const char* value) } // ========== ULocale API ========================== -ULocale* external(icu::Locale* internal) { - return (ULocale*)(internal); -} -const icu::Locale* internal(const ULocale* external) { - return (const icu::Locale*)(external); -} - -icu::Locale* internal(ULocale* external) { - return (icu::Locale*)(external); -} +#define EXTERNAL(i) ((ULocale*)(i)) +#define CONST_INTERNAL(e) ((const icu::Locale*)(e)) +#define INTERNAL(e) ((icu::Locale*)(e)) ULocale* ulocale_openLocaleID(const char* localeID, int32_t length) { if (length < 0 || localeID[length] == '\0') { - return external(new icu::Locale(localeID)); + return EXTERNAL(new icu::Locale(localeID)); } else { if (length < ULOC_FULLNAME_CAPACITY-1) { char buf[ULOC_FULLNAME_CAPACITY]; uprv_memcpy(buf, localeID, length); buf[length] = '\0'; - return external(new icu::Locale(buf)); + return EXTERNAL(new icu::Locale(buf)); } // return a bogus one Locale bogus; bogus.setToBogus(); - return external(bogus.clone()); + return EXTERNAL(bogus.clone()); } } ULocale* ulocale_openForLanguageTag(const char* tag, int32_t length, UErrorCode* err) { if (U_FAILURE(*err)) return nullptr; - return external(icu::Locale::forLanguageTag( + return EXTERNAL(icu::Locale::forLanguageTag( length < 0 ? StringPiece(tag) : StringPiece(tag, length), *err).clone()); } void ulocale_close(ULocale* locale) { if (locale == nullptr) return; - delete internal(locale); + delete INTERNAL(locale); } #define IMPL_ULOCALE_STRING_GETTER(N1, N2) \ const char* ulocale_get ## N1(const ULocale* locale) { \ if (locale == nullptr) return nullptr; \ - return internal(locale)->get ## N2(); \ + return CONST_INTERNAL(locale)->get ## N2(); \ } #define IMPL_ULOCALE_STRING_IDENTICAL_GETTER(N) IMPL_ULOCALE_STRING_GETTER(N, N) @@ -2281,7 +2274,7 @@ const char* ulocale_get ## N1(const ULocale* locale) { \ #define IMPL_ULOCALE_BOOL_IDENTICAL_GETTER(N) \ bool ulocale_is ## N(const ULocale* locale) { \ if (locale == nullptr) return false; \ - return internal(locale)->is ## N(); \ + return CONST_INTERNAL(locale)->is ## N(); \ } #define IMPL_ULOCALE_GET_KEYWORD_VALUE(N) \ @@ -2294,7 +2287,7 @@ int32_t ulocale_get ##N ( \ return 0; \ } \ CheckedArrayByteSink sink(valueBuffer, bufferCapacity); \ - internal(locale)->get ## N( \ + CONST_INTERNAL(locale)->get ## N( \ keywordLength < 0 ? StringPiece(keyword) : StringPiece(keyword, keywordLength), \ sink, *err); \ if (U_FAILURE(*err)) return 0; \ @@ -2313,7 +2306,7 @@ UEnumeration* ulocale_get ## N(const ULocale* locale, UErrorCode *err) { \ return nullptr; \ } \ return uenum_openFromStringEnumeration( \ - internal(locale)->create ## N(*err), err); \ + CONST_INTERNAL(locale)->create ## N(*err), err); \ } #define IMPL_ULOCALE_PRODUCER(N) \ @@ -2323,9 +2316,9 @@ ULocale* ulocale_ ## N(const ULocale* locale, UErrorCode *err) { \ *err = U_ILLEGAL_ARGUMENT_ERROR; \ return nullptr; \ } \ - icu::Locale* that = internal(locale)->clone(); \ + icu::Locale* that = CONST_INTERNAL(locale)->clone(); \ that->N(*err); \ - return external(that); \ + return EXTERNAL(that); \ } IMPL_ULOCALE_STRING_IDENTICAL_GETTER(Language) @@ -2346,11 +2339,4 @@ IMPL_ULOCALE_PRODUCER(canonicalize) IMPL_ULOCALE_PRODUCER(addLikelySubtags) IMPL_ULOCALE_PRODUCER(minimizeSubtags) -#undef IMPL_ULOCALE_STRING_IDENTICAL_GETTER -#undef IMPL_ULOCALE_STRING_GETTER -#undef IMPL_ULOCALE_BOOL_IDENTICAL_GETTER -#undef IMPL_ULOCALE_GET_KEYWORD_VALUE -#undef IMPL_ULOCALE_GET_KEYWORDS -#undef IMPL_ULOCALE_PRODUCER - /*eof*/