| OLD | NEW |
| 1 /* | 1 /* |
| 2 ****************************************************************************** | 2 ****************************************************************************** |
| 3 * | 3 * |
| 4 * Copyright (C) 2001-2011, International Business Machines | 4 * Copyright (C) 2001-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: utrie2_builder.cpp | 8 * file name: utrie2_builder.cpp |
| 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: 2008sep26 (split off from utrie2.c) | 13 * created on: 2008sep26 (split off from utrie2.c) |
| 14 * created by: Markus W. Scherer | 14 * created by: Markus W. Scherer |
| (...skipping 11 matching lines...) Expand all Loading... |
| 26 # include <stdio.h> | 26 # include <stdio.h> |
| 27 #endif | 27 #endif |
| 28 | 28 |
| 29 #include "unicode/utypes.h" | 29 #include "unicode/utypes.h" |
| 30 #include "cmemory.h" | 30 #include "cmemory.h" |
| 31 #include "utrie2.h" | 31 #include "utrie2.h" |
| 32 #include "utrie2_impl.h" | 32 #include "utrie2_impl.h" |
| 33 | 33 |
| 34 #include "utrie.h" /* for utrie2_fromUTrie() and utrie_swap() */ | 34 #include "utrie.h" /* for utrie2_fromUTrie() and utrie_swap() */ |
| 35 | 35 |
| 36 #define LENGTHOF(array) (int32_t)(sizeof(array)/sizeof((array)[0])) | |
| 37 | |
| 38 /* Implementation notes ----------------------------------------------------- */ | 36 /* Implementation notes ----------------------------------------------------- */ |
| 39 | 37 |
| 40 /* | 38 /* |
| 41 * The UTRIE2_SHIFT_1, UTRIE2_SHIFT_2, UTRIE2_INDEX_SHIFT and other values | 39 * The UTRIE2_SHIFT_1, UTRIE2_SHIFT_2, UTRIE2_INDEX_SHIFT and other values |
| 42 * have been chosen to minimize trie sizes overall. | 40 * have been chosen to minimize trie sizes overall. |
| 43 * Most of the code is flexible enough to work with a range of values, | 41 * Most of the code is flexible enough to work with a range of values, |
| 44 * within certain limits. | 42 * within certain limits. |
| 45 * | 43 * |
| 46 * Exception: Support for separate values for lead surrogate code _units_ | 44 * Exception: Support for separate values for lead surrogate code _units_ |
| 47 * vs. code _points_ was added after the constants were fixed, | 45 * vs. code _points_ was added after the constants were fixed, |
| (...skipping 421 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 469 block=trie->index2[i2]; | 467 block=trie->index2[i2]; |
| 470 return (UBool)(block==trie->dataNullOffset); | 468 return (UBool)(block==trie->dataNullOffset); |
| 471 } | 469 } |
| 472 | 470 |
| 473 static int32_t | 471 static int32_t |
| 474 allocIndex2Block(UNewTrie2 *trie) { | 472 allocIndex2Block(UNewTrie2 *trie) { |
| 475 int32_t newBlock, newTop; | 473 int32_t newBlock, newTop; |
| 476 | 474 |
| 477 newBlock=trie->index2Length; | 475 newBlock=trie->index2Length; |
| 478 newTop=newBlock+UTRIE2_INDEX_2_BLOCK_LENGTH; | 476 newTop=newBlock+UTRIE2_INDEX_2_BLOCK_LENGTH; |
| 479 if(newTop>LENGTHOF(trie->index2)) { | 477 if(newTop>UPRV_LENGTHOF(trie->index2)) { |
| 480 /* | 478 /* |
| 481 * Should never occur. | 479 * Should never occur. |
| 482 * Either UTRIE2_MAX_BUILD_TIME_INDEX_LENGTH is incorrect, | 480 * Either UTRIE2_MAX_BUILD_TIME_INDEX_LENGTH is incorrect, |
| 483 * or the code writes more values than should be possible. | 481 * or the code writes more values than should be possible. |
| 484 */ | 482 */ |
| 485 return -1; | 483 return -1; |
| 486 } | 484 } |
| 487 trie->index2Length=newTop; | 485 trie->index2Length=newTop; |
| 488 uprv_memcpy(trie->index2+newBlock, trie->index2+trie->index2NullOffset, UTRI
E2_INDEX_2_BLOCK_LENGTH*4); | 486 uprv_memcpy(trie->index2+newBlock, trie->index2+trie->index2NullOffset, UTRI
E2_INDEX_2_BLOCK_LENGTH*4); |
| 489 return newBlock; | 487 return newBlock; |
| (...skipping 920 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1410 *pErrorCode=U_ILLEGAL_ARGUMENT_ERROR; | 1408 *pErrorCode=U_ILLEGAL_ARGUMENT_ERROR; |
| 1411 return; | 1409 return; |
| 1412 } | 1410 } |
| 1413 | 1411 |
| 1414 /* Delete the UNewTrie2. */ | 1412 /* Delete the UNewTrie2. */ |
| 1415 uprv_free(newTrie->data); | 1413 uprv_free(newTrie->data); |
| 1416 uprv_free(newTrie); | 1414 uprv_free(newTrie); |
| 1417 trie->newTrie=NULL; | 1415 trie->newTrie=NULL; |
| 1418 } | 1416 } |
| 1419 | 1417 |
| 1420 U_CAPI UBool U_EXPORT2 | |
| 1421 utrie2_isFrozen(const UTrie2 *trie) { | |
| 1422 return (UBool)(trie->newTrie==NULL); | |
| 1423 } | |
| 1424 | |
| 1425 U_CAPI int32_t U_EXPORT2 | |
| 1426 utrie2_serialize(UTrie2 *trie, | |
| 1427 void *data, int32_t capacity, | |
| 1428 UErrorCode *pErrorCode) { | |
| 1429 /* argument check */ | |
| 1430 if(U_FAILURE(*pErrorCode)) { | |
| 1431 return 0; | |
| 1432 } | |
| 1433 | |
| 1434 if( trie==NULL || trie->memory==NULL || trie->newTrie!=NULL || | |
| 1435 capacity<0 || (capacity>0 && (data==NULL || (U_POINTER_MASK_LSB(data, 3)
!=0))) | |
| 1436 ) { | |
| 1437 *pErrorCode=U_ILLEGAL_ARGUMENT_ERROR; | |
| 1438 return 0; | |
| 1439 } | |
| 1440 | |
| 1441 if(capacity>=trie->length) { | |
| 1442 uprv_memcpy(data, trie->memory, trie->length); | |
| 1443 } else { | |
| 1444 *pErrorCode=U_BUFFER_OVERFLOW_ERROR; | |
| 1445 } | |
| 1446 return trie->length; | |
| 1447 } | |
| 1448 | |
| 1449 /* | 1418 /* |
| 1450 * This is here to avoid a dependency from utrie2.cpp on utrie.c. | 1419 * This is here to avoid a dependency from utrie2.cpp on utrie.c. |
| 1451 * This file already depends on utrie.c. | 1420 * This file already depends on utrie.c. |
| 1452 * Otherwise, this should be in utrie2.cpp right after utrie2_swap(). | 1421 * Otherwise, this should be in utrie2.cpp right after utrie2_swap(). |
| 1453 */ | 1422 */ |
| 1454 U_CAPI int32_t U_EXPORT2 | 1423 U_CAPI int32_t U_EXPORT2 |
| 1455 utrie2_swapAnyVersion(const UDataSwapper *ds, | 1424 utrie2_swapAnyVersion(const UDataSwapper *ds, |
| 1456 const void *inData, int32_t length, void *outData, | 1425 const void *inData, int32_t length, void *outData, |
| 1457 UErrorCode *pErrorCode) { | 1426 UErrorCode *pErrorCode) { |
| 1458 if(U_SUCCESS(*pErrorCode)) { | 1427 if(U_SUCCESS(*pErrorCode)) { |
| 1459 switch(utrie2_getVersion(inData, length, TRUE)) { | 1428 switch(utrie2_getVersion(inData, length, TRUE)) { |
| 1460 case 1: | 1429 case 1: |
| 1461 return utrie_swap(ds, inData, length, outData, pErrorCode); | 1430 return utrie_swap(ds, inData, length, outData, pErrorCode); |
| 1462 case 2: | 1431 case 2: |
| 1463 return utrie2_swap(ds, inData, length, outData, pErrorCode); | 1432 return utrie2_swap(ds, inData, length, outData, pErrorCode); |
| 1464 default: | 1433 default: |
| 1465 *pErrorCode=U_INVALID_FORMAT_ERROR; | 1434 *pErrorCode=U_INVALID_FORMAT_ERROR; |
| 1466 return 0; | 1435 return 0; |
| 1467 } | 1436 } |
| 1468 } | 1437 } |
| 1469 return 0; | 1438 return 0; |
| 1470 } | 1439 } |
| OLD | NEW |