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

Side by Side Diff: source/i18n/ucoleitr.cpp

Issue 1621843002: ICU 56 update step 1 (Closed) Base URL: https://chromium.googlesource.com/chromium/deps/icu.git@561
Patch Set: Created 4 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/i18n/ucol_res.cpp ('k') | source/i18n/ucurr.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) 2001-2014, International Business Machines 3 * Copyright (C) 2001-2015, International Business Machines
4 * Corporation and others. All Rights Reserved. 4 * Corporation and others. All Rights Reserved.
5 ****************************************************************************** 5 ******************************************************************************
6 * 6 *
7 * File ucoleitr.cpp 7 * File ucoleitr.cpp
8 * 8 *
9 * Modification History: 9 * Modification History:
10 * 10 *
11 * Date Name Description 11 * Date Name Description
12 * 02/15/2001 synwee Modified all methods to process its own function 12 * 02/15/2001 synwee Modified all methods to process its own function
13 * instead of calling the equivalent c++ api (coleitr.h) 13 * instead of calling the equivalent c++ api (coleitr.h)
(...skipping 13 matching lines...) Expand all
27 #include "cmemory.h" 27 #include "cmemory.h"
28 #include "usrchimp.h" 28 #include "usrchimp.h"
29 29
30 U_NAMESPACE_USE 30 U_NAMESPACE_USE
31 31
32 #define BUFFER_LENGTH 100 32 #define BUFFER_LENGTH 100
33 33
34 #define DEFAULT_BUFFER_SIZE 16 34 #define DEFAULT_BUFFER_SIZE 16
35 #define BUFFER_GROW 8 35 #define BUFFER_GROW 8
36 36
37 #define ARRAY_SIZE(array) (sizeof array / sizeof array[0])
38
39 #define ARRAY_COPY(dst, src, count) uprv_memcpy((void *) (dst), (void *) (src), (count) * sizeof (src)[0]) 37 #define ARRAY_COPY(dst, src, count) uprv_memcpy((void *) (dst), (void *) (src), (count) * sizeof (src)[0])
40 38
41 #define NEW_ARRAY(type, count) (type *) uprv_malloc((count) * sizeof(type)) 39 #define NEW_ARRAY(type, count) (type *) uprv_malloc((count) * sizeof(type))
42 40
43 #define GROW_ARRAY(array, newSize) uprv_realloc((void *) (array), (newSize) * si zeof (array)[0])
44
45 #define DELETE_ARRAY(array) uprv_free((void *) (array)) 41 #define DELETE_ARRAY(array) uprv_free((void *) (array))
46 42
47 struct RCEI 43 struct RCEI
48 { 44 {
49 uint32_t ce; 45 uint32_t ce;
50 int32_t low; 46 int32_t low;
51 int32_t high; 47 int32_t high;
52 }; 48 };
53 49
54 U_NAMESPACE_BEGIN 50 U_NAMESPACE_BEGIN
55 51
56 struct RCEBuffer 52 struct RCEBuffer
57 { 53 {
58 RCEI defaultBuffer[DEFAULT_BUFFER_SIZE]; 54 RCEI defaultBuffer[DEFAULT_BUFFER_SIZE];
59 RCEI *buffer; 55 RCEI *buffer;
60 int32_t bufferIndex; 56 int32_t bufferIndex;
61 int32_t bufferSize; 57 int32_t bufferSize;
62 58
63 RCEBuffer(); 59 RCEBuffer();
64 ~RCEBuffer(); 60 ~RCEBuffer();
65 61
66 UBool empty() const; 62 UBool isEmpty() const;
67 void put(uint32_t ce, int32_t ixLow, int32_t ixHigh); 63 void put(uint32_t ce, int32_t ixLow, int32_t ixHigh, UErrorCode &errorCode) ;
68 const RCEI *get(); 64 const RCEI *get();
69 }; 65 };
70 66
71 RCEBuffer::RCEBuffer() 67 RCEBuffer::RCEBuffer()
72 { 68 {
73 buffer = defaultBuffer; 69 buffer = defaultBuffer;
74 bufferIndex = 0; 70 bufferIndex = 0;
75 bufferSize = UPRV_LENGTHOF(defaultBuffer); 71 bufferSize = UPRV_LENGTHOF(defaultBuffer);
76 } 72 }
77 73
78 RCEBuffer::~RCEBuffer() 74 RCEBuffer::~RCEBuffer()
79 { 75 {
80 if (buffer != defaultBuffer) { 76 if (buffer != defaultBuffer) {
81 DELETE_ARRAY(buffer); 77 DELETE_ARRAY(buffer);
82 } 78 }
83 } 79 }
84 80
85 UBool RCEBuffer::empty() const 81 UBool RCEBuffer::isEmpty() const
86 { 82 {
87 return bufferIndex <= 0; 83 return bufferIndex <= 0;
88 } 84 }
89 85
90 void RCEBuffer::put(uint32_t ce, int32_t ixLow, int32_t ixHigh) 86 void RCEBuffer::put(uint32_t ce, int32_t ixLow, int32_t ixHigh, UErrorCode &erro rCode)
91 { 87 {
88 if (U_FAILURE(errorCode)) {
89 return;
90 }
92 if (bufferIndex >= bufferSize) { 91 if (bufferIndex >= bufferSize) {
93 RCEI *newBuffer = NEW_ARRAY(RCEI, bufferSize + BUFFER_GROW); 92 RCEI *newBuffer = NEW_ARRAY(RCEI, bufferSize + BUFFER_GROW);
93 if (newBuffer == NULL) {
94 errorCode = U_MEMORY_ALLOCATION_ERROR;
95 return;
96 }
94 97
95 ARRAY_COPY(newBuffer, buffer, bufferSize); 98 ARRAY_COPY(newBuffer, buffer, bufferSize);
96 99
97 if (buffer != defaultBuffer) { 100 if (buffer != defaultBuffer) {
98 DELETE_ARRAY(buffer); 101 DELETE_ARRAY(buffer);
99 } 102 }
100 103
101 buffer = newBuffer; 104 buffer = newBuffer;
102 bufferSize += BUFFER_GROW; 105 bufferSize += BUFFER_GROW;
103 } 106 }
(...skipping 26 matching lines...) Expand all
130 if (buffer != defaultBuffer) { 133 if (buffer != defaultBuffer) {
131 DELETE_ARRAY(buffer); 134 DELETE_ARRAY(buffer);
132 } 135 }
133 } 136 }
134 137
135 void PCEBuffer::reset() 138 void PCEBuffer::reset()
136 { 139 {
137 bufferIndex = 0; 140 bufferIndex = 0;
138 } 141 }
139 142
140 UBool PCEBuffer::empty() const 143 UBool PCEBuffer::isEmpty() const
141 { 144 {
142 return bufferIndex <= 0; 145 return bufferIndex <= 0;
143 } 146 }
144 147
145 void PCEBuffer::put(uint64_t ce, int32_t ixLow, int32_t ixHigh) 148 void PCEBuffer::put(uint64_t ce, int32_t ixLow, int32_t ixHigh, UErrorCode &erro rCode)
146 { 149 {
150 if (U_FAILURE(errorCode)) {
151 return;
152 }
147 if (bufferIndex >= bufferSize) { 153 if (bufferIndex >= bufferSize) {
148 PCEI *newBuffer = NEW_ARRAY(PCEI, bufferSize + BUFFER_GROW); 154 PCEI *newBuffer = NEW_ARRAY(PCEI, bufferSize + BUFFER_GROW);
155 if (newBuffer == NULL) {
156 errorCode = U_MEMORY_ALLOCATION_ERROR;
157 return;
158 }
149 159
150 ARRAY_COPY(newBuffer, buffer, bufferSize); 160 ARRAY_COPY(newBuffer, buffer, bufferSize);
151 161
152 if (buffer != defaultBuffer) { 162 if (buffer != defaultBuffer) {
153 DELETE_ARRAY(buffer); 163 DELETE_ARRAY(buffer);
154 } 164 }
155 165
156 buffer = newBuffer; 166 buffer = newBuffer;
157 bufferSize += BUFFER_GROW; 167 bufferSize += BUFFER_GROW;
158 } 168 }
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after
374 { 384 {
375 int64_t result = UCOL_IGNORABLE; 385 int64_t result = UCOL_IGNORABLE;
376 int32_t low = 0, high = 0; 386 int32_t low = 0, high = 0;
377 387
378 if (U_FAILURE(*status)) { 388 if (U_FAILURE(*status)) {
379 return UCOL_PROCESSED_NULLORDER; 389 return UCOL_PROCESSED_NULLORDER;
380 } 390 }
381 391
382 // pceBuffer.reset(); 392 // pceBuffer.reset();
383 393
384 while (pceBuffer.empty()) { 394 while (pceBuffer.isEmpty()) {
385 // buffer raw CEs up to non-ignorable primary 395 // buffer raw CEs up to non-ignorable primary
386 RCEBuffer rceb; 396 RCEBuffer rceb;
387 int32_t ce; 397 int32_t ce;
388 398
389 // **** do we need to reset rceb, or will it always be empty at this poi nt **** 399 // **** do we need to reset rceb, or will it always be empty at this poi nt ****
390 do { 400 do {
391 high = cei->getOffset(); 401 high = cei->getOffset();
392 ce = cei->previous(*status); 402 ce = cei->previous(*status);
393 low = cei->getOffset(); 403 low = cei->getOffset();
394 404
395 if (ce == UCOL_NULLORDER) { 405 if (ce == UCOL_NULLORDER) {
396 if (! rceb.empty()) { 406 if (!rceb.isEmpty()) {
397 break; 407 break;
398 } 408 }
399 409
400 goto finish; 410 goto finish;
401 } 411 }
402 412
403 rceb.put((uint32_t)ce, low, high); 413 rceb.put((uint32_t)ce, low, high, *status);
404 } while ((ce & UCOL_PRIMARYORDERMASK) == 0 || isContinuation(ce)); 414 } while (U_SUCCESS(*status) && ((ce & UCOL_PRIMARYORDERMASK) == 0 || isC ontinuation(ce)));
405 415
406 // process the raw CEs 416 // process the raw CEs
407 while (! rceb.empty()) { 417 while (U_SUCCESS(*status) && !rceb.isEmpty()) {
408 const RCEI *rcei = rceb.get(); 418 const RCEI *rcei = rceb.get();
409 419
410 result = processCE(rcei->ce); 420 result = processCE(rcei->ce);
411 421
412 if (result != UCOL_IGNORABLE) { 422 if (result != UCOL_IGNORABLE) {
413 pceBuffer.put(result, rcei->low, rcei->high); 423 pceBuffer.put(result, rcei->low, rcei->high, *status);
414 } 424 }
415 } 425 }
426 if (U_FAILURE(*status)) {
427 return UCOL_PROCESSED_NULLORDER;
428 }
416 } 429 }
417 430
418 finish: 431 finish:
419 if (pceBuffer.empty()) { 432 if (pceBuffer.isEmpty()) {
420 // **** Is -1 the right value for ixLow, ixHigh? **** 433 // **** Is -1 the right value for ixLow, ixHigh? ****
421 if (ixLow != NULL) { 434 if (ixLow != NULL) {
422 *ixLow = -1; 435 *ixLow = -1;
423 } 436 }
424 437
425 if (ixHigh != NULL) { 438 if (ixHigh != NULL) {
426 *ixHigh = -1 439 *ixHigh = -1
427 ; 440 ;
428 } 441 }
429 return UCOL_PROCESSED_NULLORDER; 442 return UCOL_PROCESSED_NULLORDER;
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
507 return (order >> 8) & 0xff; 520 return (order >> 8) & 0xff;
508 } 521 }
509 522
510 U_CAPI int32_t U_EXPORT2 523 U_CAPI int32_t U_EXPORT2
511 ucol_tertiaryOrder (int32_t order) 524 ucol_tertiaryOrder (int32_t order)
512 { 525 {
513 return order & 0xff; 526 return order & 0xff;
514 } 527 }
515 528
516 #endif /* #if !UCONFIG_NO_COLLATION */ 529 #endif /* #if !UCONFIG_NO_COLLATION */
OLDNEW
« no previous file with comments | « source/i18n/ucol_res.cpp ('k') | source/i18n/ucurr.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698