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

Side by Side Diff: source/common/utext.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/ustrtrns.cpp ('k') | source/common/utrace.c » ('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) 2005-2012, International Business Machines 4 * Copyright (C) 2005-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: utext.cpp 8 * file name: utext.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: 2005apr12 13 * created on: 2005apr12
14 * created by: Markus W. Scherer 14 * created by: Markus W. Scherer
(...skipping 494 matching lines...) Expand 10 before | Expand all | Expand 10 after
509 *status = U_NO_WRITE_PERMISSION; 509 *status = U_NO_WRITE_PERMISSION;
510 return; 510 return;
511 } 511 }
512 ut->pFuncs->copy(ut, nativeStart, nativeLimit, destIndex, move, status); 512 ut->pFuncs->copy(ut, nativeStart, nativeLimit, destIndex, move, status);
513 } 513 }
514 514
515 515
516 516
517 U_CAPI UText * U_EXPORT2 517 U_CAPI UText * U_EXPORT2
518 utext_clone(UText *dest, const UText *src, UBool deep, UBool readOnly, UErrorCod e *status) { 518 utext_clone(UText *dest, const UText *src, UBool deep, UBool readOnly, UErrorCod e *status) {
519 UText *result; 519 if (U_FAILURE(*status)) {
520 result = src->pFuncs->clone(dest, src, deep, status); 520 return dest;
521 }
522 UText *result = src->pFuncs->clone(dest, src, deep, status);
523 if (U_FAILURE(*status)) {
524 return result;
525 }
526 if (result == NULL) {
527 *status = U_MEMORY_ALLOCATION_ERROR;
528 return result;
529 }
521 if (readOnly) { 530 if (readOnly) {
522 utext_freeze(result); 531 utext_freeze(result);
523 } 532 }
524 return result; 533 return result;
525 } 534 }
526 535
527 536
528 537
529 //------------------------------------------------------------------------------ 538 //------------------------------------------------------------------------------
530 // 539 //
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after
799 // 808 //
800 // Relocate any pointers in the target that refer to the UText itself 809 // Relocate any pointers in the target that refer to the UText itself
801 // to point to the cloned copy rather than the original source. 810 // to point to the cloned copy rather than the original source.
802 // 811 //
803 adjustPointer(dest, &dest->context, src); 812 adjustPointer(dest, &dest->context, src);
804 adjustPointer(dest, &dest->p, src); 813 adjustPointer(dest, &dest->p, src);
805 adjustPointer(dest, &dest->q, src); 814 adjustPointer(dest, &dest->q, src);
806 adjustPointer(dest, &dest->r, src); 815 adjustPointer(dest, &dest->r, src);
807 adjustPointer(dest, (const void **)&dest->chunkContents, src); 816 adjustPointer(dest, (const void **)&dest->chunkContents, src);
808 817
818 // The newly shallow-cloned UText does _not_ own the underlying storage for the text.
819 // (The source for the clone may or may not have owned the text.)
820
821 dest->providerProperties &= ~I32_FLAG(UTEXT_PROVIDER_OWNS_TEXT);
822
809 return dest; 823 return dest;
810 } 824 }
811 825
812 826
813 U_CDECL_END 827 U_CDECL_END
814 828
815 829
816 830
817 //------------------------------------------------------------------------------ 831 //------------------------------------------------------------------------------
818 // 832 //
(...skipping 749 matching lines...) Expand 10 before | Expand all | Expand 10 after
1568 if (ut->providerProperties & I32_FLAG(UTEXT_PROVIDER_OWNS_TEXT)) { 1582 if (ut->providerProperties & I32_FLAG(UTEXT_PROVIDER_OWNS_TEXT)) {
1569 char *s = (char *)ut->context; 1583 char *s = (char *)ut->context;
1570 uprv_free(s); 1584 uprv_free(s);
1571 ut->context = NULL; 1585 ut->context = NULL;
1572 } 1586 }
1573 } 1587 }
1574 1588
1575 U_CDECL_END 1589 U_CDECL_END
1576 1590
1577 1591
1578 static const struct UTextFuncs utf8Funcs = 1592 static const struct UTextFuncs utf8Funcs =
1579 { 1593 {
1580 sizeof(UTextFuncs), 1594 sizeof(UTextFuncs),
1581 0, 0, 0, // Reserved alignment padding 1595 0, 0, 0, // Reserved alignment padding
1582 utf8TextClone, 1596 utf8TextClone,
1583 utf8TextLength, 1597 utf8TextLength,
1584 utf8TextAccess, 1598 utf8TextAccess,
1585 utf8TextExtract, 1599 utf8TextExtract,
1586 NULL, /* replace*/ 1600 NULL, /* replace*/
1587 NULL, /* copy */ 1601 NULL, /* copy */
1588 utf8TextMapOffsetToNative, 1602 utf8TextMapOffsetToNative,
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after
1855 limit32--; 1869 limit32--;
1856 } 1870 }
1857 1871
1858 length=limit32-start32; 1872 length=limit32-start32;
1859 if(length>destCapacity) { 1873 if(length>destCapacity) {
1860 limit32 = start32 + destCapacity; 1874 limit32 = start32 + destCapacity;
1861 } 1875 }
1862 UnicodeString buffer(dest, 0, destCapacity); // writable alias 1876 UnicodeString buffer(dest, 0, destCapacity); // writable alias
1863 rep->extractBetween(start32, limit32, buffer); 1877 rep->extractBetween(start32, limit32, buffer);
1864 repTextAccess(ut, limit32, TRUE); 1878 repTextAccess(ut, limit32, TRUE);
1865 1879
1866 return u_terminateUChars(dest, destCapacity, length, status); 1880 return u_terminateUChars(dest, destCapacity, length, status);
1867 } 1881 }
1868 1882
1869 static int32_t U_CALLCONV 1883 static int32_t U_CALLCONV
1870 repTextReplace(UText *ut, 1884 repTextReplace(UText *ut,
1871 int64_t start, int64_t limit, 1885 int64_t start, int64_t limit,
1872 const UChar *src, int32_t length, 1886 const UChar *src, int32_t length,
1873 UErrorCode *status) { 1887 UErrorCode *status) {
1874 Replaceable *rep=(Replaceable *)ut->context; 1888 Replaceable *rep=(Replaceable *)ut->context;
1875 int32_t oldLength; 1889 int32_t oldLength;
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
1977 int32_t nativeIterIndex = destIndex32 + limit32 - start32; 1991 int32_t nativeIterIndex = destIndex32 + limit32 - start32;
1978 if (move && destIndex32>start32) { 1992 if (move && destIndex32>start32) {
1979 // moved a block of text towards the end of the string. 1993 // moved a block of text towards the end of the string.
1980 nativeIterIndex = destIndex32; 1994 nativeIterIndex = destIndex32;
1981 } 1995 }
1982 1996
1983 // Set position, reload chunk if needed. 1997 // Set position, reload chunk if needed.
1984 repTextAccess(ut, nativeIterIndex, TRUE); 1998 repTextAccess(ut, nativeIterIndex, TRUE);
1985 } 1999 }
1986 2000
1987 static const struct UTextFuncs repFuncs = 2001 static const struct UTextFuncs repFuncs =
1988 { 2002 {
1989 sizeof(UTextFuncs), 2003 sizeof(UTextFuncs),
1990 0, 0, 0, // Reserved alignment padding 2004 0, 0, 0, // Reserved alignment padding
1991 repTextClone, 2005 repTextClone,
1992 repTextLength, 2006 repTextLength,
1993 repTextAccess, 2007 repTextAccess,
1994 repTextExtract, 2008 repTextExtract,
1995 repTextReplace, 2009 repTextReplace,
1996 repTextCopy, 2010 repTextCopy,
1997 NULL, // MapOffsetToNative, 2011 NULL, // MapOffsetToNative,
1998 NULL, // MapIndexToUTF16, 2012 NULL, // MapIndexToUTF16,
1999 repTextClose, 2013 repTextClose,
2000 NULL, // spare 1 2014 NULL, // spare 1
2001 NULL, // spare 2 2015 NULL, // spare 2
2002 NULL // spare 3 2016 NULL // spare 3
2003 }; 2017 };
2004 2018
2005 2019
2006 U_CAPI UText * U_EXPORT2 2020 U_CAPI UText * U_EXPORT2
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after
2228 } 2242 }
2229 2243
2230 // Iteration position to end of the newly inserted text. 2244 // Iteration position to end of the newly inserted text.
2231 ut->chunkOffset = destIndex32+limit32-start32; 2245 ut->chunkOffset = destIndex32+limit32-start32;
2232 if (move && destIndex32>start32) { 2246 if (move && destIndex32>start32) {
2233 ut->chunkOffset = destIndex32; 2247 ut->chunkOffset = destIndex32;
2234 } 2248 }
2235 2249
2236 } 2250 }
2237 2251
2238 static const struct UTextFuncs unistrFuncs = 2252 static const struct UTextFuncs unistrFuncs =
2239 { 2253 {
2240 sizeof(UTextFuncs), 2254 sizeof(UTextFuncs),
2241 0, 0, 0, // Reserved alignment padding 2255 0, 0, 0, // Reserved alignment padding
2242 unistrTextClone, 2256 unistrTextClone,
2243 unistrTextLength, 2257 unistrTextLength,
2244 unistrTextAccess, 2258 unistrTextAccess,
2245 unistrTextExtract, 2259 unistrTextExtract,
2246 unistrTextReplace, 2260 unistrTextReplace,
2247 unistrTextCopy, 2261 unistrTextCopy,
2248 NULL, // MapOffsetToNative, 2262 NULL, // MapOffsetToNative,
2249 NULL, // MapIndexToUTF16, 2263 NULL, // MapIndexToUTF16,
2250 unistrTextClose, 2264 unistrTextClose,
2251 NULL, // spare 1 2265 NULL, // spare 1
2252 NULL, // spare 2 2266 NULL, // spare 2
2253 NULL // spare 3 2267 NULL // spare 3
2254 }; 2268 };
2255 2269
2256 2270
2257 2271
(...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after
2541 2555
2542 // Put iteration position at the point just following the extracted text 2556 // Put iteration position at the point just following the extracted text
2543 ut->chunkOffset = uprv_min(strLength, start32 + destCapacity); 2557 ut->chunkOffset = uprv_min(strLength, start32 + destCapacity);
2544 2558
2545 // Add a terminating NUL if space in the buffer permits, 2559 // Add a terminating NUL if space in the buffer permits,
2546 // and set the error status as required. 2560 // and set the error status as required.
2547 u_terminateUChars(dest, destCapacity, di, pErrorCode); 2561 u_terminateUChars(dest, destCapacity, di, pErrorCode);
2548 return di; 2562 return di;
2549 } 2563 }
2550 2564
2551 static const struct UTextFuncs ucstrFuncs = 2565 static const struct UTextFuncs ucstrFuncs =
2552 { 2566 {
2553 sizeof(UTextFuncs), 2567 sizeof(UTextFuncs),
2554 0, 0, 0, // Reserved alignment padding 2568 0, 0, 0, // Reserved alignment padding
2555 ucstrTextClone, 2569 ucstrTextClone,
2556 ucstrTextLength, 2570 ucstrTextLength,
2557 ucstrTextAccess, 2571 ucstrTextAccess,
2558 ucstrTextExtract, 2572 ucstrTextExtract,
2559 NULL, // Replace 2573 NULL, // Replace
2560 NULL, // Copy 2574 NULL, // Copy
2561 NULL, // MapOffsetToNative, 2575 NULL, // MapOffsetToNative,
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
2758 U_ASSERT(desti+len>0); /* to ensure desti+len never exceeds MAX_INT32, w hich must not happen logically */ 2772 U_ASSERT(desti+len>0); /* to ensure desti+len never exceeds MAX_INT32, w hich must not happen logically */
2759 if (desti+len <= destCapacity) { 2773 if (desti+len <= destCapacity) {
2760 U16_APPEND_UNSAFE(dest, desti, c); 2774 U16_APPEND_UNSAFE(dest, desti, c);
2761 copyLimit = srci+len; 2775 copyLimit = srci+len;
2762 } else { 2776 } else {
2763 desti += len; 2777 desti += len;
2764 *status = U_BUFFER_OVERFLOW_ERROR; 2778 *status = U_BUFFER_OVERFLOW_ERROR;
2765 } 2779 }
2766 srci += len; 2780 srci += len;
2767 } 2781 }
2768 2782
2769 charIterTextAccess(ut, copyLimit, TRUE); 2783 charIterTextAccess(ut, copyLimit, TRUE);
2770 2784
2771 u_terminateUChars(dest, destCapacity, desti, status); 2785 u_terminateUChars(dest, destCapacity, desti, status);
2772 return desti; 2786 return desti;
2773 } 2787 }
2774 2788
2775 static const struct UTextFuncs charIterFuncs = 2789 static const struct UTextFuncs charIterFuncs =
2776 { 2790 {
2777 sizeof(UTextFuncs), 2791 sizeof(UTextFuncs),
2778 0, 0, 0, // Reserved alignment padding 2792 0, 0, 0, // Reserved alignment padding
2779 charIterTextClone, 2793 charIterTextClone,
2780 charIterTextLength, 2794 charIterTextLength,
2781 charIterTextAccess, 2795 charIterTextAccess,
2782 charIterTextExtract, 2796 charIterTextExtract,
2783 NULL, // Replace 2797 NULL, // Replace
2784 NULL, // Copy 2798 NULL, // Copy
2785 NULL, // MapOffsetToNative, 2799 NULL, // MapOffsetToNative,
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
2825 // zero without Access() thinking that the chunk is valid. 2839 // zero without Access() thinking that the chunk is valid.
2826 ut->chunkContents = (UChar *)ut->p; 2840 ut->chunkContents = (UChar *)ut->p;
2827 ut->chunkNativeStart = -1; 2841 ut->chunkNativeStart = -1;
2828 ut->chunkOffset = 1; 2842 ut->chunkOffset = 1;
2829 ut->chunkNativeLimit = 0; 2843 ut->chunkNativeLimit = 0;
2830 ut->chunkLength = 0; 2844 ut->chunkLength = 0;
2831 ut->nativeIndexingLimit = ut->chunkOffset; // enables native indexing 2845 ut->nativeIndexingLimit = ut->chunkOffset; // enables native indexing
2832 } 2846 }
2833 return ut; 2847 return ut;
2834 } 2848 }
2835
2836
2837
OLDNEW
« no previous file with comments | « source/common/ustrtrns.cpp ('k') | source/common/utrace.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698