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

Side by Side Diff: source/common/uniset.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/common/unifiedcache.cpp ('k') | source/common/unistr.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) 1999-2012, International Business Machines 3 * Copyright (C) 1999-2015, International Business Machines
4 * Corporation and others. All Rights Reserved. 4 * Corporation and others. All Rights Reserved.
5 ********************************************************************** 5 **********************************************************************
6 * Date Name Description 6 * Date Name Description
7 * 10/20/99 alan Creation. 7 * 10/20/99 alan Creation.
8 ********************************************************************** 8 **********************************************************************
9 */ 9 */
10 10
11 #include "unicode/utypes.h" 11 #include "unicode/utypes.h"
12 #include "unicode/parsepos.h" 12 #include "unicode/parsepos.h"
13 #include "unicode/symtable.h" 13 #include "unicode/symtable.h"
(...skipping 1447 matching lines...) Expand 10 before | Expand all | Expand 10 after
1461 if (temp) { 1461 if (temp) {
1462 list = temp; 1462 list = temp;
1463 capacity = newCapacity; 1463 capacity = newCapacity;
1464 } 1464 }
1465 // else what the heck happened?! We allocated less memory! 1465 // else what the heck happened?! We allocated less memory!
1466 // Oh well. We'll keep our original array. 1466 // Oh well. We'll keep our original array.
1467 } 1467 }
1468 return *this; 1468 return *this;
1469 } 1469 }
1470 1470
1471 #ifdef DEBUG_SERIALIZE
1472 #include <stdio.h>
1473 #endif
1474
1475 /**
1476 * Deserialize constructor.
1477 */
1478 UnicodeSet::UnicodeSet(const uint16_t data[], int32_t dataLen, ESerialization se rialization, UErrorCode &ec)
1479 : len(1), capacity(1+START_EXTRA), list(0), bmpSet(0), buffer(0),
1480 bufferCapacity(0), patLen(0), pat(NULL), strings(NULL), stringSpan(NULL),
1481 fFlags(0) {
1482
1483 if(U_FAILURE(ec)) {
1484 setToBogus();
1485 return;
1486 }
1487
1488 if( (serialization != kSerialized)
1489 || (data==NULL)
1490 || (dataLen < 1)) {
1491 ec = U_ILLEGAL_ARGUMENT_ERROR;
1492 setToBogus();
1493 return;
1494 }
1495
1496 allocateStrings(ec);
1497 if (U_FAILURE(ec)) {
1498 setToBogus();
1499 return;
1500 }
1501
1502 // bmp?
1503 int32_t headerSize = ((data[0]&0x8000)) ?2:1;
1504 int32_t bmpLength = (headerSize==1)?data[0]:data[1];
1505
1506 len = (((data[0]&0x7FFF)-bmpLength)/2)+bmpLength;
1507 #ifdef DEBUG_SERIALIZE
1508 printf("dataLen %d headerSize %d bmpLen %d len %d. data[0]=%X/%X/%X/%X\n", dat aLen,headerSize,bmpLength,len, data[0],data[1],data[2],data[3]);
1509 #endif
1510 capacity = len+1;
1511 list = (UChar32*) uprv_malloc(sizeof(UChar32) * capacity);
1512 if(!list || U_FAILURE(ec)) {
1513 setToBogus();
1514 return;
1515 }
1516 // copy bmp
1517 int32_t i;
1518 for(i = 0; i< bmpLength;i++) {
1519 list[i] = data[i+headerSize];
1520 #ifdef DEBUG_SERIALIZE
1521 printf("<<16@%d[%d] %X\n", i+headerSize, i, list[i]);
1522 #endif
1523 }
1524 // copy smp
1525 for(i=bmpLength;i<len;i++) {
1526 list[i] = ((UChar32)data[headerSize+bmpLength+(i-bmpLength)*2+0] << 16) +
1527 ((UChar32)data[headerSize+bmpLength+(i-bmpLength)*2+1]);
1528 #ifdef DEBUG_SERIALIZE
1529 printf("<<32@%d+[%d] %lX\n", headerSize+bmpLength+i, i, list[i]);
1530 #endif
1531 }
1532 // terminator
1533 list[len++]=UNICODESET_HIGH;
1534 }
1535
1536
1471 int32_t UnicodeSet::serialize(uint16_t *dest, int32_t destCapacity, UErrorCode& ec) const { 1537 int32_t UnicodeSet::serialize(uint16_t *dest, int32_t destCapacity, UErrorCode& ec) const {
1472 int32_t bmpLength, length, destLength; 1538 int32_t bmpLength, length, destLength;
1473 1539
1474 if (U_FAILURE(ec)) { 1540 if (U_FAILURE(ec)) {
1475 return 0; 1541 return 0;
1476 } 1542 }
1477 1543
1478 if (destCapacity<0 || (destCapacity>0 && dest==NULL)) { 1544 if (destCapacity<0 || (destCapacity>0 && dest==NULL)) {
1479 ec=U_ILLEGAL_ARGUMENT_ERROR; 1545 ec=U_ILLEGAL_ARGUMENT_ERROR;
1480 return 0; 1546 return 0;
(...skipping 18 matching lines...) Expand all
1499 bmpLength=length; 1565 bmpLength=length;
1500 } else if (this->list[0]>=0x10000) { 1566 } else if (this->list[0]>=0x10000) {
1501 /* all supplementary */ 1567 /* all supplementary */
1502 bmpLength=0; 1568 bmpLength=0;
1503 length*=2; 1569 length*=2;
1504 } else { 1570 } else {
1505 /* some BMP, some supplementary */ 1571 /* some BMP, some supplementary */
1506 for (bmpLength=0; bmpLength<length && this->list[bmpLength]<=0xffff; ++b mpLength) {} 1572 for (bmpLength=0; bmpLength<length && this->list[bmpLength]<=0xffff; ++b mpLength) {}
1507 length=bmpLength+2*(length-bmpLength); 1573 length=bmpLength+2*(length-bmpLength);
1508 } 1574 }
1509 1575 #ifdef DEBUG_SERIALIZE
1576 printf(">> bmpLength%d length%d len%d\n", bmpLength, length, len);
1577 #endif
1510 /* length: number of 16-bit array units */ 1578 /* length: number of 16-bit array units */
1511 if (length>0x7fff) { 1579 if (length>0x7fff) {
1512 /* there are only 15 bits for the length in the first serialized word */ 1580 /* there are only 15 bits for the length in the first serialized word */
1513 ec=U_INDEX_OUTOFBOUNDS_ERROR; 1581 ec=U_INDEX_OUTOFBOUNDS_ERROR;
1514 return 0; 1582 return 0;
1515 } 1583 }
1516 1584
1517 /* 1585 /*
1518 * total serialized length: 1586 * total serialized length:
1519 * number of 16-bit array units (length) + 1587 * number of 16-bit array units (length) +
1520 * 1 length unit (always) + 1588 * 1 length unit (always) +
1521 * 1 bmpLength unit (if there are supplementary values) 1589 * 1 bmpLength unit (if there are supplementary values)
1522 */ 1590 */
1523 destLength=length+((length>bmpLength)?2:1); 1591 destLength=length+((length>bmpLength)?2:1);
1524 if (destLength<=destCapacity) { 1592 if (destLength<=destCapacity) {
1525 const UChar32 *p; 1593 const UChar32 *p;
1526 int32_t i; 1594 int32_t i;
1527 1595
1596 #ifdef DEBUG_SERIALIZE
1597 printf("writeHdr\n");
1598 #endif
1528 *dest=(uint16_t)length; 1599 *dest=(uint16_t)length;
1529 if (length>bmpLength) { 1600 if (length>bmpLength) {
1530 *dest|=0x8000; 1601 *dest|=0x8000;
1531 *++dest=(uint16_t)bmpLength; 1602 *++dest=(uint16_t)bmpLength;
1532 } 1603 }
1533 ++dest; 1604 ++dest;
1534 1605
1535 /* write the BMP part of the array */ 1606 /* write the BMP part of the array */
1536 p=this->list; 1607 p=this->list;
1537 for (i=0; i<bmpLength; ++i) { 1608 for (i=0; i<bmpLength; ++i) {
1609 #ifdef DEBUG_SERIALIZE
1610 printf("writebmp: %x\n", (int)*p);
1611 #endif
1538 *dest++=(uint16_t)*p++; 1612 *dest++=(uint16_t)*p++;
1539 } 1613 }
1540 1614
1541 /* write the supplementary part of the array */ 1615 /* write the supplementary part of the array */
1542 for (; i<length; i+=2) { 1616 for (; i<length; i+=2) {
1617 #ifdef DEBUG_SERIALIZE
1618 printf("write32: %x\n", (int)*p);
1619 #endif
1543 *dest++=(uint16_t)(*p>>16); 1620 *dest++=(uint16_t)(*p>>16);
1544 *dest++=(uint16_t)*p++; 1621 *dest++=(uint16_t)*p++;
1545 } 1622 }
1546 } else { 1623 } else {
1547 ec=U_BUFFER_OVERFLOW_ERROR; 1624 ec=U_BUFFER_OVERFLOW_ERROR;
1548 } 1625 }
1549 return destLength; 1626 return destLength;
1550 } 1627 }
1551 1628
1552 //---------------------------------------------------------------- 1629 //----------------------------------------------------------------
(...skipping 721 matching lines...) Expand 10 before | Expand all | Expand 10 after
2274 do { 2351 do {
2275 U8_PREV_OR_FFFD(s, 0, length, c); 2352 U8_PREV_OR_FFFD(s, 0, length, c);
2276 if(spanCondition!=contains(c)) { 2353 if(spanCondition!=contains(c)) {
2277 break; 2354 break;
2278 } 2355 }
2279 } while((prev=length)>0); 2356 } while((prev=length)>0);
2280 return prev; 2357 return prev;
2281 } 2358 }
2282 2359
2283 U_NAMESPACE_END 2360 U_NAMESPACE_END
OLDNEW
« no previous file with comments | « source/common/unifiedcache.cpp ('k') | source/common/unistr.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698