clang -cc1 -cc1 -triple x86_64-pc-linux-gnu -analyze -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name ucol_sit.cpp -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=cplusplus -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -analyzer-config-compatibility-mode=true -mrelocation-model pic -pic-level 2 -fhalf-no-semantic-interposition -mframe-pointer=all -relaxed-aliasing -ffp-contract=off -fno-rounding-math -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -debugger-tuning=gdb -fdebug-compilation-dir=/root/firefox-clang/obj-x86_64-pc-linux-gnu/config/external/icu/i18n -fcoverage-compilation-dir=/root/firefox-clang/obj-x86_64-pc-linux-gnu/config/external/icu/i18n -resource-dir /usr/lib/llvm-21/lib/clang/21 -include /root/firefox-clang/config/gcc_hidden.h -include /root/firefox-clang/obj-x86_64-pc-linux-gnu/mozilla-config.h -I /root/firefox-clang/obj-x86_64-pc-linux-gnu/dist/system_wrappers -U _FORTIFY_SOURCE -D _FORTIFY_SOURCE=2 -D _GLIBCXX_ASSERTIONS -D DEBUG=1 -D U_I18N_IMPLEMENTATION -D _LIBCPP_DISABLE_DEPRECATION_WARNINGS -D U_USING_ICU_NAMESPACE=0 -D U_NO_DEFAULT_INCLUDE_UTF_HEADERS=1 -D U_HIDE_OBSOLETE_UTF_OLD_H=1 -D UCONFIG_NO_LEGACY_CONVERSION -D UCONFIG_NO_TRANSLITERATION -D UCONFIG_NO_REGULAR_EXPRESSIONS -D UCONFIG_NO_BREAK_ITERATION -D UCONFIG_NO_IDNA -D UCONFIG_NO_MF2 -D U_CHARSET_IS_UTF8 -D UNISTR_FROM_CHAR_EXPLICIT=explicit -D UNISTR_FROM_STRING_EXPLICIT=explicit -D U_ENABLE_DYLOAD=0 -D U_DEBUG=1 -I /root/firefox-clang/config/external/icu/i18n -I /root/firefox-clang/obj-x86_64-pc-linux-gnu/config/external/icu/i18n -I /root/firefox-clang/intl/icu/source/common -I /root/firefox-clang/mfbt/double-conversion -I /root/firefox-clang/obj-x86_64-pc-linux-gnu/dist/include -I /root/firefox-clang/obj-x86_64-pc-linux-gnu/dist/include/nspr -I /root/firefox-clang/obj-x86_64-pc-linux-gnu/dist/include/nss -D MOZILLA_CLIENT -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/14/../../../../include/c++/14 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/14/../../../../include/x86_64-linux-gnu/c++/14 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/14/../../../../include/c++/14/backward -internal-isystem /usr/lib/llvm-21/lib/clang/21/include -internal-isystem /usr/local/include -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/14/../../../../x86_64-linux-gnu/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -O2 -Wno-error=pessimizing-move -Wno-error=large-by-value-copy=128 -Wno-error=implicit-int-float-conversion -Wno-error=thread-safety-analysis -Wno-error=tautological-type-limit-compare -Wno-invalid-offsetof -Wno-range-loop-analysis -Wno-deprecated-anon-enum-enum-conversion -Wno-deprecated-enum-enum-conversion -Wno-deprecated-this-capture -Wno-inline-new-delete -Wno-error=deprecated-declarations -Wno-error=array-bounds -Wno-error=free-nonheap-object -Wno-error=atomic-alignment -Wno-error=deprecated-builtins -Wno-psabi -Wno-error=builtin-macro-redefined -Wno-vla-cxx-extension -Wno-unknown-warning-option -Wno-comma -Wno-implicit-const-int-float-conversion -Wno-macro-redefined -Wno-microsoft-include -Wno-tautological-unsigned-enum-zero-compare -Wno-unreachable-code-loop-increment -Wno-unreachable-code-return -fdeprecated-macro -ferror-limit 19 -fstrict-flex-arrays=1 -stack-protector 2 -fstack-clash-protection -ftrivial-auto-var-init=pattern -fgnuc-version=4.2.1 -fskip-odr-check-in-gmf -fno-sized-deallocation -fno-aligned-allocation -vectorize-loops -vectorize-slp -analyzer-checker optin.performance.Padding -analyzer-output=html -analyzer-config stable-report-filename=true -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /tmp/scan-build-2025-06-30-093548-1913035-1 -x c++ /root/firefox-clang/intl/icu/source/i18n/ucol_sit.cpp
| 1 | |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
| 6 | |
| 7 | |
| 8 | |
| 9 | |
| 10 | |
| 11 | |
| 12 | |
| 13 | |
| 14 | |
| 15 | |
| 16 | |
| 17 | |
| 18 | #include "unicode/ustring.h" |
| 19 | #include "unicode/udata.h" |
| 20 | #include "unicode/utf16.h" |
| 21 | #include "utracimp.h" |
| 22 | #include "ucol_imp.h" |
| 23 | #include "ulocimp.h" |
| 24 | #include "cmemory.h" |
| 25 | #include "cstring.h" |
| 26 | #include "uresimp.h" |
| 27 | #include "unicode/coll.h" |
| 28 | #include "unicode/stringpiece.h" |
| 29 | #include "charstr.h" |
| 30 | |
| 31 | U_NAMESPACE_USE |
| 32 | |
| 33 | #ifdef UCOL_TRACE_SIT |
| 34 | # include <stdio.h> |
| 35 | #endif |
| 36 | |
| 37 | #if !UCONFIG_NO_COLLATION |
| 38 | |
| 39 | #include "unicode/tblcoll.h" |
| 40 | |
| 41 | enum OptionsList { |
| 42 | UCOL_SIT_LANGUAGE = 0, |
| 43 | UCOL_SIT_SCRIPT = 1, |
| 44 | UCOL_SIT_REGION = 2, |
| 45 | UCOL_SIT_VARIANT = 3, |
| 46 | UCOL_SIT_KEYWORD = 4, |
| 47 | UCOL_SIT_PROVIDER = 5, |
| 48 | UCOL_SIT_LOCELEMENT_MAX = UCOL_SIT_PROVIDER, |
| 49 | |
| 50 | UCOL_SIT_BCP47, |
| 51 | UCOL_SIT_STRENGTH, |
| 52 | UCOL_SIT_CASE_LEVEL, |
| 53 | UCOL_SIT_CASE_FIRST, |
| 54 | UCOL_SIT_NUMERIC_COLLATION, |
| 55 | UCOL_SIT_ALTERNATE_HANDLING, |
| 56 | UCOL_SIT_NORMALIZATION_MODE, |
| 57 | UCOL_SIT_FRENCH_COLLATION, |
| 58 | UCOL_SIT_HIRAGANA_QUATERNARY, |
| 59 | UCOL_SIT_VARIABLE_TOP, |
| 60 | UCOL_SIT_VARIABLE_TOP_VALUE, |
| 61 | UCOL_SIT_ITEMS_COUNT |
| 62 | }; |
| 63 | |
| 64 | |
| 65 | static const char alternateHArg = 'A'; |
| 66 | static const char variableTopValArg = 'B'; |
| 67 | static const char caseFirstArg = 'C'; |
| 68 | static const char numericCollArg = 'D'; |
| 69 | static const char caseLevelArg = 'E'; |
| 70 | static const char frenchCollArg = 'F'; |
| 71 | static const char hiraganaQArg = 'H'; |
| 72 | static const char keywordArg = 'K'; |
| 73 | static const char languageArg = 'L'; |
| 74 | static const char normArg = 'N'; |
| 75 | static const char providerArg = 'P'; |
| 76 | static const char regionArg = 'R'; |
| 77 | static const char strengthArg = 'S'; |
| 78 | static const char variableTopArg = 'T'; |
| 79 | static const char variantArg = 'V'; |
| 80 | static const char RFC3066Arg = 'X'; |
| 81 | static const char scriptArg = 'Z'; |
| 82 | |
| 83 | static const char collationKeyword[] = "@collation="; |
| 84 | static const char providerKeyword[] = "@sp="; |
| 85 | |
| 86 | |
| 87 | static const int32_t locElementCount = UCOL_SIT_LOCELEMENT_MAX+1; |
| 88 | static const int32_t locElementCapacity = 32; |
| 89 | static const int32_t loc3066Capacity = 256; |
| 90 | |
| 91 | |
| 92 | |
| 93 | |
| 94 | |
| 95 | struct CollatorSpec { |
| 96 | inline CollatorSpec(); |
| 97 | |
| 98 | CharString locElements[locElementCount]; |
| 99 | CharString locale; |
| 100 | UColAttributeValue options[UCOL_ATTRIBUTE_COUNT]; |
| 101 | uint32_t variableTopValue; |
| 102 | char16_t variableTopString[locElementCapacity]; |
| 103 | int32_t variableTopStringLen; |
| 104 | UBool variableTopSet; |
| 105 | CharString entries[UCOL_SIT_ITEMS_COUNT]; |
| 106 | }; |
| 107 | |
| 108 | CollatorSpec::CollatorSpec() : |
| 109 | locale(), |
| 110 | variableTopValue(0), |
| 111 | variableTopString(), |
| 112 | variableTopSet(false) |
| 113 | { |
| 114 | |
| 115 | for(int32_t i = 0; i < UCOL_ATTRIBUTE_COUNT; i++) { |
| 116 | options[i] = UCOL_DEFAULT; |
| 117 | } |
| 118 | } |
| 119 | |
| 120 | |
| 121 | |
| 122 | |
| 123 | |
| 124 | struct AttributeConversion { |
| 125 | char letter; |
| 126 | UColAttributeValue value; |
| 127 | }; |
| 128 | |
| 129 | static const AttributeConversion conversions[12] = { |
| 130 | { '1', UCOL_PRIMARY }, |
| 131 | { '2', UCOL_SECONDARY }, |
| 132 | { '3', UCOL_TERTIARY }, |
| 133 | { '4', UCOL_QUATERNARY }, |
| 134 | { 'D', UCOL_DEFAULT }, |
| 135 | { 'I', UCOL_IDENTICAL }, |
| 136 | { 'L', UCOL_LOWER_FIRST }, |
| 137 | { 'N', UCOL_NON_IGNORABLE }, |
| 138 | { 'O', UCOL_ON }, |
| 139 | { 'S', UCOL_SHIFTED }, |
| 140 | { 'U', UCOL_UPPER_FIRST }, |
| 141 | { 'X', UCOL_OFF } |
| 142 | }; |
| 143 | |
| 144 | |
| 145 | static UColAttributeValue |
| 146 | ucol_sit_letterToAttributeValue(char letter, UErrorCode *status) { |
| 147 | uint32_t i = 0; |
| 148 | for(i = 0; i < UPRV_LENGTHOF(conversions); i++) { |
| 149 | if(conversions[i].letter == letter) { |
| 150 | return conversions[i].value; |
| 151 | } |
| 152 | } |
| 153 | *status = U_ILLEGAL_ARGUMENT_ERROR; |
| 154 | #ifdef UCOL_TRACE_SIT |
| 155 | fprintf(stderr, "%s:%d: unknown letter %c: %s\n", __FILE__, __LINE__, letter, u_errorName(*status)); |
| 156 | #endif |
| 157 | return UCOL_DEFAULT; |
| 158 | } |
| 159 | |
| 160 | |
| 161 | U_CDECL_BEGIN |
| 162 | typedef const char* U_CALLCONV |
| 163 | ActionFunction(CollatorSpec *spec, uint32_t value1, const char* string, |
| 164 | UErrorCode *status); |
| 165 | U_CDECL_END |
| 166 | |
| 167 | U_CDECL_BEGIN |
| 168 | static const char* U_CALLCONV |
| 169 | _processLocaleElement(CollatorSpec *spec, uint32_t value, const char* string, |
| 170 | UErrorCode *status) |
| 171 | { |
| 172 | do { |
| 173 | if(value == UCOL_SIT_LANGUAGE || value == UCOL_SIT_KEYWORD || value == UCOL_SIT_PROVIDER) { |
| 174 | spec->locElements[value].append(uprv_tolower(*string), *status); |
| 175 | } else { |
| 176 | spec->locElements[value].append(*string, *status); |
| 177 | } |
| 178 | } while(*(++string) != '_' && *string && U_SUCCESS(*status)); |
| 179 | |
| 180 | return string; |
| 181 | } |
| 182 | U_CDECL_END |
| 183 | |
| 184 | U_CDECL_BEGIN |
| 185 | static const char* U_CALLCONV |
| 186 | _processRFC3066Locale(CollatorSpec *spec, uint32_t, const char* string, |
| 187 | UErrorCode *status) |
| 188 | { |
| 189 | char terminator = *string; |
| 190 | string++; |
| 191 | const char *end = uprv_strchr(string+1, terminator); |
| 192 | if(end == nullptr || end - string >= loc3066Capacity) { |
| 193 | *status = U_BUFFER_OVERFLOW_ERROR; |
| 194 | return string; |
| 195 | } else { |
| 196 | spec->locale.copyFrom(CharString(string, static_cast<int32_t>(end-string), *status), *status); |
| 197 | return end+1; |
| 198 | } |
| 199 | } |
| 200 | |
| 201 | U_CDECL_END |
| 202 | |
| 203 | U_CDECL_BEGIN |
| 204 | static const char* U_CALLCONV |
| 205 | _processCollatorOption(CollatorSpec *spec, uint32_t option, const char* string, |
| 206 | UErrorCode *status) |
| 207 | { |
| 208 | spec->options[option] = ucol_sit_letterToAttributeValue(*string, status); |
| 209 | if((*(++string) != '_' && *string) || U_FAILURE(*status)) { |
| 210 | #ifdef UCOL_TRACE_SIT |
| 211 | fprintf(stderr, "%s:%d: unknown collator option at '%s': %s\n", __FILE__, __LINE__, string, u_errorName(*status)); |
| 212 | #endif |
| 213 | *status = U_ILLEGAL_ARGUMENT_ERROR; |
| 214 | } |
| 215 | return string; |
| 216 | } |
| 217 | U_CDECL_END |
| 218 | |
| 219 | |
| 220 | static char16_t |
| 221 | readHexCodeUnit(const char **string, UErrorCode *status) |
| 222 | { |
| 223 | char16_t result = 0; |
| 224 | int32_t value = 0; |
| 225 | char c; |
| 226 | int32_t noDigits = 0; |
| 227 | while((c = **string) != 0 && noDigits < 4) { |
| 228 | if( c >= '0' && c <= '9') { |
| 229 | value = c - '0'; |
| 230 | } else if ( c >= 'a' && c <= 'f') { |
| 231 | value = c - 'a' + 10; |
| 232 | } else if ( c >= 'A' && c <= 'F') { |
| 233 | value = c - 'A' + 10; |
| 234 | } else { |
| 235 | *status = U_ILLEGAL_ARGUMENT_ERROR; |
| 236 | #ifdef UCOL_TRACE_SIT |
| 237 | fprintf(stderr, "%s:%d: Bad hex char at '%s': %s\n", __FILE__, __LINE__, *string, u_errorName(*status)); |
| 238 | #endif |
| 239 | return 0; |
| 240 | } |
| 241 | result = (result << 4) | static_cast<char16_t>(value); |
| 242 | noDigits++; |
| 243 | (*string)++; |
| 244 | } |
| 245 | |
| 246 | if(noDigits < 4) { |
| 247 | *status = U_ILLEGAL_ARGUMENT_ERROR; |
| 248 | #ifdef UCOL_TRACE_SIT |
| 249 | fprintf(stderr, "%s:%d: Short (only %d digits, wanted 4) at '%s': %s\n", __FILE__, __LINE__, noDigits,*string, u_errorName(*status)); |
| 250 | #endif |
| 251 | } |
| 252 | return result; |
| 253 | } |
| 254 | |
| 255 | U_CDECL_BEGIN |
| 256 | static const char* U_CALLCONV |
| 257 | _processVariableTop(CollatorSpec *spec, uint32_t value1, const char* string, UErrorCode *status) |
| 258 | { |
| 259 | |
| 260 | int32_t i = 0; |
| 261 | if(!value1) { |
| 262 | while(U_SUCCESS(*status) && i < locElementCapacity && *string != 0 && *string != '_') { |
| 263 | spec->variableTopString[i++] = readHexCodeUnit(&string, status); |
| 264 | } |
| 265 | spec->variableTopStringLen = i; |
| 266 | if(i == locElementCapacity && *string != 0 && *string != '_') { |
| 267 | *status = U_BUFFER_OVERFLOW_ERROR; |
| 268 | } |
| 269 | } else { |
| 270 | spec->variableTopValue = readHexCodeUnit(&string, status); |
| 271 | } |
| 272 | if(U_SUCCESS(*status)) { |
| 273 | spec->variableTopSet = true; |
| 274 | } |
| 275 | return string; |
| 276 | } |
| 277 | U_CDECL_END |
| 278 | |
| 279 | |
| 280 | |
| 281 | struct ShortStringOptions { |
| 282 | char optionStart; |
| 283 | ActionFunction *action; |
| 284 | uint32_t attr; |
| 285 | }; |
| 286 | |
| 287 | static const ShortStringOptions options[UCOL_SIT_ITEMS_COUNT] = |
| 288 | { |
| 289 | {alternateHArg, _processCollatorOption, UCOL_ALTERNATE_HANDLING }, |
| 290 | {variableTopValArg, _processVariableTop, 1 }, |
| 291 | {caseFirstArg, _processCollatorOption, UCOL_CASE_FIRST }, |
| 292 | {numericCollArg, _processCollatorOption, UCOL_NUMERIC_COLLATION }, |
| 293 | {caseLevelArg, _processCollatorOption, UCOL_CASE_LEVEL }, |
| 294 | {frenchCollArg, _processCollatorOption, UCOL_FRENCH_COLLATION }, |
| 295 | {hiraganaQArg, _processCollatorOption, UCOL_HIRAGANA_QUATERNARY_MODE }, |
| 296 | {keywordArg, _processLocaleElement, UCOL_SIT_KEYWORD }, |
| 297 | {languageArg, _processLocaleElement, UCOL_SIT_LANGUAGE }, |
| 298 | {normArg, _processCollatorOption, UCOL_NORMALIZATION_MODE }, |
| 299 | {regionArg, _processLocaleElement, UCOL_SIT_REGION }, |
| 300 | {strengthArg, _processCollatorOption, UCOL_STRENGTH }, |
| 301 | {variableTopArg, _processVariableTop, 0 }, |
| 302 | {variantArg, _processLocaleElement, UCOL_SIT_VARIANT }, |
| 303 | {RFC3066Arg, _processRFC3066Locale, 0 }, |
| 304 | {scriptArg, _processLocaleElement, UCOL_SIT_SCRIPT }, |
| 305 | {providerArg, _processLocaleElement, UCOL_SIT_PROVIDER } |
| 306 | }; |
| 307 | |
| 308 | |
| 309 | static |
| 310 | const char* ucol_sit_readOption(const char *start, CollatorSpec *spec, |
| 311 | UErrorCode *status) |
| 312 | { |
| 313 | int32_t i = 0; |
| 314 | |
| 315 | for(i = 0; i < UCOL_SIT_ITEMS_COUNT; i++) { |
| 316 | if(*start == options[i].optionStart) { |
| 317 | const char* end = options[i].action(spec, options[i].attr, start+1, status); |
| 318 | #ifdef UCOL_TRACE_SIT |
| 319 | fprintf(stderr, "***Set %d to %s...\n", i, start); |
| 320 | #endif |
| 321 | |
| 322 | spec->entries[i].copyFrom(CharString(start, static_cast<int32_t>(end - start), *status), *status); |
| 323 | return end; |
| 324 | } |
| 325 | } |
| 326 | *status = U_ILLEGAL_ARGUMENT_ERROR; |
| 327 | #ifdef UCOL_TRACE_SIT |
| 328 | fprintf(stderr, "%s:%d: Unknown option at '%s': %s\n", __FILE__, __LINE__, start, u_errorName(*status)); |
| 329 | #endif |
| 330 | return start; |
| 331 | } |
| 332 | |
| 333 | static const char* |
| 334 | ucol_sit_readSpecs(CollatorSpec *s, const char *string, |
| 335 | UParseError *parseError, UErrorCode *status) |
| 336 | { |
| 337 | const char *definition = string; |
| 338 | while(U_SUCCESS(*status) && *string) { |
| 339 | string = ucol_sit_readOption(string, s, status); |
| 340 | |
| 341 | while(*string && *string == '_') { |
| 342 | string++; |
| 343 | } |
| 344 | } |
| 345 | if(U_FAILURE(*status)) { |
| 346 | parseError->offset = static_cast<int32_t>(string - definition); |
| 347 | } |
| 348 | return string; |
| 349 | } |
| 350 | |
| 351 | static |
| 352 | int32_t ucol_sit_dumpSpecs(CollatorSpec *s, char *destination, int32_t capacity, UErrorCode *status) |
| 353 | { |
| 354 | int32_t i = 0, j = 0; |
| 355 | int32_t len = 0; |
| 356 | char optName; |
| 357 | if(U_SUCCESS(*status)) { |
| |
| 358 | for(i = 0; i < UCOL_SIT_ITEMS_COUNT; i++) { |
| 9 | | Loop condition is true. Entering loop body | |
|
| 359 | if(!s->entries[i].isEmpty()) { |
| |
| 360 | if(len) { |
| |
| 361 | if(len < capacity) { |
| 362 | uprv_strcat(destination, "_"); |
| 363 | } |
| 364 | len++; |
| 365 | } |
| 366 | optName = s->entries[i][0]; |
| 367 | if(optName == languageArg || optName == regionArg || optName == variantArg || optName == keywordArg) { |
| 12 | | Assuming 'optName' is equal to 'languageArg' | |
|
| 368 | for(j = 0; j < s->entries[i].length(); j++) { |
| 13 | | Assuming the condition is true | |
|
| 14 | | Loop condition is true. Entering loop body | |
|
| 369 | if(len + j < capacity) { |
| 15 | | Assuming the condition is true | |
|
| |
| 370 | destination[len+j] = uprv_toupper(s->entries[i][j]); |
| 17 | | Array access (from variable 'destination') results in a null pointer dereference |
|
| 371 | } |
| 372 | } |
| 373 | len += s->entries[i].length(); |
| 374 | } else { |
| 375 | len += s->entries[i].extract(destination + len, capacity - len, *status); |
| 376 | } |
| 377 | } |
| 378 | } |
| 379 | return len; |
| 380 | } else { |
| 381 | return 0; |
| 382 | } |
| 383 | } |
| 384 | |
| 385 | static void |
| 386 | ucol_sit_calculateWholeLocale(CollatorSpec *s, UErrorCode &status) { |
| 387 | |
| 388 | |
| 389 | if(s->locale.isEmpty()) { |
| 390 | |
| 391 | s->locale.append(s->locElements[UCOL_SIT_LANGUAGE], status); |
| 392 | |
| 393 | if(!s->locElements[UCOL_SIT_SCRIPT].isEmpty()) { |
| 394 | s->locale.append("_", status); |
| 395 | s->locale.append(s->locElements[UCOL_SIT_SCRIPT], status); |
| 396 | } |
| 397 | |
| 398 | if(!s->locElements[UCOL_SIT_REGION].isEmpty()) { |
| 399 | s->locale.append("_", status); |
| 400 | s->locale.append(s->locElements[UCOL_SIT_REGION], status); |
| 401 | } else if(!s->locElements[UCOL_SIT_VARIANT].isEmpty()) { |
| 402 | s->locale.append("_", status); |
| 403 | } |
| 404 | |
| 405 | if(!s->locElements[UCOL_SIT_VARIANT].isEmpty()) { |
| 406 | s->locale.append("_", status); |
| 407 | s->locale.append(s->locElements[UCOL_SIT_VARIANT], status); |
| 408 | } |
| 409 | |
| 410 | |
| 411 | if(!s->locElements[UCOL_SIT_KEYWORD].isEmpty()) { |
| 412 | s->locale.append(collationKeyword, status); |
| 413 | s->locale.append(s->locElements[UCOL_SIT_KEYWORD], status); |
| 414 | } |
| 415 | |
| 416 | |
| 417 | if(!s->locElements[UCOL_SIT_PROVIDER].isEmpty()) { |
| 418 | s->locale.append(providerKeyword, status); |
| 419 | s->locale.append(s->locElements[UCOL_SIT_PROVIDER], status); |
| 420 | } |
| 421 | } |
| 422 | } |
| 423 | |
| 424 | |
| 425 | U_CAPI void U_EXPORT2 |
| 426 | ucol_prepareShortStringOpen( const char *definition, |
| 427 | UBool, |
| 428 | UParseError *parseError, |
| 429 | UErrorCode *status) |
| 430 | { |
| 431 | if(U_FAILURE(*status)) return; |
| 432 | |
| 433 | UParseError internalParseError; |
| 434 | |
| 435 | if(!parseError) { |
| 436 | parseError = &internalParseError; |
| 437 | } |
| 438 | parseError->line = 0; |
| 439 | parseError->offset = 0; |
| 440 | parseError->preContext[0] = 0; |
| 441 | parseError->postContext[0] = 0; |
| 442 | |
| 443 | |
| 444 | |
| 445 | |
| 446 | |
| 447 | |
| 448 | |
| 449 | CollatorSpec s; |
| 450 | ucol_sit_readSpecs(&s, definition, parseError, status); |
| 451 | ucol_sit_calculateWholeLocale(&s, *status); |
| 452 | |
| 453 | CharString buffer = ulocimp_canonicalize(s.locale.toStringPiece(), *status); |
| 454 | |
| 455 | UResourceBundle *b = ures_open(U_ICUDATA_COLL, buffer.data(), status); |
| 456 | |
| 457 | UResourceBundle *collations = ures_getByKey(b, "collations", nullptr, status); |
| 458 | UResourceBundle *collElem = nullptr; |
| 459 | |
| 460 | CharString keyBuffer = ulocimp_getKeywordValue(buffer.data(), "collation", *status); |
| 461 | if(keyBuffer.isEmpty()) { |
| 462 | |
| 463 | |
| 464 | UResourceBundle *defaultColl = ures_getByKeyWithFallback(collations, "default", nullptr, status); |
| 465 | if(U_SUCCESS(*status)) { |
| 466 | int32_t defaultKeyLen = 0; |
| 467 | const char16_t *defaultKey = ures_getString(defaultColl, &defaultKeyLen, status); |
| 468 | keyBuffer.appendInvariantChars(defaultKey, defaultKeyLen, *status); |
| 469 | } else { |
| 470 | *status = U_INTERNAL_PROGRAM_ERROR; |
| 471 | return; |
| 472 | } |
| 473 | ures_close(defaultColl); |
| 474 | } |
| 475 | collElem = ures_getByKeyWithFallback(collations, keyBuffer.data(), collElem, status); |
| 476 | ures_close(collElem); |
| 477 | ures_close(collations); |
| 478 | ures_close(b); |
| 479 | } |
| 480 | |
| 481 | |
| 482 | U_CAPI UCollator* U_EXPORT2 |
| 483 | ucol_openFromShortString( const char *definition, |
| 484 | UBool forceDefaults, |
| 485 | UParseError *parseError, |
| 486 | UErrorCode *status) |
| 487 | { |
| 488 | UTRACE_ENTRY_OC(UTRACE_UCOL_OPEN_FROM_SHORT_STRING); |
| 489 | UTRACE_DATA1(UTRACE_INFO, "short string = \"%s\"", definition); |
| 490 | |
| 491 | if (U_FAILURE(*status)) return nullptr; |
| 492 | |
| 493 | UParseError internalParseError; |
| 494 | |
| 495 | if(!parseError) { |
| 496 | parseError = &internalParseError; |
| 497 | } |
| 498 | parseError->line = 0; |
| 499 | parseError->offset = 0; |
| 500 | parseError->preContext[0] = 0; |
| 501 | parseError->postContext[0] = 0; |
| 502 | |
| 503 | |
| 504 | |
| 505 | |
| 506 | |
| 507 | |
| 508 | |
| 509 | const char *string = definition; |
| 510 | CollatorSpec s; |
| 511 | string = ucol_sit_readSpecs(&s, definition, parseError, status); |
| 512 | ucol_sit_calculateWholeLocale(&s, *status); |
| 513 | |
| 514 | #ifdef UCOL_TRACE_SIT |
| 515 | fprintf(stderr, "DEF %s, DATA %s, ERR %s\n", definition, s.locale.data(), u_errorName(*status)); |
| 516 | #endif |
| 517 | CharString buffer = ulocimp_canonicalize(s.locale.toStringPiece(), *status); |
| 518 | |
| 519 | UCollator *result = ucol_open(buffer.data(), status); |
| 520 | int32_t i = 0; |
| 521 | |
| 522 | for(i = 0; i < UCOL_ATTRIBUTE_COUNT; i++) { |
| 523 | if(s.options[i] != UCOL_DEFAULT) { |
| 524 | if(forceDefaults || ucol_getAttribute(result, (UColAttribute)i, status) != s.options[i]) { |
| 525 | ucol_setAttribute(result, (UColAttribute)i, s.options[i], status); |
| 526 | } |
| 527 | |
| 528 | if(U_FAILURE(*status)) { |
| 529 | parseError->offset = (int32_t)(string - definition); |
| 530 | ucol_close(result); |
| 531 | return nullptr; |
| 532 | } |
| 533 | |
| 534 | } |
| 535 | } |
| 536 | if(s.variableTopSet) { |
| 537 | if(s.variableTopString[0]) { |
| 538 | ucol_setVariableTop(result, s.variableTopString, s.variableTopStringLen, status); |
| 539 | } else { |
| 540 | ucol_restoreVariableTop(result, s.variableTopValue, status); |
| 541 | } |
| 542 | } |
| 543 | |
| 544 | |
| 545 | if(U_FAILURE(*status)) { |
| 546 | ucol_close(result); |
| 547 | result = nullptr; |
| 548 | } |
| 549 | |
| 550 | UTRACE_EXIT_PTR_STATUS(result, *status); |
| 551 | return result; |
| 552 | } |
| 553 | |
| 554 | |
| 555 | U_CAPI int32_t U_EXPORT2 |
| 556 | ucol_getShortDefinitionString(const UCollator *coll, |
| 557 | const char *locale, |
| 558 | char *dst, |
| 559 | int32_t capacity, |
| 560 | UErrorCode *status) |
| 561 | { |
| 562 | if(U_FAILURE(*status)) return 0; |
| 563 | if(coll == nullptr) { |
| 564 | *status = U_ILLEGAL_ARGUMENT_ERROR; |
| 565 | return 0; |
| 566 | } |
| 567 | return ((icu::Collator*)coll)->internalGetShortDefinitionString(locale,dst,capacity,*status); |
| 568 | } |
| 569 | |
| 570 | U_CAPI int32_t U_EXPORT2 |
| 571 | ucol_normalizeShortDefinitionString(const char *definition, |
| 572 | char *destination, |
| 573 | int32_t capacity, |
| 574 | UParseError *parseError, |
| 575 | UErrorCode *status) |
| 576 | { |
| 577 | |
| 578 | if(U_FAILURE(*status)) { |
| |
| 579 | return 0; |
| 580 | } |
| 581 | |
| 582 | if(destination) { |
| 2 | | Assuming 'destination' is null | |
|
| |
| 583 | uprv_memset(destination, 0, capacity*sizeof(char)); |
| 584 | } |
| 585 | |
| 586 | UParseError pe; |
| 587 | if(!parseError) { |
| 4 | | Assuming 'parseError' is non-null | |
|
| |
| 588 | parseError = &pe; |
| 589 | } |
| 590 | |
| 591 | |
| 592 | CollatorSpec s; |
| 593 | ucol_sit_readSpecs(&s, definition, parseError, status); |
| 594 | return ucol_sit_dumpSpecs(&s, destination, capacity, status); |
| 6 | | Passing null pointer value via 2nd parameter 'destination' | |
|
| 7 | | Calling 'ucol_sit_dumpSpecs' | |
|
| 595 | } |
| 596 | |
| 597 | |
| 598 | |
| 599 | |
| 600 | |
| 601 | |
| 602 | |
| 603 | |
| 604 | |
| 605 | U_CAPI int32_t U_EXPORT2 |
| 606 | ucol_getContractions( const UCollator *coll, |
| 607 | USet *contractions, |
| 608 | UErrorCode *status) |
| 609 | { |
| 610 | ucol_getContractionsAndExpansions(coll, contractions, nullptr, false, status); |
| 611 | return uset_getItemCount(contractions); |
| 612 | } |
| 613 | |
| 614 | |
| 615 | |
| 616 | |
| 617 | |
| 618 | |
| 619 | |
| 620 | |
| 621 | |
| 622 | |
| 623 | |
| 624 | U_CAPI void U_EXPORT2 |
| 625 | ucol_getContractionsAndExpansions( const UCollator *coll, |
| 626 | USet *contractions, |
| 627 | USet *expansions, |
| 628 | UBool addPrefixes, |
| 629 | UErrorCode *status) |
| 630 | { |
| 631 | if(U_FAILURE(*status)) { |
| 632 | return; |
| 633 | } |
| 634 | if(coll == nullptr) { |
| 635 | *status = U_ILLEGAL_ARGUMENT_ERROR; |
| 636 | return; |
| 637 | } |
| 638 | const icu::RuleBasedCollator *rbc = icu::RuleBasedCollator::rbcFromUCollator(coll); |
| 639 | if(rbc == nullptr) { |
| 640 | *status = U_UNSUPPORTED_ERROR; |
| 641 | return; |
| 642 | } |
| 643 | rbc->internalGetContractionsAndExpansions( |
| 644 | icu::UnicodeSet::fromUSet(contractions), |
| 645 | icu::UnicodeSet::fromUSet(expansions), |
| 646 | addPrefixes, *status); |
| 647 | } |
| 648 | #endif |