File: | home/maarten/src/libreoffice/core/sal/rtl/string.cxx |
Warning: | line 234, column 30 Dereference of null pointer (loaded from variable 'pBuffer') |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
1 | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ | |||
2 | /* | |||
3 | * This file is part of the LibreOffice project. | |||
4 | * | |||
5 | * This Source Code Form is subject to the terms of the Mozilla Public | |||
6 | * License, v. 2.0. If a copy of the MPL was not distributed with this | |||
7 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. | |||
8 | * | |||
9 | * This file incorporates work covered by the following license notice: | |||
10 | * | |||
11 | * Licensed to the Apache Software Foundation (ASF) under one or more | |||
12 | * contributor license agreements. See the NOTICE file distributed | |||
13 | * with this work for additional information regarding copyright | |||
14 | * ownership. The ASF licenses this file to you under the Apache | |||
15 | * License, Version 2.0 (the "License"); you may not use this file | |||
16 | * except in compliance with the License. You may obtain a copy of | |||
17 | * the License at http://www.apache.org/licenses/LICENSE-2.0 . | |||
18 | */ | |||
19 | ||||
20 | #include <sal/config.h> | |||
21 | ||||
22 | #include <cassert> | |||
23 | #include <cstdlib> | |||
24 | ||||
25 | #include <osl/interlck.h> | |||
26 | #include <rtl/alloc.h> | |||
27 | #include <osl/diagnose.h> | |||
28 | #include <rtl/tencinfo.h> | |||
29 | ||||
30 | #include "strimp.hxx" | |||
31 | #include <rtl/character.hxx> | |||
32 | #include <rtl/string.h> | |||
33 | ||||
34 | #include <rtl/math.h> | |||
35 | ||||
36 | /* ======================================================================= */ | |||
37 | ||||
38 | /* static data to be referenced by all empty strings | |||
39 | * the refCount is predefined to 1 and must never become 0 ! | |||
40 | */ | |||
41 | rtl_String const aImplEmpty_rtl_String = | |||
42 | { | |||
43 | SAL_STRING_STATIC_FLAG0x40000000|1, | |||
44 | /* sal_Int32 refCount; */ | |||
45 | 0, /* sal_Int32 length; */ | |||
46 | { 0 } /* char buffer[1]; */ | |||
47 | }; | |||
48 | ||||
49 | /* ======================================================================= */ | |||
50 | /* These macros are for the "poor-man templates" included from | |||
51 | * the strtmpl.cxx just below, used to share code between here and | |||
52 | * ustring.cxx | |||
53 | */ | |||
54 | ||||
55 | #define IMPL_RTL_IS_USTRING 0 | |||
56 | ||||
57 | #define IMPL_RTL_STRCODE char | |||
58 | #define IMPL_RTL_USTRCODE( c ) (static_cast<unsigned char>(c)) | |||
59 | #define IMPL_RTL_STRNAME( n ) rtl_str_ ## n | |||
60 | ||||
61 | #define IMPL_RTL_STRINGNAME( n ) rtl_string_ ## n | |||
62 | #define IMPL_RTL_STRINGDATA rtl_String | |||
63 | #define IMPL_RTL_EMPTYSTRING aImplEmpty_rtl_String | |||
64 | ||||
65 | #if USE_SDT_PROBES1 | |||
66 | #define RTL_LOG_STRING_BITS 8 | |||
67 | #endif | |||
68 | ||||
69 | /* ======================================================================= */ | |||
70 | ||||
71 | /* Include String/UString template code */ | |||
72 | ||||
73 | #include "strtmpl.cxx" | |||
74 | ||||
75 | #undef IMPL_RTL_EMPTYSTRING | |||
76 | #undef IMPL_RTL_IS_USTRING | |||
77 | #undef IMPL_RTL_STRCODE | |||
78 | #undef IMPL_RTL_STRINGDATA | |||
79 | #undef IMPL_RTL_STRINGNAME | |||
80 | #undef IMPL_RTL_STRNAME | |||
81 | #undef IMPL_RTL_USTRCODE | |||
82 | #undef RTL_LOG_STRING_BITS | |||
83 | ||||
84 | sal_Int32 SAL_CALL rtl_str_valueOfFloat(char * pStr, float f) | |||
85 | SAL_THROW_EXTERN_C()throw () | |||
86 | { | |||
87 | assert(pStr)(static_cast <bool> (pStr) ? void (0) : __assert_fail ( "pStr", "/home/maarten/src/libreoffice/core/sal/rtl/string.cxx" , 87, __extension__ __PRETTY_FUNCTION__)); | |||
88 | rtl_String * pResult = nullptr; | |||
89 | sal_Int32 nLen; | |||
90 | rtl_math_doubleToString( | |||
91 | &pResult, nullptr, 0, f, rtl_math_StringFormat_G, | |||
92 | RTL_STR_MAX_VALUEOFFLOAT15 - RTL_CONSTASCII_LENGTH("-x.E-xxx")((sal_Int32)((sizeof(sal_n_array_size("-x.E-xxx")))-1)), '.', nullptr, 0, | |||
93 | true); | |||
94 | nLen = pResult->length; | |||
95 | OSL_ASSERT(nLen < RTL_STR_MAX_VALUEOFFLOAT)do { if (true && (!(nLen < 15))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/sal/rtl/string.cxx" ":" "95" ": "), "OSL_ASSERT: %s", "nLen < RTL_STR_MAX_VALUEOFFLOAT" ); } } while (false); | |||
96 | memcpy(pStr, pResult->buffer, (nLen + 1) * sizeof(char)); | |||
97 | rtl_string_release(pResult); | |||
98 | return nLen; | |||
99 | } | |||
100 | ||||
101 | sal_Int32 SAL_CALL rtl_str_valueOfDouble(char * pStr, double d) | |||
102 | SAL_THROW_EXTERN_C()throw () | |||
103 | { | |||
104 | assert(pStr)(static_cast <bool> (pStr) ? void (0) : __assert_fail ( "pStr", "/home/maarten/src/libreoffice/core/sal/rtl/string.cxx" , 104, __extension__ __PRETTY_FUNCTION__)); | |||
105 | rtl_String * pResult = nullptr; | |||
106 | sal_Int32 nLen; | |||
107 | rtl_math_doubleToString( | |||
108 | &pResult, nullptr, 0, d, rtl_math_StringFormat_G, | |||
109 | RTL_STR_MAX_VALUEOFDOUBLE25 - RTL_CONSTASCII_LENGTH("-x.E-xxx")((sal_Int32)((sizeof(sal_n_array_size("-x.E-xxx")))-1)), '.', nullptr, | |||
110 | 0, true); | |||
111 | nLen = pResult->length; | |||
112 | OSL_ASSERT(nLen < RTL_STR_MAX_VALUEOFDOUBLE)do { if (true && (!(nLen < 25))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/sal/rtl/string.cxx" ":" "112" ": "), "OSL_ASSERT: %s", "nLen < RTL_STR_MAX_VALUEOFDOUBLE" ); } } while (false); | |||
113 | memcpy(pStr, pResult->buffer, (nLen + 1) * sizeof(char)); | |||
114 | rtl_string_release(pResult); | |||
115 | return nLen; | |||
116 | } | |||
117 | ||||
118 | float SAL_CALL rtl_str_toFloat(char const * pStr) SAL_THROW_EXTERN_C()throw () | |||
119 | { | |||
120 | assert(pStr)(static_cast <bool> (pStr) ? void (0) : __assert_fail ( "pStr", "/home/maarten/src/libreoffice/core/sal/rtl/string.cxx" , 120, __extension__ __PRETTY_FUNCTION__)); | |||
121 | return static_cast<float>(rtl_math_stringToDouble(pStr, pStr + rtl_str_getLength(pStr), | |||
122 | '.', 0, nullptr, nullptr)); | |||
123 | } | |||
124 | ||||
125 | double SAL_CALL rtl_str_toDouble(char const * pStr) SAL_THROW_EXTERN_C()throw () | |||
126 | { | |||
127 | assert(pStr)(static_cast <bool> (pStr) ? void (0) : __assert_fail ( "pStr", "/home/maarten/src/libreoffice/core/sal/rtl/string.cxx" , 127, __extension__ __PRETTY_FUNCTION__)); | |||
128 | return rtl_math_stringToDouble(pStr, pStr + rtl_str_getLength(pStr), '.', 0, | |||
129 | nullptr, nullptr); | |||
130 | } | |||
131 | ||||
132 | /* ======================================================================= */ | |||
133 | ||||
134 | static int rtl_ImplGetFastUTF8ByteLen( const sal_Unicode* pStr, sal_Int32 nLen ) | |||
135 | { | |||
136 | int n; | |||
137 | sal_Unicode c; | |||
138 | sal_uInt32 nUCS4Char; | |||
139 | const sal_Unicode* pEndStr; | |||
140 | ||||
141 | n = 0; | |||
142 | pEndStr = pStr+nLen; | |||
143 | while ( pStr < pEndStr ) | |||
144 | { | |||
145 | c = *pStr; | |||
146 | ||||
147 | if ( c < 0x80 ) | |||
148 | n++; | |||
149 | else if ( c < 0x800 ) | |||
150 | n += 2; | |||
151 | else | |||
152 | { | |||
153 | if ( !rtl::isHighSurrogate(c) ) | |||
154 | n += 3; | |||
155 | else | |||
156 | { | |||
157 | nUCS4Char = c; | |||
158 | ||||
159 | if ( pStr+1 < pEndStr ) | |||
160 | { | |||
161 | c = *(pStr+1); | |||
162 | if ( rtl::isLowSurrogate(c) ) | |||
163 | { | |||
164 | nUCS4Char = rtl::combineSurrogates(nUCS4Char, c); | |||
165 | pStr++; | |||
166 | } | |||
167 | } | |||
168 | ||||
169 | if ( nUCS4Char < 0x10000 ) | |||
170 | n += 3; | |||
171 | else if ( nUCS4Char < 0x200000 ) | |||
172 | n += 4; | |||
173 | else if ( nUCS4Char < 0x4000000 ) | |||
174 | n += 5; | |||
175 | else | |||
176 | n += 6; | |||
177 | } | |||
178 | } | |||
179 | ||||
180 | pStr++; | |||
181 | } | |||
182 | ||||
183 | return n; | |||
184 | } | |||
185 | ||||
186 | /* ----------------------------------------------------------------------- */ | |||
187 | ||||
188 | static bool rtl_impl_convertUStringToString(rtl_String ** pTarget, | |||
189 | sal_Unicode const * pSource, | |||
190 | sal_Int32 nLength, | |||
191 | rtl_TextEncoding nEncoding, | |||
192 | sal_uInt32 nFlags, | |||
193 | bool bCheckErrors) | |||
194 | { | |||
195 | assert(pTarget != nullptr)(static_cast <bool> (pTarget != nullptr) ? void (0) : __assert_fail ("pTarget != nullptr", "/home/maarten/src/libreoffice/core/sal/rtl/string.cxx" , 195, __extension__ __PRETTY_FUNCTION__)); | |||
196 | assert(pSource != nullptr || nLength == 0)(static_cast <bool> (pSource != nullptr || nLength == 0 ) ? void (0) : __assert_fail ("pSource != nullptr || nLength == 0" , "/home/maarten/src/libreoffice/core/sal/rtl/string.cxx", 196 , __extension__ __PRETTY_FUNCTION__)); | |||
197 | assert(nLength >= 0)(static_cast <bool> (nLength >= 0) ? void (0) : __assert_fail ("nLength >= 0", "/home/maarten/src/libreoffice/core/sal/rtl/string.cxx" , 197, __extension__ __PRETTY_FUNCTION__)); | |||
198 | OSL_ASSERT(nLength == 0 || rtl_isOctetTextEncoding(nEncoding))do { if (true && (!(nLength == 0 || rtl_isOctetTextEncoding (nEncoding)))) { sal_detail_logFormat((SAL_DETAIL_LOG_LEVEL_WARN ), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/sal/rtl/string.cxx" ":" "198" ": "), "OSL_ASSERT: %s", "nLength == 0 || rtl_isOctetTextEncoding(nEncoding)" ); } } while (false); | |||
199 | ||||
200 | if ( !nLength
| |||
201 | rtl_string_new( pTarget ); | |||
202 | else | |||
203 | { | |||
204 | rtl_String* pTemp; | |||
205 | rtl_UnicodeToTextConverter hConverter; | |||
206 | sal_uInt32 nInfo; | |||
207 | sal_Size nSrcChars; | |||
208 | sal_Size nDestBytes; | |||
209 | sal_Size nNewLen; | |||
210 | sal_Size nNotConvertedChars; | |||
211 | sal_Size nMaxCharLen; | |||
212 | ||||
213 | /* Optimization for UTF-8 - we try to calculate the exact length */ | |||
214 | /* For all other encoding we try a good estimation */ | |||
215 | if ( nEncoding == RTL_TEXTENCODING_UTF8(((rtl_TextEncoding) 76)) ) | |||
216 | { | |||
217 | nNewLen = rtl_ImplGetFastUTF8ByteLen( pSource, nLength ); | |||
218 | /* Includes the string only ASCII, then we could copy | |||
219 | the buffer faster */ | |||
220 | if ( nNewLen == static_cast<sal_Size>(nLength) ) | |||
221 | { | |||
222 | char* pBuffer; | |||
223 | if ( *pTarget ) | |||
224 | rtl_string_release( *pTarget ); | |||
225 | *pTarget = rtl_string_ImplAlloc( nLength ); | |||
226 | OSL_ASSERT(*pTarget != nullptr)do { if (true && (!(*pTarget != nullptr))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/sal/rtl/string.cxx" ":" "226" ": "), "OSL_ASSERT: %s", "*pTarget != nullptr"); } } while (false); | |||
227 | pBuffer = (*pTarget)->buffer; | |||
228 | do | |||
229 | { | |||
230 | /* Check ASCII range */ | |||
231 | OSL_ENSURE( *pSource <= 127,do { if (true && (!(*pSource <= 127))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/sal/rtl/string.cxx" ":" "232" ": "), "%s", "rtl_uString2String() - UTF8 test is encoding is wrong" ); } } while (false) | |||
232 | "rtl_uString2String() - UTF8 test is encoding is wrong" )do { if (true && (!(*pSource <= 127))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/sal/rtl/string.cxx" ":" "232" ": "), "%s", "rtl_uString2String() - UTF8 test is encoding is wrong" ); } } while (false); | |||
233 | ||||
234 | *pBuffer = static_cast<char>(static_cast<unsigned char>(*pSource)); | |||
| ||||
235 | pBuffer++; | |||
236 | pSource++; | |||
237 | nLength--; | |||
238 | } | |||
239 | while ( nLength ); | |||
240 | return true; | |||
241 | } | |||
242 | ||||
243 | nMaxCharLen = 4; | |||
244 | } | |||
245 | else | |||
246 | { | |||
247 | rtl_TextEncodingInfo aTextEncInfo; | |||
248 | aTextEncInfo.StructSize = sizeof( aTextEncInfo ); | |||
249 | if ( !rtl_getTextEncodingInfo( nEncoding, &aTextEncInfo ) ) | |||
250 | { | |||
251 | aTextEncInfo.AverageCharSize = 1; | |||
252 | aTextEncInfo.MaximumCharSize = 8; | |||
253 | } | |||
254 | ||||
255 | nNewLen = nLength * static_cast<sal_Size>(aTextEncInfo.AverageCharSize); | |||
256 | nMaxCharLen = aTextEncInfo.MaximumCharSize; | |||
257 | } | |||
258 | ||||
259 | nFlags |= RTL_UNICODETOTEXT_FLAGS_FLUSH((sal_uInt32)0x8000); | |||
260 | hConverter = rtl_createUnicodeToTextConverter( nEncoding ); | |||
261 | ||||
262 | for (;;) | |||
263 | { | |||
264 | pTemp = rtl_string_ImplAlloc( nNewLen ); | |||
265 | OSL_ASSERT(pTemp != nullptr)do { if (true && (!(pTemp != nullptr))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/sal/rtl/string.cxx" ":" "265" ": "), "OSL_ASSERT: %s", "pTemp != nullptr"); } } while (false); | |||
266 | nDestBytes = rtl_convertUnicodeToText( hConverter, nullptr, | |||
267 | pSource, nLength, | |||
268 | pTemp->buffer, nNewLen, | |||
269 | nFlags, | |||
270 | &nInfo, &nSrcChars ); | |||
271 | if (bCheckErrors && (nInfo & RTL_UNICODETOTEXT_INFO_ERROR((sal_uInt32)0x0001)) != 0) | |||
272 | { | |||
273 | rtl_freeString(pTemp); | |||
274 | rtl_destroyUnicodeToTextConverter(hConverter); | |||
275 | return false; | |||
276 | } | |||
277 | ||||
278 | if ((nInfo & RTL_UNICODETOTEXT_INFO_DESTBUFFERTOSMALL((sal_uInt32)0x0004)) == 0) | |||
279 | break; | |||
280 | ||||
281 | /* Buffer not big enough, try again with enough space */ | |||
282 | rtl_freeString( pTemp ); | |||
283 | ||||
284 | /* Try with the max. count of characters with | |||
285 | additional overhead for replacing functionality */ | |||
286 | nNotConvertedChars = nLength-nSrcChars; | |||
287 | nNewLen = nDestBytes+(nNotConvertedChars*nMaxCharLen)+nNotConvertedChars+4; | |||
288 | } | |||
289 | ||||
290 | /* Set the buffer to the correct size or is there to | |||
291 | much overhead, reallocate to the correct size */ | |||
292 | if ( nNewLen > nDestBytes+8 ) | |||
293 | { | |||
294 | rtl_String* pTemp2 = rtl_string_ImplAlloc( nDestBytes ); | |||
295 | OSL_ASSERT(pTemp2 != nullptr)do { if (true && (!(pTemp2 != nullptr))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/sal/rtl/string.cxx" ":" "295" ": "), "OSL_ASSERT: %s", "pTemp2 != nullptr"); } } while (false); | |||
296 | rtl_str_ImplCopy( pTemp2->buffer, pTemp->buffer, nDestBytes ); | |||
297 | rtl_freeString( pTemp ); | |||
298 | pTemp = pTemp2; | |||
299 | } | |||
300 | else | |||
301 | { | |||
302 | pTemp->length = nDestBytes; | |||
303 | pTemp->buffer[nDestBytes] = 0; | |||
304 | } | |||
305 | ||||
306 | rtl_destroyUnicodeToTextConverter( hConverter ); | |||
307 | if ( *pTarget ) | |||
308 | rtl_string_release( *pTarget ); | |||
309 | *pTarget = pTemp; | |||
310 | ||||
311 | /* Results the conversion in an empty buffer - | |||
312 | create an empty string */ | |||
313 | if ( pTemp && !nDestBytes ) | |||
314 | rtl_string_new( pTarget ); | |||
315 | } | |||
316 | return true; | |||
317 | } | |||
318 | ||||
319 | void SAL_CALL rtl_uString2String( rtl_String** ppThis, | |||
320 | const sal_Unicode* pUStr, | |||
321 | sal_Int32 nULen, | |||
322 | rtl_TextEncoding eTextEncoding, | |||
323 | sal_uInt32 nCvtFlags ) | |||
324 | SAL_THROW_EXTERN_C()throw () | |||
325 | { | |||
326 | rtl_impl_convertUStringToString(ppThis, pUStr, nULen, eTextEncoding, | |||
327 | nCvtFlags, false); | |||
328 | } | |||
329 | ||||
330 | sal_Bool SAL_CALL rtl_convertUStringToString(rtl_String ** pTarget, | |||
331 | sal_Unicode const * pSource, | |||
332 | sal_Int32 nLength, | |||
333 | rtl_TextEncoding nEncoding, | |||
334 | sal_uInt32 nFlags) | |||
335 | SAL_THROW_EXTERN_C()throw () | |||
336 | { | |||
337 | return rtl_impl_convertUStringToString(pTarget, pSource, nLength, nEncoding, | |||
| ||||
338 | nFlags, true); | |||
339 | } | |||
340 | ||||
341 | void rtl_string_newReplaceFirst( | |||
342 | rtl_String ** newStr, rtl_String * str, char const * from, | |||
343 | sal_Int32 fromLength, char const * to, sal_Int32 toLength, | |||
344 | sal_Int32 * index) SAL_THROW_EXTERN_C()throw () | |||
345 | { | |||
346 | assert(str != nullptr)(static_cast <bool> (str != nullptr) ? void (0) : __assert_fail ("str != nullptr", "/home/maarten/src/libreoffice/core/sal/rtl/string.cxx" , 346, __extension__ __PRETTY_FUNCTION__)); | |||
347 | assert(index != nullptr)(static_cast <bool> (index != nullptr) ? void (0) : __assert_fail ("index != nullptr", "/home/maarten/src/libreoffice/core/sal/rtl/string.cxx" , 347, __extension__ __PRETTY_FUNCTION__)); | |||
348 | assert(*index >= 0 && *index <= str->length)(static_cast <bool> (*index >= 0 && *index <= str->length) ? void (0) : __assert_fail ("*index >= 0 && *index <= str->length" , "/home/maarten/src/libreoffice/core/sal/rtl/string.cxx", 348 , __extension__ __PRETTY_FUNCTION__)); | |||
349 | assert(fromLength >= 0)(static_cast <bool> (fromLength >= 0) ? void (0) : __assert_fail ("fromLength >= 0", "/home/maarten/src/libreoffice/core/sal/rtl/string.cxx" , 349, __extension__ __PRETTY_FUNCTION__)); | |||
350 | assert(toLength >= 0)(static_cast <bool> (toLength >= 0) ? void (0) : __assert_fail ("toLength >= 0", "/home/maarten/src/libreoffice/core/sal/rtl/string.cxx" , 350, __extension__ __PRETTY_FUNCTION__)); | |||
351 | sal_Int32 i = rtl_str_indexOfStr_WithLength( | |||
352 | str->buffer + *index, str->length - *index, from, fromLength); | |||
353 | if (i == -1) { | |||
354 | rtl_string_assign(newStr, str); | |||
355 | } else { | |||
356 | assert(i <= str->length - *index)(static_cast <bool> (i <= str->length - *index) ? void (0) : __assert_fail ("i <= str->length - *index", "/home/maarten/src/libreoffice/core/sal/rtl/string.cxx", 356 , __extension__ __PRETTY_FUNCTION__)); | |||
357 | i += *index; | |||
358 | assert(fromLength <= str->length)(static_cast <bool> (fromLength <= str->length) ? void (0) : __assert_fail ("fromLength <= str->length", "/home/maarten/src/libreoffice/core/sal/rtl/string.cxx", 358 , __extension__ __PRETTY_FUNCTION__)); | |||
359 | if (str->length - fromLength > SAL_MAX_INT32((sal_Int32) 0x7FFFFFFF) - toLength) { | |||
360 | std::abort(); | |||
361 | } | |||
362 | sal_Int32 n = str->length - fromLength + toLength; | |||
363 | rtl_string_acquire(str); // in case *newStr == str | |||
364 | rtl_string_new_WithLength(newStr, n); | |||
365 | if (n != 0) { | |||
366 | (*newStr)->length = n; | |||
367 | assert(i >= 0 && i < str->length)(static_cast <bool> (i >= 0 && i < str-> length) ? void (0) : __assert_fail ("i >= 0 && i < str->length" , "/home/maarten/src/libreoffice/core/sal/rtl/string.cxx", 367 , __extension__ __PRETTY_FUNCTION__)); | |||
368 | memcpy((*newStr)->buffer, str->buffer, i); | |||
369 | memcpy((*newStr)->buffer + i, to, toLength); | |||
370 | memcpy( | |||
371 | (*newStr)->buffer + i + toLength, str->buffer + i + fromLength, | |||
372 | str->length - i - fromLength); | |||
373 | } | |||
374 | rtl_string_release(str); | |||
375 | } | |||
376 | *index = i; | |||
377 | } | |||
378 | ||||
379 | void rtl_string_newReplaceAll( | |||
380 | rtl_String ** newStr, rtl_String * str, char const * from, | |||
381 | sal_Int32 fromLength, char const * to, sal_Int32 toLength) | |||
382 | SAL_THROW_EXTERN_C()throw () | |||
383 | { | |||
384 | rtl_string_assign(newStr, str); | |||
385 | for (sal_Int32 i = 0;; i += toLength) { | |||
386 | rtl_string_newReplaceFirst( | |||
387 | newStr, *newStr, from, fromLength, to, toLength, &i); | |||
388 | if (i == -1) { | |||
389 | break; | |||
390 | } | |||
391 | } | |||
392 | } | |||
393 | ||||
394 | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |