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

Side by Side Diff: source/common/unames.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/umutex.cpp ('k') | source/common/unicode/brkiter.h » ('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 * 3 *
4 * Copyright (C) 1999-2013, International Business Machines 4 * Copyright (C) 1999-2014, International Business Machines
5 * Corporation and others. All Rights Reserved. 5 * Corporation and others. All Rights Reserved.
6 * 6 *
7 ****************************************************************************** 7 ******************************************************************************
8 * file name: unames.c 8 * file name: unames.c
9 * encoding: US-ASCII 9 * encoding: US-ASCII
10 * tab size: 8 (not used) 10 * tab size: 8 (not used)
11 * indentation:4 11 * indentation:4
12 * 12 *
13 * created on: 1999oct04 13 * created on: 1999oct04
14 * created by: Markus W. Scherer 14 * created by: Markus W. Scherer
(...skipping 11 matching lines...) Expand all
26 #include "cmemory.h" 26 #include "cmemory.h"
27 #include "cstring.h" 27 #include "cstring.h"
28 #include "ucln_cmn.h" 28 #include "ucln_cmn.h"
29 #include "udataswp.h" 29 #include "udataswp.h"
30 #include "uprops.h" 30 #include "uprops.h"
31 31
32 U_NAMESPACE_BEGIN 32 U_NAMESPACE_BEGIN
33 33
34 /* prototypes ------------------------------------------------------------- */ 34 /* prototypes ------------------------------------------------------------- */
35 35
36 #define LENGTHOF(array) (int32_t)(sizeof(array)/sizeof((array)[0]))
37
38 static const char DATA_NAME[] = "unames"; 36 static const char DATA_NAME[] = "unames";
39 static const char DATA_TYPE[] = "icu"; 37 static const char DATA_TYPE[] = "icu";
40 38
41 #define GROUP_SHIFT 5 39 #define GROUP_SHIFT 5
42 #define LINES_PER_GROUP (1L<<GROUP_SHIFT) 40 #define LINES_PER_GROUP (1L<<GROUP_SHIFT)
43 #define GROUP_MASK (LINES_PER_GROUP-1) 41 #define GROUP_MASK (LINES_PER_GROUP-1)
44 42
45 /* 43 /*
46 * This struct was replaced by explicitly accessing equivalent 44 * This struct was replaced by explicitly accessing equivalent
47 * fields from triples of uint16_t. 45 * fields from triples of uint16_t.
(...skipping 383 matching lines...) Expand 10 before | Expand all | Expand 10 after
431 429
432 return cat; 430 return cat;
433 } 431 }
434 432
435 static const char *getCharCatName(UChar32 cp) { 433 static const char *getCharCatName(UChar32 cp) {
436 uint8_t cat = getCharCat(cp); 434 uint8_t cat = getCharCat(cp);
437 435
438 /* Return unknown if the table of names above is not up to 436 /* Return unknown if the table of names above is not up to
439 date. */ 437 date. */
440 438
441 if (cat >= LENGTHOF(charCatNames)) { 439 if (cat >= UPRV_LENGTHOF(charCatNames)) {
442 return "unknown"; 440 return "unknown";
443 } else { 441 } else {
444 return charCatNames[cat]; 442 return charCatNames[cat];
445 } 443 }
446 } 444 }
447 445
448 static uint16_t getExtName(uint32_t code, char *buffer, uint16_t bufferLength) { 446 static uint16_t getExtName(uint32_t code, char *buffer, uint16_t bufferLength) {
449 const char *catname = getCharCatName(code); 447 const char *catname = getCharCatName(code);
450 uint16_t length = 0; 448 uint16_t length = 0;
451 449
(...skipping 818 matching lines...) Expand 10 before | Expand all | Expand 10 after
1270 range=(AlgorithmicRange *)((uint8_t *)range+range->size); 1268 range=(AlgorithmicRange *)((uint8_t *)range+range->size);
1271 --rangeCount; 1269 --rangeCount;
1272 } 1270 }
1273 return maxNameLength; 1271 return maxNameLength;
1274 } 1272 }
1275 1273
1276 static int32_t 1274 static int32_t
1277 calcExtNameSetsLengths(int32_t maxNameLength) { 1275 calcExtNameSetsLengths(int32_t maxNameLength) {
1278 int32_t i, length; 1276 int32_t i, length;
1279 1277
1280 for(i=0; i<LENGTHOF(charCatNames); ++i) { 1278 for(i=0; i<UPRV_LENGTHOF(charCatNames); ++i) {
1281 /* 1279 /*
1282 * for each category, count the length of the category name 1280 * for each category, count the length of the category name
1283 * plus 9= 1281 * plus 9=
1284 * 2 for <> 1282 * 2 for <>
1285 * 1 for - 1283 * 1 for -
1286 * 6 for most hex digits per code point 1284 * 6 for most hex digits per code point
1287 */ 1285 */
1288 length=9+calcStringSetLength(gNameSet, charCatNames[i]); 1286 length=9+calcStringSetLength(gNameSet, charCatNames[i]);
1289 if(length>maxNameLength) { 1287 if(length>maxNameLength) {
1290 maxNameLength=length; 1288 maxNameLength=length;
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
1433 1431
1434 /* set sets and lengths from extended names */ 1432 /* set sets and lengths from extended names */
1435 maxNameLength=calcExtNameSetsLengths(maxNameLength); 1433 maxNameLength=calcExtNameSetsLengths(maxNameLength);
1436 1434
1437 /* set sets and lengths from group names, set global maximum values */ 1435 /* set sets and lengths from group names, set global maximum values */
1438 calcGroupNameSetsLengths(maxNameLength); 1436 calcGroupNameSetsLengths(maxNameLength);
1439 1437
1440 return TRUE; 1438 return TRUE;
1441 } 1439 }
1442 1440
1441 U_NAMESPACE_END
1442
1443 /* public API --------------------------------------------------------------- */ 1443 /* public API --------------------------------------------------------------- */
1444 1444
1445 U_NAMESPACE_USE
1446
1445 U_CAPI int32_t U_EXPORT2 1447 U_CAPI int32_t U_EXPORT2
1446 u_charName(UChar32 code, UCharNameChoice nameChoice, 1448 u_charName(UChar32 code, UCharNameChoice nameChoice,
1447 char *buffer, int32_t bufferLength, 1449 char *buffer, int32_t bufferLength,
1448 UErrorCode *pErrorCode) { 1450 UErrorCode *pErrorCode) {
1449 AlgorithmicRange *algRange; 1451 AlgorithmicRange *algRange;
1450 uint32_t *p; 1452 uint32_t *p;
1451 uint32_t i; 1453 uint32_t i;
1452 int32_t length; 1454 int32_t length;
1453 1455
1454 /* check the argument values */ 1456 /* check the argument values */
1455 if(pErrorCode==NULL || U_FAILURE(*pErrorCode)) { 1457 if(pErrorCode==NULL || U_FAILURE(*pErrorCode)) {
1456 return 0; 1458 return 0;
1457 } else if(nameChoice>=U_CHAR_NAME_CHOICE_COUNT || 1459 } else if(nameChoice>=U_CHAR_NAME_CHOICE_COUNT ||
1458 bufferLength<0 || (bufferLength>0 && buffer==NULL) 1460 bufferLength<0 || (bufferLength>0 && buffer==NULL)
1459 ) { 1461 ) {
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
1545 } else { 1547 } else {
1546 upper[i]=lower[i]=0; 1548 upper[i]=lower[i]=0;
1547 break; 1549 break;
1548 } 1550 }
1549 } 1551 }
1550 if(i==sizeof(upper)) { 1552 if(i==sizeof(upper)) {
1551 /* name too long, there is no such character */ 1553 /* name too long, there is no such character */
1552 *pErrorCode = U_ILLEGAL_CHAR_FOUND; 1554 *pErrorCode = U_ILLEGAL_CHAR_FOUND;
1553 return error; 1555 return error;
1554 } 1556 }
1557 // i==strlen(name)==strlen(lower)==strlen(upper)
1555 1558
1556 /* try extended names first */ 1559 /* try extended names first */
1557 if (lower[0] == '<') { 1560 if (lower[0] == '<') {
1558 if (nameChoice == U_EXTENDED_CHAR_NAME) { 1561 if (nameChoice == U_EXTENDED_CHAR_NAME) {
1559 if (lower[--i] == '>') { 1562 // Parse a string like "<category-HHHH>" where HHHH is a hex code po int.
1560 for (--i; lower[i] && lower[i] != '-'; --i) { 1563 if (lower[--i] == '>' && i >= 3 && lower[--i] != '-') {
1561 } 1564 while (i >= 3 && lower[--i] != '-') {}
1562 1565
1563 if (lower[i] == '-') { /* We've got a category. */ 1566 if (i >= 2 && lower[i] == '-') {
1564 uint32_t cIdx; 1567 uint32_t cIdx;
1565 1568
1566 lower[i] = 0; 1569 lower[i] = 0;
1567 1570
1568 for (++i; lower[i] != '>'; ++i) { 1571 for (++i; lower[i] != '>'; ++i) {
1569 if (lower[i] >= '0' && lower[i] <= '9') { 1572 if (lower[i] >= '0' && lower[i] <= '9') {
1570 cp = (cp << 4) + lower[i] - '0'; 1573 cp = (cp << 4) + lower[i] - '0';
1571 } else if (lower[i] >= 'a' && lower[i] <= 'f') { 1574 } else if (lower[i] >= 'a' && lower[i] <= 'f') {
1572 cp = (cp << 4) + lower[i] - 'a' + 10; 1575 cp = (cp << 4) + lower[i] - 'a' + 10;
1573 } else { 1576 } else {
1574 *pErrorCode = U_ILLEGAL_CHAR_FOUND; 1577 *pErrorCode = U_ILLEGAL_CHAR_FOUND;
1575 return error; 1578 return error;
1576 } 1579 }
1577 } 1580 }
1578 1581
1579 /* Now validate the category name. 1582 /* Now validate the category name.
1580 We could use a binary search, or a trie, if 1583 We could use a binary search, or a trie, if
1581 we really wanted to. */ 1584 we really wanted to. */
1582 1585
1583 for (lower[i] = 0, cIdx = 0; cIdx < LENGTHOF(charCatNames); ++cIdx) { 1586 for (lower[i] = 0, cIdx = 0; cIdx < UPRV_LENGTHOF(charCatNam es); ++cIdx) {
1584 1587
1585 if (!uprv_strcmp(lower + 1, charCatNames[cIdx])) { 1588 if (!uprv_strcmp(lower + 1, charCatNames[cIdx])) {
1586 if (getCharCat(cp) == cIdx) { 1589 if (getCharCat(cp) == cIdx) {
1587 return cp; 1590 return cp;
1588 } 1591 }
1589 break; 1592 break;
1590 } 1593 }
1591 } 1594 }
1592 } 1595 }
1593 } 1596 }
(...skipping 485 matching lines...) Expand 10 before | Expand all | Expand 10 after
2079 inRange->type, i); 2082 inRange->type, i);
2080 *pErrorCode=U_UNSUPPORTED_ERROR; 2083 *pErrorCode=U_UNSUPPORTED_ERROR;
2081 return 0; 2084 return 0;
2082 } 2085 }
2083 } 2086 }
2084 } 2087 }
2085 2088
2086 return headerSize+(int32_t)offset; 2089 return headerSize+(int32_t)offset;
2087 } 2090 }
2088 2091
2089 U_NAMESPACE_END
2090
2091 /* 2092 /*
2092 * Hey, Emacs, please set the following: 2093 * Hey, Emacs, please set the following:
2093 * 2094 *
2094 * Local Variables: 2095 * Local Variables:
2095 * indent-tabs-mode: nil 2096 * indent-tabs-mode: nil
2096 * End: 2097 * End:
2097 * 2098 *
2098 */ 2099 */
OLDNEW
« no previous file with comments | « source/common/umutex.cpp ('k') | source/common/unicode/brkiter.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698