Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(177)

Side by Side Diff: source/common/uloc.cpp

Issue 845603002: Update ICU to 54.1 step 1 (Closed) Base URL: https://chromium.googlesource.com/chromium/deps/icu.git@master
Patch Set: remove unusued directories Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « source/common/ulist.c ('k') | source/common/uloc_keytype.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 ********************************************************************** 2 **********************************************************************
3 * Copyright (C) 1997-2013, International Business Machines 3 * Copyright (C) 1997-2014, International Business Machines
4 * Corporation and others. All Rights Reserved. 4 * Corporation and others. All Rights Reserved.
5 ********************************************************************** 5 **********************************************************************
6 * 6 *
7 * File ULOC.CPP 7 * File ULOC.CPP
8 * 8 *
9 * Modification History: 9 * Modification History:
10 * 10 *
11 * Date Name Description 11 * Date Name Description
12 * 04/01/97 aliu Creation. 12 * 04/01/97 aliu Creation.
13 * 08/21/98 stephen JDK 1.2 sync 13 * 08/21/98 stephen JDK 1.2 sync
(...skipping 17 matching lines...) Expand all
31 #include "unicode/utypes.h" 31 #include "unicode/utypes.h"
32 #include "unicode/ustring.h" 32 #include "unicode/ustring.h"
33 #include "unicode/uloc.h" 33 #include "unicode/uloc.h"
34 34
35 #include "putilimp.h" 35 #include "putilimp.h"
36 #include "ustr_imp.h" 36 #include "ustr_imp.h"
37 #include "ulocimp.h" 37 #include "ulocimp.h"
38 #include "umutex.h" 38 #include "umutex.h"
39 #include "cstring.h" 39 #include "cstring.h"
40 #include "cmemory.h" 40 #include "cmemory.h"
41 #include "ucln_cmn.h"
42 #include "locmap.h" 41 #include "locmap.h"
43 #include "uarrsort.h" 42 #include "uarrsort.h"
44 #include "uenumimp.h" 43 #include "uenumimp.h"
45 #include "uassert.h" 44 #include "uassert.h"
46 45
47 #include <stdio.h> /* for sprintf */ 46 #include <stdio.h> /* for sprintf */
48 47
49 /* ### Declarations **************************************************/ 48 /* ### Declarations **************************************************/
50 49
51 /* Locale stuff from locid.cpp */ 50 /* Locale stuff from locid.cpp */
(...skipping 2466 matching lines...) Expand 10 before | Expand all | Expand 10 after
2518 *outResult = ULOC_ACCEPT_FAILED; 2517 *outResult = ULOC_ACCEPT_FAILED;
2519 } 2518 }
2520 } 2519 }
2521 for(i=0;i<acceptListCount;i++) { 2520 for(i=0;i<acceptListCount;i++) {
2522 uprv_free(fallbackList[i]); 2521 uprv_free(fallbackList[i]);
2523 } 2522 }
2524 uprv_free(fallbackList); 2523 uprv_free(fallbackList);
2525 return -1; 2524 return -1;
2526 } 2525 }
2527 2526
2527 U_CAPI const char* U_EXPORT2
2528 uloc_toUnicodeLocaleKey(const char* keyword)
2529 {
2530 const char* bcpKey = ulocimp_toBcpKey(keyword);
2531 if (bcpKey == NULL && ultag_isUnicodeLocaleKey(keyword, -1)) {
2532 // unknown keyword, but syntax is fine..
2533 return keyword;
2534 }
2535 return bcpKey;
2536 }
2537
2538 U_CAPI const char* U_EXPORT2
2539 uloc_toUnicodeLocaleType(const char* keyword, const char* value)
2540 {
2541 const char* bcpType = ulocimp_toBcpType(keyword, value, NULL, NULL);
2542 if (bcpType == NULL && ultag_isUnicodeLocaleType(value, -1)) {
2543 // unknown keyword, but syntax is fine..
2544 return value;
2545 }
2546 return bcpType;
2547 }
2548
2549 #define UPRV_ISDIGIT(c) (((c) >= '0') && ((c) <= '9'))
2550 #define UPRV_ISALPHANUM(c) (uprv_isASCIILetter(c) || UPRV_ISDIGIT(c) )
2551
2552 static UBool
2553 isWellFormedLegacyKey(const char* legacyKey)
2554 {
2555 const char* p = legacyKey;
2556 while (*p) {
2557 if (!UPRV_ISALPHANUM(*p)) {
2558 return FALSE;
2559 }
2560 p++;
2561 }
2562 return TRUE;
2563 }
2564
2565 static UBool
2566 isWellFormedLegacyType(const char* legacyType)
2567 {
2568 const char* p = legacyType;
2569 int32_t alphaNumLen = 0;
2570 while (*p) {
2571 if (*p == '_' || *p == '/' || *p == '-') {
2572 if (alphaNumLen == 0) {
2573 return FALSE;
2574 }
2575 alphaNumLen = 0;
2576 } else if (UPRV_ISALPHANUM(*p)) {
2577 alphaNumLen++;
2578 } else {
2579 return FALSE;
2580 }
2581 p++;
2582 }
2583 return (alphaNumLen != 0);
2584 }
2585
2586 U_CAPI const char* U_EXPORT2
2587 uloc_toLegacyKey(const char* keyword)
2588 {
2589 const char* legacyKey = ulocimp_toLegacyKey(keyword);
2590 if (legacyKey == NULL) {
2591 // Checks if the specified locale key is well-formed with the legacy loc ale syntax.
2592 //
2593 // Note:
2594 // Neither ICU nor LDML/CLDR provides the definition of keyword syntax.
2595 // However, a key should not contain '=' obviously. For now, all existi ng
2596 // keys are using ASCII alphabetic letters only. We won't add any new k ey
2597 // that is not compatible with the BCP 47 syntax. Therefore, we assume
2598 // a valid key consist from [0-9a-zA-Z], no symbols.
2599 if (isWellFormedLegacyKey(keyword)) {
2600 return keyword;
2601 }
2602 }
2603 return legacyKey;
2604 }
2605
2606 U_CAPI const char* U_EXPORT2
2607 uloc_toLegacyType(const char* keyword, const char* value)
2608 {
2609 const char* legacyType = ulocimp_toLegacyType(keyword, value, NULL, NULL);
2610 if (legacyType == NULL) {
2611 // Checks if the specified locale type is well-formed with the legacy lo cale syntax.
2612 //
2613 // Note:
2614 // Neither ICU nor LDML/CLDR provides the definition of keyword syntax.
2615 // However, a type should not contain '=' obviously. For now, all exist ing
2616 // types are using ASCII alphabetic letters with a few symbol letters. We won't
2617 // add any new type that is not compatible with the BCP 47 syntax excep t timezone
2618 // IDs. For now, we assume a valid type start with [0-9a-zA-Z], but may contain
2619 // '-' '_' '/' in the middle.
2620 if (isWellFormedLegacyType(value)) {
2621 return value;
2622 }
2623 }
2624 return legacyType;
2625 }
2626
2528 /*eof*/ 2627 /*eof*/
OLDNEW
« no previous file with comments | « source/common/ulist.c ('k') | source/common/uloc_keytype.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698