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.
This commit is contained in:
Timothy Flynn 2024-06-18 11:21:29 -04:00 committed by Andreas Kling
parent 1feef17bf7
commit 187349e4db
Notes: sideshowbarker 2024-07-17 05:09:48 +09:00
2 changed files with 12 additions and 16 deletions

View file

@ -15,7 +15,6 @@
#include <unicode/locdspnm.h>
#include <unicode/numsys.h>
#include <unicode/tznames.h>
#include <unicode/unistr.h>
namespace Locale {
@ -116,16 +115,6 @@ icu::TimeZoneNames& LocaleData::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> result;

View file

@ -16,6 +16,7 @@
#include <unicode/locid.h>
#include <unicode/stringpiece.h>
#include <unicode/unistr.h>
#include <unicode/utypes.h>
#include <unicode/uversion.h>
@ -24,7 +25,6 @@ class DateTimePatternGenerator;
class LocaleDisplayNames;
class NumberingSystem;
class TimeZoneNames;
class UnicodeString;
U_NAMESPACE_END
namespace Locale {
@ -63,18 +63,25 @@ private:
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));
}
static constexpr bool icu_failure(UErrorCode code)
constexpr bool icu_failure(UErrorCode 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);