Browse Source

LibLocale: Inline a couple of ICU string conversion methods

This just allows using the ICU header within LibUnicode, without having
to link against LibLocale.

Eventually, I think it will make sense to combine LibUnicode & LibLocale
back into a single library. They were separated to remove the large CLDR
data library from LibUnicode since most users did not need it. But that
is not much of a concern now.
Timothy Flynn 1 year ago
parent
commit
187349e4db
2 changed files with 12 additions and 16 deletions
  1. 0 11
      Userland/Libraries/LibLocale/ICU.cpp
  2. 12 5
      Userland/Libraries/LibLocale/ICU.h

+ 0 - 11
Userland/Libraries/LibLocale/ICU.cpp

@@ -15,7 +15,6 @@
 #include <unicode/locdspnm.h>
 #include <unicode/locdspnm.h>
 #include <unicode/numsys.h>
 #include <unicode/numsys.h>
 #include <unicode/tznames.h>
 #include <unicode/tznames.h>
-#include <unicode/unistr.h>
 
 
 namespace Locale {
 namespace Locale {
 
 
@@ -116,16 +115,6 @@ icu::TimeZoneNames& LocaleData::time_zone_names()
     return *m_time_zone_names;
     return *m_time_zone_names;
 }
 }
 
 
-icu::UnicodeString icu_string(StringView string)
-{
-    return icu::UnicodeString::fromUTF8(icu_string_piece(string));
-}
-
-icu::StringPiece icu_string_piece(StringView string)
-{
-    return { string.characters_without_null_termination(), static_cast<i32>(string.length()) };
-}
-
 Vector<icu::UnicodeString> icu_string_list(ReadonlySpan<String> strings)
 Vector<icu::UnicodeString> icu_string_list(ReadonlySpan<String> strings)
 {
 {
     Vector<icu::UnicodeString> result;
     Vector<icu::UnicodeString> result;

+ 12 - 5
Userland/Libraries/LibLocale/ICU.h

@@ -16,6 +16,7 @@
 
 
 #include <unicode/locid.h>
 #include <unicode/locid.h>
 #include <unicode/stringpiece.h>
 #include <unicode/stringpiece.h>
+#include <unicode/unistr.h>
 #include <unicode/utypes.h>
 #include <unicode/utypes.h>
 #include <unicode/uversion.h>
 #include <unicode/uversion.h>
 
 
@@ -24,7 +25,6 @@ class DateTimePatternGenerator;
 class LocaleDisplayNames;
 class LocaleDisplayNames;
 class NumberingSystem;
 class NumberingSystem;
 class TimeZoneNames;
 class TimeZoneNames;
-class UnicodeString;
 U_NAMESPACE_END
 U_NAMESPACE_END
 
 
 namespace Locale {
 namespace Locale {
@@ -63,18 +63,25 @@ private:
     Optional<DigitalFormat> m_digital_format;
     Optional<DigitalFormat> m_digital_format;
 };
 };
 
 
-static constexpr bool icu_success(UErrorCode code)
+constexpr bool icu_success(UErrorCode code)
 {
 {
     return static_cast<bool>(U_SUCCESS(code));
     return static_cast<bool>(U_SUCCESS(code));
 }
 }
 
 
-static constexpr bool icu_failure(UErrorCode code)
+constexpr bool icu_failure(UErrorCode code)
 {
 {
     return static_cast<bool>(U_FAILURE(code));
     return static_cast<bool>(U_FAILURE(code));
 }
 }
 
 
-icu::UnicodeString icu_string(StringView string);
-icu::StringPiece icu_string_piece(StringView string);
+ALWAYS_INLINE icu::StringPiece icu_string_piece(StringView string)
+{
+    return { string.characters_without_null_termination(), static_cast<i32>(string.length()) };
+}
+
+ALWAYS_INLINE icu::UnicodeString icu_string(StringView string)
+{
+    return icu::UnicodeString::fromUTF8(icu_string_piece(string));
+}
 
 
 Vector<icu::UnicodeString> icu_string_list(ReadonlySpan<String> strings);
 Vector<icu::UnicodeString> icu_string_list(ReadonlySpan<String> strings);