mirror of
https://github.com/unicode-org/icu.git
synced 2025-04-07 22:44:49 +00:00
ICU-12187 fix dependencies, add a file, fix memory allocations
X-SVN-Rev: 38479
This commit is contained in:
parent
8eefcba4ec
commit
155fb20a8e
5 changed files with 68 additions and 58 deletions
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
*******************************************************************************
|
||||
*
|
||||
* Copyright (C) 1997-2014, International Business Machines
|
||||
* Copyright (C) 1997-2016, International Business Machines
|
||||
* Corporation and others. All Rights Reserved.
|
||||
*
|
||||
*******************************************************************************
|
||||
|
@ -1330,4 +1330,53 @@ Locale::isRightToLeft() const {
|
|||
return uloc_isRightToLeft(getBaseName());
|
||||
}
|
||||
|
||||
// The following must at least allow for rg key value (6) plus terminator (1).
|
||||
#define ULOC_RG_BUFLEN 8
|
||||
|
||||
U_CAPI int32_t U_EXPORT2
|
||||
ulocimp_getRegionForSupplementalData(const char *localeID, UBool inferRegion,
|
||||
char *region, int32_t regionCapacity, UErrorCode* status) {
|
||||
if (U_FAILURE(*status)) {
|
||||
return 0;
|
||||
}
|
||||
char rgBuf[ULOC_RG_BUFLEN];
|
||||
UErrorCode rgStatus = U_ZERO_ERROR;
|
||||
|
||||
// First check for rg keyword value
|
||||
int32_t rgLen = uloc_getKeywordValue(localeID, "rg", rgBuf, ULOC_RG_BUFLEN, &rgStatus);
|
||||
if (U_FAILURE(rgStatus) || rgLen != 6) {
|
||||
rgLen = 0;
|
||||
} else {
|
||||
// rgBuf guaranteed to be zero terminated here, with text len 6
|
||||
char *rgPtr = rgBuf;
|
||||
for (; *rgPtr!= 0; rgPtr++) {
|
||||
*rgPtr = uprv_toupper(*rgPtr);
|
||||
}
|
||||
rgLen = (uprv_strcmp(rgBuf+2, "ZZZZ") == 0)? 2: 0;
|
||||
}
|
||||
|
||||
if (rgLen == 0) {
|
||||
// No valid rg keyword value, try for unicode_region_subtag
|
||||
rgLen = uloc_getCountry(localeID, rgBuf, ULOC_RG_BUFLEN, status);
|
||||
if (U_FAILURE(*status)) {
|
||||
rgLen = 0;
|
||||
} else if (rgLen == 0 && inferRegion) {
|
||||
// no unicode_region_subtag but inferRegion TRUE, try likely subtags
|
||||
char locBuf[ULOC_FULLNAME_CAPACITY];
|
||||
rgStatus = U_ZERO_ERROR;
|
||||
(void)uloc_addLikelySubtags(localeID, locBuf, ULOC_FULLNAME_CAPACITY, &rgStatus);
|
||||
if (U_SUCCESS(rgStatus)) {
|
||||
rgLen = uloc_getCountry(locBuf, rgBuf, ULOC_RG_BUFLEN, status);
|
||||
if (U_FAILURE(*status)) {
|
||||
rgLen = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
rgBuf[rgLen] = 0;
|
||||
uprv_strncpy(region, rgBuf, regionCapacity);
|
||||
return u_terminateChars(region, regionCapacity, rgLen, status);
|
||||
}
|
||||
|
||||
U_NAMESPACE_END
|
||||
|
|
|
@ -1348,56 +1348,6 @@ ulocimp_getCountry(const char *localeID,
|
|||
return idLen;
|
||||
}
|
||||
|
||||
// the following must at least allow for rg key value (6) plus terminator (1).
|
||||
#define ULOC_RG_BUFLEN 8
|
||||
|
||||
U_CAPI int32_t U_EXPORT2
|
||||
ulocimp_getRegionForSupplementalData(const char *localeID, UBool inferRegion,
|
||||
char *region, int32_t regionCapacity, UErrorCode* status)
|
||||
{
|
||||
if (U_FAILURE(*status)) {
|
||||
return 0;
|
||||
}
|
||||
char rgBuf[ULOC_RG_BUFLEN];
|
||||
UErrorCode rgStatus = U_ZERO_ERROR;
|
||||
|
||||
// First check for rg keyword value
|
||||
int32_t rgLen = uloc_getKeywordValue(localeID, "rg", rgBuf, ULOC_RG_BUFLEN, &rgStatus);
|
||||
if (U_FAILURE(rgStatus) || rgLen != 6) {
|
||||
rgLen = 0;
|
||||
} else {
|
||||
// rgBuf guaranteed to be zero terminated here, with text len 6
|
||||
char *rgPtr = rgBuf;
|
||||
for (; *rgPtr!= 0; rgPtr++) {
|
||||
*rgPtr = uprv_toupper(*rgPtr);
|
||||
}
|
||||
rgLen = (uprv_strcmp(rgBuf+2, "ZZZZ") == 0)? 2: 0;
|
||||
}
|
||||
|
||||
if (rgLen == 0) {
|
||||
// No valid rg keyword value, try for unicode_region_subtag
|
||||
rgLen = uloc_getCountry(localeID, rgBuf, ULOC_RG_BUFLEN, status);
|
||||
if (U_FAILURE(*status)) {
|
||||
rgLen = 0;
|
||||
} else if (rgLen == 0 && inferRegion) {
|
||||
// no unicode_region_subtag but inferRegion TRUE, try likely subtags
|
||||
char locBuf[ULOC_FULLNAME_CAPACITY];
|
||||
rgStatus = U_ZERO_ERROR;
|
||||
(void)uloc_addLikelySubtags(localeID, locBuf, ULOC_FULLNAME_CAPACITY, &rgStatus);
|
||||
if (U_SUCCESS(rgStatus)) {
|
||||
rgLen = uloc_getCountry(locBuf, rgBuf, ULOC_RG_BUFLEN, status);
|
||||
if (U_FAILURE(*status)) {
|
||||
rgLen = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
rgBuf[rgLen] = 0;
|
||||
uprv_strncpy(region, rgBuf, regionCapacity);
|
||||
return u_terminateChars(region, regionCapacity, rgLen, status);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param needSeparator if true, then add leading '_' if any variants
|
||||
* are added to 'variant'
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
#include "dayperiodrules.h"
|
||||
|
||||
#include "unicode/ures.h"
|
||||
#include "cstr.h"
|
||||
#include "charstr.h"
|
||||
#include "cstring.h"
|
||||
#include "ucln_in.h"
|
||||
#include "uhash.h"
|
||||
|
@ -24,7 +24,7 @@ U_NAMESPACE_BEGIN
|
|||
|
||||
namespace {
|
||||
|
||||
struct DayPeriodRulesData {
|
||||
struct DayPeriodRulesData : public UMemory {
|
||||
DayPeriodRulesData() : localeToRuleSetNumMap(NULL), rules(NULL), maxRuleSetNum(0) {}
|
||||
|
||||
UHashtable *localeToRuleSetNumMap;
|
||||
|
@ -176,7 +176,9 @@ struct DayPeriodRulesDataSink : public ResourceTableSink {
|
|||
|
||||
// Helpers.
|
||||
static int32_t parseSetNum(const UnicodeString &setNumStr, UErrorCode &errorCode) {
|
||||
return parseSetNum(CStr(setNumStr)(), errorCode);
|
||||
CharString cs;
|
||||
cs.appendInvariantChars(setNumStr, errorCode);
|
||||
return parseSetNum(cs.data(), errorCode);
|
||||
}
|
||||
|
||||
static int32_t parseSetNum(const char *setNumStr, UErrorCode &errorCode) {
|
||||
|
@ -315,6 +317,7 @@ struct DayPeriodRulesDataSink : public ResourceTableSink {
|
|||
}; // struct DayPeriodRulesDataSink
|
||||
|
||||
struct DayPeriodRulesCountSink : public ResourceTableSink {
|
||||
virtual ~DayPeriodRulesCountSink();
|
||||
virtual ResourceTableSink *getOrCreateTableSink(const char *key, int32_t, UErrorCode &errorCode) {
|
||||
if (U_FAILURE(errorCode)) { return NULL; }
|
||||
|
||||
|
@ -335,6 +338,8 @@ DayPeriodRulesDataSink::RuleSetSink::~RuleSetSink() {}
|
|||
DayPeriodRulesDataSink::RulesSink::~RulesSink() {}
|
||||
DayPeriodRulesDataSink::~DayPeriodRulesDataSink() {}
|
||||
|
||||
DayPeriodRulesCountSink::~DayPeriodRulesCountSink() {}
|
||||
|
||||
namespace {
|
||||
|
||||
UInitOnce initOnce = U_INITONCE_INITIALIZER;
|
||||
|
|
|
@ -393,7 +393,7 @@ UHashtable *localeToAllowedHourFormatsMap = NULL;
|
|||
|
||||
// Value deleter for hashmap.
|
||||
void deleteAllowedHourFormats(void *ptr) {
|
||||
delete[] (int32_t *)ptr;
|
||||
uprv_free(ptr);
|
||||
}
|
||||
|
||||
// Close hashmap at cleanup.
|
||||
|
@ -456,7 +456,7 @@ struct AllowedHourFormatsSink : public ResourceTableSink {
|
|||
if (U_FAILURE(status)) { return; }
|
||||
|
||||
if (uprv_strcmp(key, "allowed") == 0) {
|
||||
outer.allowedFormats = new int32_t[2];
|
||||
outer.allowedFormats = static_cast<int32_t *>(uprv_malloc(2 * sizeof(int32_t)));
|
||||
outer.allowedFormatsLength = 1;
|
||||
if (outer.allowedFormats == NULL) {
|
||||
status = U_MEMORY_ALLOCATION_ERROR;
|
||||
|
@ -471,7 +471,7 @@ struct AllowedHourFormatsSink : public ResourceTableSink {
|
|||
if (U_FAILURE(status)) { return NULL; }
|
||||
|
||||
if (uprv_strcmp(key, "allowed") == 0) {
|
||||
outer.allowedFormats = new int32_t[size + 1];
|
||||
outer.allowedFormats = static_cast<int32_t *>(uprv_malloc((size + 1) * sizeof(int32_t)));
|
||||
outer.allowedFormatsLength = size;
|
||||
if (outer.allowedFormats == NULL) {
|
||||
status = U_MEMORY_ALLOCATION_ERROR;
|
||||
|
|
|
@ -769,6 +769,7 @@ library: i18n
|
|||
deps
|
||||
region localedata genderinfo charset_detector spoof_detection
|
||||
alphabetic_index collation collation_builder string_search
|
||||
dayperiodrules
|
||||
formatting formattable_cnv regex regex_cnv translit
|
||||
universal_time_scale
|
||||
uclean_i18n
|
||||
|
@ -839,6 +840,11 @@ group: string_search
|
|||
deps
|
||||
breakiterator collation
|
||||
|
||||
group: dayperiodrules
|
||||
dayperiodrules.o
|
||||
deps
|
||||
resourcebundle uclean_i18n
|
||||
|
||||
group: formatting
|
||||
# TODO: Try to subdivide this ball of wax.
|
||||
# currencyformat
|
||||
|
@ -872,7 +878,7 @@ group: formatting
|
|||
choicfmt.o msgfmt.o plurfmt.o selfmt.o umsg.o
|
||||
deps
|
||||
digitlist formattable format
|
||||
pluralrules
|
||||
dayperiodrules pluralrules
|
||||
collation collation_builder # for rbnf
|
||||
common
|
||||
floating_point # sqrt() for astro.o
|
||||
|
|
Loading…
Add table
Reference in a new issue