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

Side by Side Diff: source/common/charstr.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/charstr.h ('k') | source/common/cmemory.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 * Copyright (C) 2010-2011, International Business Machines 3 * Copyright (C) 2010-2015, International Business Machines
4 * Corporation and others. All Rights Reserved. 4 * Corporation and others. All Rights Reserved.
5 ******************************************************************************* 5 *******************************************************************************
6 * file name: charstr.cpp 6 * file name: charstr.cpp
7 * encoding: US-ASCII 7 * encoding: US-ASCII
8 * tab size: 8 (not used) 8 * tab size: 8 (not used)
9 * indentation:4 9 * indentation:4
10 * 10 *
11 * created on: 2010may19 11 * created on: 2010may19
12 * created by: Markus W. Scherer 12 * created by: Markus W. Scherer
13 */ 13 */
14 14
15 #include "unicode/utypes.h" 15 #include "unicode/utypes.h"
16 #include "charstr.h" 16 #include "charstr.h"
17 #include "cmemory.h" 17 #include "cmemory.h"
18 #include "cstring.h" 18 #include "cstring.h"
19 #include "uinvchar.h"
19 20
20 U_NAMESPACE_BEGIN 21 U_NAMESPACE_BEGIN
21 22
22 CharString &CharString::copyFrom(const CharString &s, UErrorCode &errorCode) { 23 CharString &CharString::copyFrom(const CharString &s, UErrorCode &errorCode) {
23 if(U_SUCCESS(errorCode) && this!=&s && ensureCapacity(s.len+1, 0, errorCode) ) { 24 if(U_SUCCESS(errorCode) && this!=&s && ensureCapacity(s.len+1, 0, errorCode) ) {
24 len=s.len; 25 len=s.len;
25 uprv_memcpy(buffer.getAlias(), s.buffer.getAlias(), len+1); 26 uprv_memcpy(buffer.getAlias(), s.buffer.getAlias(), len+1);
26 } 27 }
27 return *this; 28 return *this;
28 } 29 }
29 30
31 int32_t CharString::lastIndexOf(char c) const {
32 for(int32_t i=len; i>0;) {
33 if(buffer[--i]==c) {
34 return i;
35 }
36 }
37 return -1;
38 }
39
30 CharString &CharString::truncate(int32_t newLength) { 40 CharString &CharString::truncate(int32_t newLength) {
31 if(newLength<0) { 41 if(newLength<0) {
32 newLength=0; 42 newLength=0;
33 } 43 }
34 if(newLength<len) { 44 if(newLength<len) {
35 buffer[len=newLength]=0; 45 buffer[len=newLength]=0;
36 } 46 }
37 return *this; 47 return *this;
38 } 48 }
39 49
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 } 104 }
95 if(ensureCapacity(len+minCapacity+1, len+desiredCapacityHint+1, errorCode)) { 105 if(ensureCapacity(len+minCapacity+1, len+desiredCapacityHint+1, errorCode)) {
96 resultCapacity=buffer.getCapacity()-len-1; 106 resultCapacity=buffer.getCapacity()-len-1;
97 return buffer.getAlias()+len; 107 return buffer.getAlias()+len;
98 } 108 }
99 resultCapacity=0; 109 resultCapacity=0;
100 return NULL; 110 return NULL;
101 } 111 }
102 112
103 CharString &CharString::appendInvariantChars(const UnicodeString &s, UErrorCode &errorCode) { 113 CharString &CharString::appendInvariantChars(const UnicodeString &s, UErrorCode &errorCode) {
114 if(U_FAILURE(errorCode)) {
115 return *this;
116 }
117 if (!uprv_isInvariantUnicodeString(s)) {
118 errorCode = U_INVARIANT_CONVERSION_ERROR;
119 return *this;
120 }
104 if(ensureCapacity(len+s.length()+1, 0, errorCode)) { 121 if(ensureCapacity(len+s.length()+1, 0, errorCode)) {
105 len+=s.extract(0, 0x7fffffff, buffer.getAlias()+len, buffer.getCapacity( )-len, US_INV); 122 len+=s.extract(0, 0x7fffffff, buffer.getAlias()+len, buffer.getCapacity( )-len, US_INV);
106 } 123 }
107 return *this; 124 return *this;
108 } 125 }
109 126
110 UBool CharString::ensureCapacity(int32_t capacity, 127 UBool CharString::ensureCapacity(int32_t capacity,
111 int32_t desiredCapacityHint, 128 int32_t desiredCapacityHint,
112 UErrorCode &errorCode) { 129 UErrorCode &errorCode) {
113 if(U_FAILURE(errorCode)) { 130 if(U_FAILURE(errorCode)) {
(...skipping 21 matching lines...) Expand all
135 return *this; 152 return *this;
136 } 153 }
137 char c; 154 char c;
138 if(len>0 && (c=buffer[len-1])!=U_FILE_SEP_CHAR && c!=U_FILE_ALT_SEP_CHAR) { 155 if(len>0 && (c=buffer[len-1])!=U_FILE_SEP_CHAR && c!=U_FILE_ALT_SEP_CHAR) {
139 append(U_FILE_SEP_CHAR, errorCode); 156 append(U_FILE_SEP_CHAR, errorCode);
140 } 157 }
141 append(s, errorCode); 158 append(s, errorCode);
142 return *this; 159 return *this;
143 } 160 }
144 161
162 CharString &CharString::ensureEndsWithFileSeparator(UErrorCode &errorCode) {
163 char c;
164 if(U_SUCCESS(errorCode) && len>0 &&
165 (c=buffer[len-1])!=U_FILE_SEP_CHAR && c!=U_FILE_ALT_SEP_CHAR) {
166 append(U_FILE_SEP_CHAR, errorCode);
167 }
168 return *this;
169 }
170
145 U_NAMESPACE_END 171 U_NAMESPACE_END
OLDNEW
« no previous file with comments | « source/common/charstr.h ('k') | source/common/cmemory.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698