clang -cc1 -cc1 -triple x86_64-unknown-linux-gnu -analyze -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name locdispnames.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 -mrelocation-model pic -pic-level 2 -pic-is-pie -mframe-pointer=all -fmath-errno -ffp-contract=on -fno-rounding-math -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -debugger-tuning=gdb -fcoverage-compilation-dir=/home/maurizio/node-v18.6.0/out -resource-dir /usr/local/lib/clang/16.0.0 -D V8_DEPRECATION_WARNINGS -D V8_IMMINENT_DEPRECATION_WARNINGS -D _GLIBCXX_USE_CXX11_ABI=1 -D NODE_OPENSSL_CONF_NAME=nodejs_conf -D NODE_OPENSSL_HAS_QUIC -D __STDC_FORMAT_MACROS -D OPENSSL_NO_PINSHARED -D OPENSSL_THREADS -D U_COMMON_IMPLEMENTATION=1 -D U_ATTRIBUTE_DEPRECATED= -D _CRT_SECURE_NO_DEPRECATE= -D U_STATIC_IMPLEMENTATION=1 -D UCONFIG_NO_SERVICE=1 -D U_ENABLE_DYLOAD=0 -D U_HAVE_STD_STRING=1 -D UCONFIG_NO_BREAK_ITERATION=0 -I ../deps/icu-small/source/common -internal-isystem /usr/lib/gcc/x86_64-redhat-linux/8/../../../../include/c++/8 -internal-isystem /usr/lib/gcc/x86_64-redhat-linux/8/../../../../include/c++/8/x86_64-redhat-linux -internal-isystem /usr/lib/gcc/x86_64-redhat-linux/8/../../../../include/c++/8/backward -internal-isystem /usr/local/lib/clang/16.0.0/include -internal-isystem /usr/local/include -internal-isystem /usr/lib/gcc/x86_64-redhat-linux/8/../../../../x86_64-redhat-linux/include -internal-externc-isystem /include -internal-externc-isystem /usr/include -O3 -Wno-unused-parameter -Wno-deprecated-declarations -Wno-strict-aliasing -std=gnu++17 -fdeprecated-macro -fdebug-compilation-dir=/home/maurizio/node-v18.6.0/out -ferror-limit 19 -fgnuc-version=4.2.1 -vectorize-loops -vectorize-slp -analyzer-output=html -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /tmp/scan-build-2022-08-22-142216-507842-1 -x c++ ../deps/icu-small/source/common/locdispnames.cpp
| 1 | |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
| 6 | |
| 7 | |
| 8 | |
| 9 | |
| 10 | |
| 11 | |
| 12 | |
| 13 | |
| 14 | |
| 15 | |
| 16 | |
| 17 | |
| 18 | |
| 19 | |
| 20 | |
| 21 | |
| 22 | #include "unicode/utypes.h" |
| 23 | #include "unicode/brkiter.h" |
| 24 | #include "unicode/locid.h" |
| 25 | #include "unicode/uenum.h" |
| 26 | #include "unicode/uloc.h" |
| 27 | #include "unicode/ures.h" |
| 28 | #include "unicode/ustring.h" |
| 29 | #include "bytesinkutil.h" |
| 30 | #include "charstr.h" |
| 31 | #include "cmemory.h" |
| 32 | #include "cstring.h" |
| 33 | #include "putilimp.h" |
| 34 | #include "ulocimp.h" |
| 35 | #include "uresimp.h" |
| 36 | #include "ureslocs.h" |
| 37 | #include "ustr_imp.h" |
| 38 | |
| 39 | |
| 40 | |
| 41 | U_NAMESPACE_BEGIN |
| 42 | |
| 43 | UnicodeString& |
| 44 | Locale::getDisplayLanguage(UnicodeString& dispLang) const |
| 45 | { |
| 46 | return this->getDisplayLanguage(getDefault(), dispLang); |
| 47 | } |
| 48 | |
| 49 | |
| 50 | |
| 51 | |
| 52 | |
| 53 | |
| 54 | |
| 55 | UnicodeString& |
| 56 | Locale::getDisplayLanguage(const Locale &displayLocale, |
| 57 | UnicodeString &result) const { |
| 58 | UChar *buffer; |
| 59 | UErrorCode errorCode=U_ZERO_ERROR; |
| 60 | int32_t length; |
| 61 | |
| 62 | buffer=result.getBuffer(ULOC_FULLNAME_CAPACITY); |
| 63 | if(buffer==0) { |
| 64 | result.truncate(0); |
| 65 | return result; |
| 66 | } |
| 67 | |
| 68 | length=uloc_getDisplayLanguage(fullName, displayLocale.fullName, |
| 69 | buffer, result.getCapacity(), |
| 70 | &errorCode); |
| 71 | result.releaseBuffer(U_SUCCESS(errorCode) ? length : 0); |
| 72 | |
| 73 | if(errorCode==U_BUFFER_OVERFLOW_ERROR) { |
| 74 | buffer=result.getBuffer(length); |
| 75 | if(buffer==0) { |
| 76 | result.truncate(0); |
| 77 | return result; |
| 78 | } |
| 79 | errorCode=U_ZERO_ERROR; |
| 80 | length=uloc_getDisplayLanguage(fullName, displayLocale.fullName, |
| 81 | buffer, result.getCapacity(), |
| 82 | &errorCode); |
| 83 | result.releaseBuffer(U_SUCCESS(errorCode) ? length : 0); |
| 84 | } |
| 85 | |
| 86 | return result; |
| 87 | } |
| 88 | |
| 89 | UnicodeString& |
| 90 | Locale::getDisplayScript(UnicodeString& dispScript) const |
| 91 | { |
| 92 | return this->getDisplayScript(getDefault(), dispScript); |
| 93 | } |
| 94 | |
| 95 | UnicodeString& |
| 96 | Locale::getDisplayScript(const Locale &displayLocale, |
| 97 | UnicodeString &result) const { |
| 98 | UChar *buffer; |
| 99 | UErrorCode errorCode=U_ZERO_ERROR; |
| 100 | int32_t length; |
| 101 | |
| 102 | buffer=result.getBuffer(ULOC_FULLNAME_CAPACITY); |
| 103 | if(buffer==0) { |
| 104 | result.truncate(0); |
| 105 | return result; |
| 106 | } |
| 107 | |
| 108 | length=uloc_getDisplayScript(fullName, displayLocale.fullName, |
| 109 | buffer, result.getCapacity(), |
| 110 | &errorCode); |
| 111 | result.releaseBuffer(U_SUCCESS(errorCode) ? length : 0); |
| 112 | |
| 113 | if(errorCode==U_BUFFER_OVERFLOW_ERROR) { |
| 114 | buffer=result.getBuffer(length); |
| 115 | if(buffer==0) { |
| 116 | result.truncate(0); |
| 117 | return result; |
| 118 | } |
| 119 | errorCode=U_ZERO_ERROR; |
| 120 | length=uloc_getDisplayScript(fullName, displayLocale.fullName, |
| 121 | buffer, result.getCapacity(), |
| 122 | &errorCode); |
| 123 | result.releaseBuffer(U_SUCCESS(errorCode) ? length : 0); |
| 124 | } |
| 125 | |
| 126 | return result; |
| 127 | } |
| 128 | |
| 129 | UnicodeString& |
| 130 | Locale::getDisplayCountry(UnicodeString& dispCntry) const |
| 131 | { |
| 132 | return this->getDisplayCountry(getDefault(), dispCntry); |
| 133 | } |
| 134 | |
| 135 | UnicodeString& |
| 136 | Locale::getDisplayCountry(const Locale &displayLocale, |
| 137 | UnicodeString &result) const { |
| 138 | UChar *buffer; |
| 139 | UErrorCode errorCode=U_ZERO_ERROR; |
| 140 | int32_t length; |
| 141 | |
| 142 | buffer=result.getBuffer(ULOC_FULLNAME_CAPACITY); |
| 143 | if(buffer==0) { |
| 144 | result.truncate(0); |
| 145 | return result; |
| 146 | } |
| 147 | |
| 148 | length=uloc_getDisplayCountry(fullName, displayLocale.fullName, |
| 149 | buffer, result.getCapacity(), |
| 150 | &errorCode); |
| 151 | result.releaseBuffer(U_SUCCESS(errorCode) ? length : 0); |
| 152 | |
| 153 | if(errorCode==U_BUFFER_OVERFLOW_ERROR) { |
| 154 | buffer=result.getBuffer(length); |
| 155 | if(buffer==0) { |
| 156 | result.truncate(0); |
| 157 | return result; |
| 158 | } |
| 159 | errorCode=U_ZERO_ERROR; |
| 160 | length=uloc_getDisplayCountry(fullName, displayLocale.fullName, |
| 161 | buffer, result.getCapacity(), |
| 162 | &errorCode); |
| 163 | result.releaseBuffer(U_SUCCESS(errorCode) ? length : 0); |
| 164 | } |
| 165 | |
| 166 | return result; |
| 167 | } |
| 168 | |
| 169 | UnicodeString& |
| 170 | Locale::getDisplayVariant(UnicodeString& dispVar) const |
| 171 | { |
| 172 | return this->getDisplayVariant(getDefault(), dispVar); |
| 173 | } |
| 174 | |
| 175 | UnicodeString& |
| 176 | Locale::getDisplayVariant(const Locale &displayLocale, |
| 177 | UnicodeString &result) const { |
| 178 | UChar *buffer; |
| 179 | UErrorCode errorCode=U_ZERO_ERROR; |
| 180 | int32_t length; |
| 181 | |
| 182 | buffer=result.getBuffer(ULOC_FULLNAME_CAPACITY); |
| 183 | if(buffer==0) { |
| 184 | result.truncate(0); |
| 185 | return result; |
| 186 | } |
| 187 | |
| 188 | length=uloc_getDisplayVariant(fullName, displayLocale.fullName, |
| 189 | buffer, result.getCapacity(), |
| 190 | &errorCode); |
| 191 | result.releaseBuffer(U_SUCCESS(errorCode) ? length : 0); |
| 192 | |
| 193 | if(errorCode==U_BUFFER_OVERFLOW_ERROR) { |
| 194 | buffer=result.getBuffer(length); |
| 195 | if(buffer==0) { |
| 196 | result.truncate(0); |
| 197 | return result; |
| 198 | } |
| 199 | errorCode=U_ZERO_ERROR; |
| 200 | length=uloc_getDisplayVariant(fullName, displayLocale.fullName, |
| 201 | buffer, result.getCapacity(), |
| 202 | &errorCode); |
| 203 | result.releaseBuffer(U_SUCCESS(errorCode) ? length : 0); |
| 204 | } |
| 205 | |
| 206 | return result; |
| 207 | } |
| 208 | |
| 209 | UnicodeString& |
| 210 | Locale::getDisplayName( UnicodeString& name ) const |
| 211 | { |
| 212 | return this->getDisplayName(getDefault(), name); |
| 213 | } |
| 214 | |
| 215 | UnicodeString& |
| 216 | Locale::getDisplayName(const Locale &displayLocale, |
| 217 | UnicodeString &result) const { |
| 218 | UChar *buffer; |
| 219 | UErrorCode errorCode=U_ZERO_ERROR; |
| 220 | int32_t length; |
| 221 | |
| 222 | buffer=result.getBuffer(ULOC_FULLNAME_CAPACITY); |
| 223 | if(buffer==0) { |
| 224 | result.truncate(0); |
| 225 | return result; |
| 226 | } |
| 227 | |
| 228 | length=uloc_getDisplayName(fullName, displayLocale.fullName, |
| 229 | buffer, result.getCapacity(), |
| 230 | &errorCode); |
| 231 | result.releaseBuffer(U_SUCCESS(errorCode) ? length : 0); |
| 232 | |
| 233 | if(errorCode==U_BUFFER_OVERFLOW_ERROR) { |
| 234 | buffer=result.getBuffer(length); |
| 235 | if(buffer==0) { |
| 236 | result.truncate(0); |
| 237 | return result; |
| 238 | } |
| 239 | errorCode=U_ZERO_ERROR; |
| 240 | length=uloc_getDisplayName(fullName, displayLocale.fullName, |
| 241 | buffer, result.getCapacity(), |
| 242 | &errorCode); |
| 243 | result.releaseBuffer(U_SUCCESS(errorCode) ? length : 0); |
| 244 | } |
| 245 | |
| 246 | return result; |
| 247 | } |
| 248 | |
| 249 | #if ! UCONFIG_NO_BREAK_ITERATION |
| 250 | |
| 251 | |
| 252 | |
| 253 | UnicodeString& U_EXPORT2 |
| 254 | BreakIterator::getDisplayName(const Locale& objectLocale, |
| 255 | UnicodeString& name) |
| 256 | { |
| 257 | return objectLocale.getDisplayName(name); |
| 258 | } |
| 259 | |
| 260 | |
| 261 | |
| 262 | UnicodeString& U_EXPORT2 |
| 263 | BreakIterator::getDisplayName(const Locale& objectLocale, |
| 264 | const Locale& displayLocale, |
| 265 | UnicodeString& name) |
| 266 | { |
| 267 | return objectLocale.getDisplayName(displayLocale, name); |
| 268 | } |
| 269 | |
| 270 | #endif |
| 271 | |
| 272 | |
| 273 | U_NAMESPACE_END |
| 274 | |
| 275 | |
| 276 | |
| 277 | U_NAMESPACE_USE |
| 278 | |
| 279 | |
| 280 | |
| 281 | |
| 282 | |
| 283 | static const char _kLanguages[] = "Languages"; |
| 284 | static const char _kScripts[] = "Scripts"; |
| 285 | static const char _kScriptsStandAlone[] = "Scripts%stand-alone"; |
| 286 | static const char _kCountries[] = "Countries"; |
| 287 | static const char _kVariants[] = "Variants"; |
| 288 | static const char _kKeys[] = "Keys"; |
| 289 | static const char _kTypes[] = "Types"; |
| 290 | |
| 291 | static const char _kCurrency[] = "currency"; |
| 292 | static const char _kCurrencies[] = "Currencies"; |
| 293 | static const char _kLocaleDisplayPattern[] = "localeDisplayPattern"; |
| 294 | static const char _kPattern[] = "pattern"; |
| 295 | static const char _kSeparator[] = "separator"; |
| 296 | |
| 297 | |
| 298 | |
| 299 | static int32_t |
| 300 | _getStringOrCopyKey(const char *path, const char *locale, |
| 301 | const char *tableKey, |
| 302 | const char* subTableKey, |
| 303 | const char *itemKey, |
| 304 | const char *substitute, |
| 305 | UChar *dest, int32_t destCapacity, |
| 306 | UErrorCode *pErrorCode) { |
| 307 | const UChar *s = NULL; |
| 308 | int32_t length = 0; |
| 309 | |
| 310 | if(itemKey==NULL) { |
| 311 | |
| 312 | icu::LocalUResourceBundlePointer rb(ures_open(path, locale, pErrorCode)); |
| 313 | |
| 314 | if(U_SUCCESS(*pErrorCode)) { |
| 315 | s=ures_getStringByKey(rb.getAlias(), tableKey, &length, pErrorCode); |
| 316 | |
| 317 | } |
| 318 | } else { |
| 319 | bool isLanguageCode = (uprv_strncmp(tableKey, _kLanguages, 9) == 0); |
| 320 | |
| 321 | if (isLanguageCode && uprv_strtol(itemKey, NULL, 10)) { |
| 322 | *pErrorCode = U_MISSING_RESOURCE_ERROR; |
| 323 | } else { |
| 324 | |
| 325 | s=uloc_getTableStringWithFallback(path, locale, |
| 326 | tableKey, |
| 327 | subTableKey, |
| 328 | itemKey, |
| 329 | &length, |
| 330 | pErrorCode); |
| 331 | if (U_FAILURE(*pErrorCode) && isLanguageCode && itemKey != nullptr) { |
| 332 | |
| 333 | *pErrorCode = U_ZERO_ERROR; |
| 334 | Locale canonKey = Locale::createCanonical(itemKey); |
| 335 | s=uloc_getTableStringWithFallback(path, locale, |
| 336 | tableKey, |
| 337 | subTableKey, |
| 338 | canonKey.getName(), |
| 339 | &length, |
| 340 | pErrorCode); |
| 341 | } |
| 342 | } |
| 343 | } |
| 344 | |
| 345 | if(U_SUCCESS(*pErrorCode)) { |
| 346 | int32_t copyLength=uprv_min(length, destCapacity); |
| 347 | if(copyLength>0 && s != NULL) { |
| 348 | u_memcpy(dest, s, copyLength); |
| 349 | } |
| 350 | } else { |
| 351 | |
| 352 | length=(int32_t)uprv_strlen(substitute); |
| 353 | u_charsToUChars(substitute, dest, uprv_min(length, destCapacity)); |
| 354 | *pErrorCode=U_USING_DEFAULT_WARNING; |
| 355 | } |
| 356 | |
| 357 | return u_terminateUChars(dest, destCapacity, length, pErrorCode); |
| 358 | } |
| 359 | |
| 360 | typedef int32_t U_CALLCONV UDisplayNameGetter(const char *, char *, int32_t, UErrorCode *); |
| 361 | |
| 362 | static int32_t |
| 363 | _getDisplayNameForComponent(const char *locale, |
| 364 | const char *displayLocale, |
| 365 | UChar *dest, int32_t destCapacity, |
| 366 | UDisplayNameGetter *getter, |
| 367 | const char *tag, |
| 368 | UErrorCode *pErrorCode) { |
| 369 | char localeBuffer[ULOC_FULLNAME_CAPACITY*4]; |
| 370 | int32_t length; |
| 371 | UErrorCode localStatus; |
| 372 | const char* root = NULL; |
| 373 | |
| 374 | |
| 375 | if(pErrorCode==NULL || U_FAILURE(*pErrorCode)) { |
| 376 | return 0; |
| 377 | } |
| 378 | |
| 379 | if(destCapacity<0 || (destCapacity>0 && dest==NULL)) { |
| 380 | *pErrorCode=U_ILLEGAL_ARGUMENT_ERROR; |
| 381 | return 0; |
| 382 | } |
| 383 | |
| 384 | localStatus = U_ZERO_ERROR; |
| 385 | length=(*getter)(locale, localeBuffer, sizeof(localeBuffer), &localStatus); |
| 386 | if(U_FAILURE(localStatus) || localStatus==U_STRING_NOT_TERMINATED_WARNING) { |
| 387 | *pErrorCode=U_ILLEGAL_ARGUMENT_ERROR; |
| 388 | return 0; |
| 389 | } |
| 390 | if(length==0) { |
| 391 | |
| 392 | if (getter == uloc_getLanguage) { |
| 393 | uprv_strcpy(localeBuffer, "und"); |
| 394 | } else { |
| 395 | return u_terminateUChars(dest, destCapacity, 0, pErrorCode); |
| 396 | } |
| 397 | } |
| 398 | |
| 399 | root = tag == _kCountries ? U_ICUDATA_REGION : U_ICUDATA_LANG; |
| 400 | |
| 401 | return _getStringOrCopyKey(root, displayLocale, |
| 402 | tag, NULL, localeBuffer, |
| 403 | localeBuffer, |
| 404 | dest, destCapacity, |
| 405 | pErrorCode); |
| 406 | } |
| 407 | |
| 408 | U_CAPI int32_t U_EXPORT2 |
| 409 | uloc_getDisplayLanguage(const char *locale, |
| 410 | const char *displayLocale, |
| 411 | UChar *dest, int32_t destCapacity, |
| 412 | UErrorCode *pErrorCode) { |
| 413 | return _getDisplayNameForComponent(locale, displayLocale, dest, destCapacity, |
| 414 | uloc_getLanguage, _kLanguages, pErrorCode); |
| 415 | } |
| 416 | |
| 417 | U_CAPI int32_t U_EXPORT2 |
| 418 | uloc_getDisplayScript(const char* locale, |
| 419 | const char* displayLocale, |
| 420 | UChar *dest, int32_t destCapacity, |
| 421 | UErrorCode *pErrorCode) |
| 422 | { |
| 423 | UErrorCode err = U_ZERO_ERROR; |
| 424 | int32_t res = _getDisplayNameForComponent(locale, displayLocale, dest, destCapacity, |
| 425 | uloc_getScript, _kScriptsStandAlone, &err); |
| 426 | |
| 427 | if (destCapacity == 0 && err == U_BUFFER_OVERFLOW_ERROR) { |
| 428 | |
| 429 | int32_t fallback_res = _getDisplayNameForComponent(locale, displayLocale, dest, destCapacity, |
| 430 | uloc_getScript, _kScripts, pErrorCode); |
| 431 | return (fallback_res > res) ? fallback_res : res; |
| 432 | } |
| 433 | if ( err == U_USING_DEFAULT_WARNING ) { |
| 434 | return _getDisplayNameForComponent(locale, displayLocale, dest, destCapacity, |
| 435 | uloc_getScript, _kScripts, pErrorCode); |
| 436 | } else { |
| 437 | *pErrorCode = err; |
| 438 | return res; |
| 439 | } |
| 440 | } |
| 441 | |
| 442 | static int32_t |
| 443 | uloc_getDisplayScriptInContext(const char* locale, |
| 444 | const char* displayLocale, |
| 445 | UChar *dest, int32_t destCapacity, |
| 446 | UErrorCode *pErrorCode) |
| 447 | { |
| 448 | return _getDisplayNameForComponent(locale, displayLocale, dest, destCapacity, |
| 449 | uloc_getScript, _kScripts, pErrorCode); |
| 450 | } |
| 451 | |
| 452 | U_CAPI int32_t U_EXPORT2 |
| 453 | uloc_getDisplayCountry(const char *locale, |
| 454 | const char *displayLocale, |
| 455 | UChar *dest, int32_t destCapacity, |
| 456 | UErrorCode *pErrorCode) { |
| 457 | return _getDisplayNameForComponent(locale, displayLocale, dest, destCapacity, |
| 458 | uloc_getCountry, _kCountries, pErrorCode); |
| 459 | } |
| 460 | |
| 461 | |
| 462 | |
| 463 | |
| 464 | |
| 465 | |
| 466 | U_CAPI int32_t U_EXPORT2 |
| 467 | uloc_getDisplayVariant(const char *locale, |
| 468 | const char *displayLocale, |
| 469 | UChar *dest, int32_t destCapacity, |
| 470 | UErrorCode *pErrorCode) { |
| 471 | return _getDisplayNameForComponent(locale, displayLocale, dest, destCapacity, |
| 472 | uloc_getVariant, _kVariants, pErrorCode); |
| 473 | } |
| 474 | |
| 475 | |
| 476 | |
| 477 | |
| 478 | |
| 479 | |
| 480 | |
| 481 | |
| 482 | |
| 483 | |
| 484 | |
| 485 | |
| 486 | |
| 487 | U_CAPI int32_t U_EXPORT2 |
| 488 | uloc_getDisplayName(const char *locale, |
| 489 | const char *displayLocale, |
| 490 | UChar *dest, int32_t destCapacity, |
| 491 | UErrorCode *pErrorCode) |
| 492 | { |
| 493 | static const UChar defaultSeparator[9] = { 0x007b, 0x0030, 0x007d, 0x002c, 0x0020, 0x007b, 0x0031, 0x007d, 0x0000 }; |
| 494 | static const UChar sub0[4] = { 0x007b, 0x0030, 0x007d , 0x0000 } ; |
| 495 | static const UChar sub1[4] = { 0x007b, 0x0031, 0x007d , 0x0000 } ; |
| 496 | static const int32_t subLen = 3; |
| 497 | static const UChar defaultPattern[10] = { |
| 498 | 0x007b, 0x0030, 0x007d, 0x0020, 0x0028, 0x007b, 0x0031, 0x007d, 0x0029, 0x0000 |
| 499 | }; |
| 500 | static const int32_t defaultPatLen = 9; |
| 501 | static const int32_t defaultSub0Pos = 0; |
| 502 | static const int32_t defaultSub1Pos = 5; |
| 503 | |
| 504 | int32_t length; |
| 505 | |
| 506 | const UChar *separator; |
| 507 | int32_t sepLen = 0; |
| 508 | const UChar *pattern; |
| 509 | int32_t patLen = 0; |
| 510 | int32_t sub0Pos, sub1Pos; |
| 511 | |
| 512 | UChar formatOpenParen = 0x0028; |
| 513 | UChar formatReplaceOpenParen = 0x005B; |
| 514 | UChar formatCloseParen = 0x0029; |
| 515 | UChar formatReplaceCloseParen = 0x005D; |
| 516 | |
| 517 | UBool haveLang = TRUE; |
| 518 | |
| 519 | UBool haveRest = TRUE; |
| 520 | |
| 521 | UBool retry = FALSE; |
| 522 | |
| 523 | int32_t langi = 0; |
| 524 | |
| 525 | if(pErrorCode==NULL || U_FAILURE(*pErrorCode)) { |
| 1 | Assuming 'pErrorCode' is not equal to NULL | |
|
| 526 | return 0; |
| 527 | } |
| 528 | |
| 529 | if(destCapacity<0 || (destCapacity>0 && dest==NULL)) { |
| 2 | | Assuming 'destCapacity' is >= 0 | |
|
| 3 | | Assuming 'destCapacity' is <= 0 | |
|
| 530 | *pErrorCode=U_ILLEGAL_ARGUMENT_ERROR; |
| 531 | return 0; |
| 532 | } |
| 533 | |
| 534 | { |
| 535 | UErrorCode status = U_ZERO_ERROR; |
| 536 | |
| 537 | icu::LocalUResourceBundlePointer locbundle( |
| 538 | ures_open(U_ICUDATA_LANG, displayLocale, &status)); |
| 539 | icu::LocalUResourceBundlePointer dspbundle( |
| 540 | ures_getByKeyWithFallback(locbundle.getAlias(), _kLocaleDisplayPattern, NULL, &status)); |
| 541 | |
| 542 | separator=ures_getStringByKeyWithFallback(dspbundle.getAlias(), _kSeparator, &sepLen, &status); |
| 543 | pattern=ures_getStringByKeyWithFallback(dspbundle.getAlias(), _kPattern, &patLen, &status); |
| 544 | } |
| 545 | |
| 546 | |
| 547 | if(sepLen == 0) { |
| 4 | | Assuming 'sepLen' is not equal to 0 | |
|
| |
| 548 | separator = defaultSeparator; |
| 549 | } |
| 550 | |
| 551 | |
| 552 | |
| 553 | |
| 554 | |
| 555 | |
| 556 | |
| 557 | |
| 558 | |
| 559 | { |
| 560 | UChar *p0=u_strstr(separator, sub0); |
| 561 | UChar *p1=u_strstr(separator, sub1); |
| 562 | if (p0==NULL || p1==NULL || p1<p0) { |
| 6 | | Assuming 'p0' is not equal to NULL | |
|
| 7 | | Assuming 'p1' is not equal to NULL | |
|
| 8 | | Assuming 'p1' is >= 'p0' | |
|
| |
| 563 | *pErrorCode=U_ILLEGAL_ARGUMENT_ERROR; |
| 564 | return 0; |
| 565 | } |
| 566 | separator = (const UChar *)p0 + subLen; |
| 567 | sepLen = static_cast<int32_t>(p1 - separator); |
| 568 | } |
| 569 | |
| 570 | if(patLen==0 || (patLen==defaultPatLen && !u_strncmp(pattern, defaultPattern, patLen))) { |
| 10 | | Assuming 'patLen' is not equal to 0 | |
|
| 11 | | Assuming 'patLen' is not equal to 'defaultPatLen' | |
|
| 571 | pattern=defaultPattern; |
| 572 | patLen=defaultPatLen; |
| 573 | sub0Pos=defaultSub0Pos; |
| 574 | sub1Pos=defaultSub1Pos; |
| 575 | |
| 576 | } else { |
| 577 | UChar *p0=u_strstr(pattern, sub0); |
| 578 | UChar *p1=u_strstr(pattern, sub1); |
| 579 | if (p0==NULL || p1==NULL) { |
| 12 | | Assuming 'p0' is not equal to NULL | |
|
| 13 | | Assuming 'p1' is not equal to NULL | |
|
| |
| 580 | *pErrorCode=U_ILLEGAL_ARGUMENT_ERROR; |
| 581 | return 0; |
| 582 | } |
| 583 | sub0Pos = static_cast<int32_t>(p0-pattern); |
| 584 | sub1Pos = static_cast<int32_t>(p1-pattern); |
| 585 | if (sub1Pos < sub0Pos) { |
| 15 | | Assuming 'sub1Pos' is >= 'sub0Pos' | |
|
| |
| 586 | int32_t t=sub0Pos; sub0Pos=sub1Pos; sub1Pos=t; |
| 587 | langi=1; |
| 588 | } |
| 589 | if (u_strchr(pattern, 0xFF08) != NULL) { |
| 17 | | Assuming the condition is false | |
|
| |
| 590 | formatOpenParen = 0xFF08; |
| 591 | formatReplaceOpenParen = 0xFF3B; |
| 592 | formatCloseParen = 0xFF09; |
| 593 | formatReplaceCloseParen = 0xFF3D; |
| 594 | } |
| 595 | } |
| 596 | |
| 597 | |
| 598 | |
| 599 | |
| 600 | |
| 601 | |
| 602 | |
| 603 | |
| 604 | do { |
| 605 | UChar* p=dest; |
| 606 | int32_t patPos=0; |
| 607 | int32_t langLen=0; |
| 608 | int32_t langPos=0; |
| 609 | int32_t restLen=0; |
| 610 | int32_t restPos=0; |
| 611 | icu::LocalUEnumerationPointer kenum; |
| 612 | |
| 613 | |
| 614 | if(sub0Pos) { |
| 19 | | Assuming 'sub0Pos' is 0 | |
|
| |
| 615 | if(destCapacity >= sub0Pos) { |
| 616 | while (patPos < sub0Pos) { |
| 617 | *p++ = pattern[patPos++]; |
| 618 | } |
| 619 | } else { |
| 620 | patPos=sub0Pos; |
| 621 | } |
| 622 | length=sub0Pos; |
| 623 | } else { |
| 624 | length=0; |
| 625 | } |
| 626 | |
| 627 | for(int32_t subi=0,resti=0;subi<2;) { |
| 21 | | Loop condition is true. Entering loop body | |
|
| 32 | | Loop condition is true. Entering loop body | |
|
| 43 | | Loop condition is true. Entering loop body | |
|
| 628 | UBool subdone = FALSE; |
| 629 | |
| 630 | |
| 631 | |
| 632 | int32_t cap=destCapacity-length; |
| 633 | if (cap <= 0) { |
| |
| |
| |
| |
| 634 | cap=0; |
| 635 | } else { |
| 636 | p=dest+length; |
| 637 | } |
| 638 | |
| 639 | if (subi == langi) { |
| |
| |
| |
| 640 | if(haveLang) { |
| |
| 641 | langPos=length; |
| 642 | langLen=uloc_getDisplayLanguage(locale, displayLocale, p, cap, pErrorCode); |
| 643 | length+=langLen; |
| 644 | haveLang=langLen>0; |
| 25 | | Assuming 'langLen' is > 0 | |
|
| 645 | } |
| 646 | subdone=TRUE; |
| 647 | } else { |
| 648 | if(!haveRest) { |
| |
| |
| 649 | subdone=TRUE; |
| 650 | } else { |
| 651 | int32_t len; |
| 652 | switch(resti++) { |
| 37 | | Control jumps to 'case 0:' at line 653 | |
|
| 47 | | Control jumps to 'case 1:' at line 657 | |
|
| 653 | case 0: |
| 654 | restPos=length; |
| 655 | len=uloc_getDisplayScriptInContext(locale, displayLocale, p, cap, pErrorCode); |
| 656 | break; |
| 657 | case 1: |
| 658 | len=uloc_getDisplayCountry(locale, displayLocale, p, cap, pErrorCode); |
| 659 | break; |
| 660 | case 2: |
| 661 | len=uloc_getDisplayVariant(locale, displayLocale, p, cap, pErrorCode); |
| 662 | break; |
| 663 | case 3: |
| 664 | kenum.adoptInstead(uloc_openKeywords(locale, pErrorCode)); |
| 665 | U_FALLTHROUGH; |
| 666 | default: { |
| 667 | const char* kw=uenum_next(kenum.getAlias(), &len, pErrorCode); |
| 668 | if (kw == NULL) { |
| 669 | len=0; |
| 670 | subdone=TRUE; |
| 671 | } else { |
| 672 | |
| 673 | |
| 674 | len = uloc_getDisplayKeyword(kw, displayLocale, p, cap, pErrorCode); |
| 675 | if(len) { |
| 676 | if(len < cap) { |
| 677 | p[len]=0x3d; |
| 678 | } |
| 679 | len+=1; |
| 680 | |
| 681 | |
| 682 | cap-=len; |
| 683 | if(cap <= 0) { |
| 684 | cap=0; |
| 685 | } else { |
| 686 | p+=len; |
| 687 | } |
| 688 | } |
| 689 | |
| 690 | if(*pErrorCode == U_BUFFER_OVERFLOW_ERROR) { |
| 691 | *pErrorCode=U_ZERO_ERROR; |
| 692 | } |
| 693 | int32_t vlen = uloc_getDisplayKeywordValue(locale, kw, displayLocale, |
| 694 | p, cap, pErrorCode); |
| 695 | if(len) { |
| 696 | if(vlen==0) { |
| 697 | --len; |
| 698 | } |
| 699 | |
| 700 | cap=destCapacity-length; |
| 701 | if(cap <= 0) { |
| 702 | cap=0; |
| 703 | } else { |
| 704 | p=dest+length; |
| 705 | } |
| 706 | } |
| 707 | len+=vlen; |
| 708 | } |
| 709 | } break; |
| 710 | } |
| 711 | |
| 712 | if (len>0) { |
| 38 | | Execution continues on line 712 | |
|
| |
| 48 | | Execution continues on line 712 | |
|
| |
| |
| 713 | |
| 714 | if(len+sepLen<=cap) { |
| 51 | | Assuming the condition is true | |
|
| |
| 715 | const UChar * plimit = p + len; |
| 716 | for (; p < plimit; p++) { |
| 53 | | Loop condition is false. Execution continues on line 723 | |
|
| 717 | if (*p == formatOpenParen) { |
| 718 | *p = formatReplaceOpenParen; |
| 719 | } else if (*p == formatCloseParen) { |
| 720 | *p = formatReplaceCloseParen; |
| 721 | } |
| 722 | } |
| 723 | for(int32_t i=0;i<sepLen;++i) { |
| 54 | | Assuming 'i' is < 'sepLen' | |
|
| 55 | | Loop condition is true. Entering loop body | |
|
| 724 | *p++=separator[i]; |
| 56 | | Null pointer value stored to 'p' | |
|
| 57 | | Dereference of null pointer |
|
| 725 | } |
| 726 | } |
| 727 | length+=len+sepLen; |
| 728 | } else if(subdone) { |
| |
| 729 | |
| 730 | if (length!=restPos) { |
| 731 | length-=sepLen; |
| 732 | } |
| 733 | restLen=length-restPos; |
| 734 | haveRest=restLen>0; |
| 735 | } |
| 736 | } |
| 737 | } |
| 738 | |
| 739 | if(*pErrorCode == U_BUFFER_OVERFLOW_ERROR) { |
| 26 | | Assuming the condition is false | |
|
| |
| |
| 740 | *pErrorCode=U_ZERO_ERROR; |
| 741 | } |
| 742 | |
| 743 | if(subdone) { |
| |
| 744 | if(haveLang && haveRest) { |
| |
| 745 | |
| 746 | |
| 747 | int32_t padLen; |
| 748 | patPos+=subLen; |
| 749 | padLen=(subi==0 ? sub1Pos : patLen)-patPos; |
| |
| 750 | if(length+padLen <= destCapacity) { |
| 30 | | Assuming the condition is false | |
|
| |
| 751 | p=dest+length; |
| 752 | for(int32_t i=0;i<padLen;++i) { |
| 753 | *p++=pattern[patPos++]; |
| 754 | } |
| 755 | } else { |
| 756 | patPos+=padLen; |
| 757 | } |
| 758 | length+=padLen; |
| 759 | } else if(subi==0) { |
| 760 | |
| 761 | sub0Pos=0; |
| 762 | length=0; |
| 763 | } else if(length>0) { |
| 764 | |
| 765 | length=haveLang?langLen:restLen; |
| 766 | if(dest && sub0Pos!=0) { |
| 767 | if (sub0Pos+length<=destCapacity) { |
| 768 | |
| 769 | |
| 770 | u_memmove(dest, dest+(haveLang?langPos:restPos), length); |
| 771 | } else { |
| 772 | |
| 773 | sub0Pos=0; |
| 774 | |
| 775 | retry=TRUE; |
| 776 | } |
| 777 | } |
| 778 | } |
| 779 | |
| 780 | ++subi; |
| 781 | } |
| 782 | } |
| 783 | } while(retry); |
| 784 | |
| 785 | return u_terminateUChars(dest, destCapacity, length, pErrorCode); |
| 786 | } |
| 787 | |
| 788 | U_CAPI int32_t U_EXPORT2 |
| 789 | uloc_getDisplayKeyword(const char* keyword, |
| 790 | const char* displayLocale, |
| 791 | UChar* dest, |
| 792 | int32_t destCapacity, |
| 793 | UErrorCode* status){ |
| 794 | |
| 795 | |
| 796 | if(status==NULL || U_FAILURE(*status)) { |
| 797 | return 0; |
| 798 | } |
| 799 | |
| 800 | if(destCapacity<0 || (destCapacity>0 && dest==NULL)) { |
| 801 | *status=U_ILLEGAL_ARGUMENT_ERROR; |
| 802 | return 0; |
| 803 | } |
| 804 | |
| 805 | |
| 806 | |
| 807 | return _getStringOrCopyKey(U_ICUDATA_LANG, displayLocale, |
| 808 | _kKeys, NULL, |
| 809 | keyword, |
| 810 | keyword, |
| 811 | dest, destCapacity, |
| 812 | status); |
| 813 | |
| 814 | } |
| 815 | |
| 816 | |
| 817 | #define UCURRENCY_DISPLAY_NAME_INDEX 1 |
| 818 | |
| 819 | U_CAPI int32_t U_EXPORT2 |
| 820 | uloc_getDisplayKeywordValue( const char* locale, |
| 821 | const char* keyword, |
| 822 | const char* displayLocale, |
| 823 | UChar* dest, |
| 824 | int32_t destCapacity, |
| 825 | UErrorCode* status){ |
| 826 | |
| 827 | |
| 828 | |
| 829 | if(status==NULL || U_FAILURE(*status)) { |
| 830 | return 0; |
| 831 | } |
| 832 | |
| 833 | if(destCapacity<0 || (destCapacity>0 && dest==NULL)) { |
| 834 | *status=U_ILLEGAL_ARGUMENT_ERROR; |
| 835 | return 0; |
| 836 | } |
| 837 | |
| 838 | |
| 839 | CharString keywordValue; |
| 840 | { |
| 841 | CharStringByteSink sink(&keywordValue); |
| 842 | ulocimp_getKeywordValue(locale, keyword, sink, status); |
| 843 | } |
| 844 | |
| 845 | |
| 846 | |
| 847 | |
| 848 | |
| 849 | if(uprv_stricmp(keyword, _kCurrency)==0){ |
| 850 | |
| 851 | int32_t dispNameLen = 0; |
| 852 | const UChar *dispName = NULL; |
| 853 | |
| 854 | icu::LocalUResourceBundlePointer bundle( |
| 855 | ures_open(U_ICUDATA_CURR, displayLocale, status)); |
| 856 | icu::LocalUResourceBundlePointer currencies( |
| 857 | ures_getByKey(bundle.getAlias(), _kCurrencies, NULL, status)); |
| 858 | icu::LocalUResourceBundlePointer currency( |
| 859 | ures_getByKeyWithFallback(currencies.getAlias(), keywordValue.data(), NULL, status)); |
| 860 | |
| 861 | dispName = ures_getStringByIndex(currency.getAlias(), UCURRENCY_DISPLAY_NAME_INDEX, &dispNameLen, status); |
| 862 | |
| 863 | if(U_FAILURE(*status)){ |
| 864 | if(*status == U_MISSING_RESOURCE_ERROR){ |
| 865 | |
| 866 | *status = U_USING_DEFAULT_WARNING; |
| 867 | }else{ |
| 868 | return 0; |
| 869 | } |
| 870 | } |
| 871 | |
| 872 | |
| 873 | if(dispName != NULL){ |
| 874 | if(dispNameLen <= destCapacity){ |
| 875 | u_memcpy(dest, dispName, dispNameLen); |
| 876 | return u_terminateUChars(dest, destCapacity, dispNameLen, status); |
| 877 | }else{ |
| 878 | *status = U_BUFFER_OVERFLOW_ERROR; |
| 879 | return dispNameLen; |
| 880 | } |
| 881 | }else{ |
| 882 | |
| 883 | if(keywordValue.length() <= destCapacity){ |
| 884 | u_charsToUChars(keywordValue.data(), dest, keywordValue.length()); |
| 885 | return u_terminateUChars(dest, destCapacity, keywordValue.length(), status); |
| 886 | }else{ |
| 887 | *status = U_BUFFER_OVERFLOW_ERROR; |
| 888 | return keywordValue.length(); |
| 889 | } |
| 890 | } |
| 891 | |
| 892 | |
| 893 | }else{ |
| 894 | |
| 895 | return _getStringOrCopyKey(U_ICUDATA_LANG, displayLocale, |
| 896 | _kTypes, keyword, |
| 897 | keywordValue.data(), |
| 898 | keywordValue.data(), |
| 899 | dest, destCapacity, |
| 900 | status); |
| 901 | } |
| 902 | } |