ICU-22520 Add convenience wrappers for calling ulocimp_getSubtags().

These wrappers that call ulocimp_getSubtags() to get only one particular
subtag and then return that as icu::CharString will be convenient for
replacing code that currently calls the uloc_get*() functions writing
into a fixed size buffer.
This commit is contained in:
Fredrik Roubert 2024-02-06 13:35:28 +01:00 committed by Fredrik Roubert
parent 835b009314
commit 930b4d9ab9
3 changed files with 76 additions and 0 deletions

View file

@ -1345,6 +1345,66 @@ _getVariant(const char* localeID,
}
}
U_EXPORT CharString U_EXPORT2
ulocimp_getLanguage(const char* localeID, UErrorCode& status) {
CharString language;
CharStringByteSink sink(&language);
ulocimp_getSubtags(
localeID,
&sink,
nullptr,
nullptr,
nullptr,
nullptr,
status);
return language;
}
U_EXPORT CharString U_EXPORT2
ulocimp_getScript(const char* localeID, UErrorCode& status) {
CharString script;
CharStringByteSink sink(&script);
ulocimp_getSubtags(
localeID,
nullptr,
&sink,
nullptr,
nullptr,
nullptr,
status);
return script;
}
U_EXPORT CharString U_EXPORT2
ulocimp_getRegion(const char* localeID, UErrorCode& status) {
CharString region;
CharStringByteSink sink(&region);
ulocimp_getSubtags(
localeID,
nullptr,
nullptr,
&sink,
nullptr,
nullptr,
status);
return region;
}
U_EXPORT CharString U_EXPORT2
ulocimp_getVariant(const char* localeID, UErrorCode& status) {
CharString variant;
CharStringByteSink sink(&variant);
ulocimp_getSubtags(
localeID,
nullptr,
nullptr,
nullptr,
&sink,
nullptr,
status);
return variant;
}
U_EXPORT void U_EXPORT2
ulocimp_getSubtags(
const char* localeID,

View file

@ -79,6 +79,18 @@ ulocimp_getKeywordValue(const char* localeID,
icu::ByteSink& sink,
UErrorCode* status);
U_EXPORT icu::CharString U_EXPORT2
ulocimp_getLanguage(const char* localeID, UErrorCode& status);
U_EXPORT icu::CharString U_EXPORT2
ulocimp_getScript(const char* localeID, UErrorCode& status);
U_EXPORT icu::CharString U_EXPORT2
ulocimp_getRegion(const char* localeID, UErrorCode& status);
U_EXPORT icu::CharString U_EXPORT2
ulocimp_getVariant(const char* localeID, UErrorCode& status);
U_EXPORT void U_EXPORT2
ulocimp_setKeywordValue(const char* keywordName,
const char* keywordValue,

View file

@ -1195,10 +1195,14 @@
#define ulocimp_getKeywordValue U_ICU_ENTRY_POINT_RENAME(ulocimp_getKeywordValue)
#define ulocimp_getKeywords U_ICU_ENTRY_POINT_RENAME(ulocimp_getKeywords)
#define ulocimp_getKnownCanonicalizedLocaleForTest U_ICU_ENTRY_POINT_RENAME(ulocimp_getKnownCanonicalizedLocaleForTest)
#define ulocimp_getLanguage U_ICU_ENTRY_POINT_RENAME(ulocimp_getLanguage)
#define ulocimp_getName U_ICU_ENTRY_POINT_RENAME(ulocimp_getName)
#define ulocimp_getParent U_ICU_ENTRY_POINT_RENAME(ulocimp_getParent)
#define ulocimp_getRegion U_ICU_ENTRY_POINT_RENAME(ulocimp_getRegion)
#define ulocimp_getRegionForSupplementalData U_ICU_ENTRY_POINT_RENAME(ulocimp_getRegionForSupplementalData)
#define ulocimp_getScript U_ICU_ENTRY_POINT_RENAME(ulocimp_getScript)
#define ulocimp_getSubtags U_ICU_ENTRY_POINT_RENAME(ulocimp_getSubtags)
#define ulocimp_getVariant U_ICU_ENTRY_POINT_RENAME(ulocimp_getVariant)
#define ulocimp_isCanonicalizedLocaleForTest U_ICU_ENTRY_POINT_RENAME(ulocimp_isCanonicalizedLocaleForTest)
#define ulocimp_minimizeSubtags U_ICU_ENTRY_POINT_RENAME(ulocimp_minimizeSubtags)
#define ulocimp_setKeywordValue U_ICU_ENTRY_POINT_RENAME(ulocimp_setKeywordValue)