File: | home/maarten/src/libreoffice/core/sal/rtl/strtmpl.cxx |
Warning: | line 54, column 5 Null pointer passed to 1st parameter expecting 'nonnull' |
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
| ||||
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: */ |
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 | /* ======================================================================= */ | |||
21 | /* Internal C-String help functions which could be used without the */ | |||
22 | /* String-Class */ | |||
23 | /* ======================================================================= */ | |||
24 | ||||
25 | #include <algorithm> | |||
26 | #include <cassert> | |||
27 | #include <limits> | |||
28 | ||||
29 | #include <cstring> | |||
30 | #include <wchar.h> | |||
31 | #include <sal/log.hxx> | |||
32 | #include <rtl/character.hxx> | |||
33 | ||||
34 | /* | |||
35 | inline void rtl_str_ImplCopy( IMPL_RTL_STRCODE* pDest, | |||
36 | const IMPL_RTL_STRCODE* pSrc, | |||
37 | sal_Int32 nCount ) | |||
38 | { | |||
39 | while ( nCount > 0 ) | |||
40 | { | |||
41 | *pDest = *pSrc; | |||
42 | pDest++; | |||
43 | pSrc++; | |||
44 | nCount--; | |||
45 | } | |||
46 | } | |||
47 | */ | |||
48 | ||||
49 | static void rtl_str_ImplCopy( IMPL_RTL_STRCODE* _pDest, | |||
50 | const IMPL_RTL_STRCODE* _pSrc, | |||
51 | sal_Int32 _nCount ) | |||
52 | { | |||
53 | // take advantage of builtin optimisations | |||
54 | memcpy( _pDest, _pSrc, _nCount * sizeof(IMPL_RTL_STRCODE)); | |||
| ||||
55 | } | |||
56 | ||||
57 | /* ======================================================================= */ | |||
58 | /* C-String functions which could be used without the String-Class */ | |||
59 | /* ======================================================================= */ | |||
60 | ||||
61 | sal_Int32 SAL_CALL IMPL_RTL_STRNAME( getLength )( const IMPL_RTL_STRCODE* pStr ) | |||
62 | SAL_THROW_EXTERN_C()throw () | |||
63 | { | |||
64 | assert(pStr)(static_cast <bool> (pStr) ? void (0) : __assert_fail ( "pStr", "/home/maarten/src/libreoffice/core/sal/rtl/strtmpl.cxx" , 64, __extension__ __PRETTY_FUNCTION__)); | |||
65 | #if !IMPL_RTL_IS_USTRING | |||
66 | // take advantage of builtin optimisations | |||
67 | return strlen( pStr); | |||
68 | #else | |||
69 | if (sizeof(IMPL_RTL_STRCODE) == sizeof(wchar_t)) | |||
70 | { | |||
71 | // take advantage of builtin optimisations | |||
72 | return wcslen(reinterpret_cast<wchar_t const *>(pStr)); | |||
73 | } | |||
74 | else | |||
75 | { | |||
76 | const IMPL_RTL_STRCODE* pTempStr = pStr; | |||
77 | while( *pTempStr ) | |||
78 | pTempStr++; | |||
79 | return pTempStr-pStr; | |||
80 | } | |||
81 | #endif | |||
82 | } | |||
83 | ||||
84 | /* ----------------------------------------------------------------------- */ | |||
85 | ||||
86 | sal_Int32 SAL_CALL IMPL_RTL_STRNAME( compare )( const IMPL_RTL_STRCODE* pStr1, | |||
87 | const IMPL_RTL_STRCODE* pStr2 ) | |||
88 | SAL_THROW_EXTERN_C()throw () | |||
89 | { | |||
90 | assert(pStr1)(static_cast <bool> (pStr1) ? void (0) : __assert_fail ( "pStr1", "/home/maarten/src/libreoffice/core/sal/rtl/strtmpl.cxx" , 90, __extension__ __PRETTY_FUNCTION__)); | |||
91 | assert(pStr2)(static_cast <bool> (pStr2) ? void (0) : __assert_fail ( "pStr2", "/home/maarten/src/libreoffice/core/sal/rtl/strtmpl.cxx" , 91, __extension__ __PRETTY_FUNCTION__)); | |||
92 | #if !IMPL_RTL_IS_USTRING | |||
93 | // take advantage of builtin optimisations | |||
94 | return strcmp( pStr1, pStr2); | |||
95 | #else | |||
96 | if (sizeof(IMPL_RTL_STRCODE) == sizeof(wchar_t)) | |||
97 | { | |||
98 | // take advantage of builtin optimisations | |||
99 | return wcscmp(reinterpret_cast<wchar_t const *>(pStr1), reinterpret_cast<wchar_t const *>(pStr2)); | |||
100 | } | |||
101 | else | |||
102 | { | |||
103 | sal_Int32 nRet; | |||
104 | for (;;) | |||
105 | { | |||
106 | nRet = static_cast<sal_Int32>(IMPL_RTL_USTRCODE(*pStr1)) - | |||
107 | static_cast<sal_Int32>(IMPL_RTL_USTRCODE(*pStr2)); | |||
108 | if (!(nRet == 0 && *pStr2 )) | |||
109 | break; | |||
110 | pStr1++; | |||
111 | pStr2++; | |||
112 | } | |||
113 | ||||
114 | return nRet; | |||
115 | } | |||
116 | #endif | |||
117 | } | |||
118 | ||||
119 | /* ----------------------------------------------------------------------- */ | |||
120 | ||||
121 | sal_Int32 SAL_CALL IMPL_RTL_STRNAME( compare_WithLength )( const IMPL_RTL_STRCODE* pStr1, | |||
122 | sal_Int32 nStr1Len, | |||
123 | const IMPL_RTL_STRCODE* pStr2, | |||
124 | sal_Int32 nStr2Len ) | |||
125 | SAL_THROW_EXTERN_C()throw () | |||
126 | { | |||
127 | assert(nStr1Len >= 0)(static_cast <bool> (nStr1Len >= 0) ? void (0) : __assert_fail ("nStr1Len >= 0", "/home/maarten/src/libreoffice/core/sal/rtl/strtmpl.cxx" , 127, __extension__ __PRETTY_FUNCTION__)); | |||
128 | assert(nStr2Len >= 0)(static_cast <bool> (nStr2Len >= 0) ? void (0) : __assert_fail ("nStr2Len >= 0", "/home/maarten/src/libreoffice/core/sal/rtl/strtmpl.cxx" , 128, __extension__ __PRETTY_FUNCTION__)); | |||
129 | #if !IMPL_RTL_IS_USTRING | |||
130 | // take advantage of builtin optimisations | |||
131 | sal_Int32 nMin = std::min(nStr1Len, nStr2Len); | |||
132 | sal_Int32 nRet = memcmp(pStr1, pStr2, nMin); | |||
133 | return nRet == 0 ? nStr1Len - nStr2Len : nRet; | |||
134 | #else | |||
135 | if (sizeof(IMPL_RTL_STRCODE) == sizeof(wchar_t)) | |||
136 | { | |||
137 | // take advantage of builtin optimisations | |||
138 | sal_Int32 nMin = std::min(nStr1Len, nStr2Len); | |||
139 | sal_Int32 nRet = wmemcmp(reinterpret_cast<wchar_t const *>(pStr1), | |||
140 | reinterpret_cast<wchar_t const *>(pStr2), nMin); | |||
141 | return nRet == 0 ? nStr1Len - nStr2Len : nRet; | |||
142 | } | |||
143 | else | |||
144 | { | |||
145 | sal_Int32 nRet = nStr1Len - nStr2Len; | |||
146 | int nCount = (nRet <= 0) ? nStr1Len : nStr2Len; | |||
147 | ||||
148 | --pStr1; | |||
149 | --pStr2; | |||
150 | while( (--nCount >= 0) && (*++pStr1 == *++pStr2) ) ; | |||
151 | ||||
152 | if( nCount >= 0 ) | |||
153 | nRet = static_cast<sal_Int32>(IMPL_RTL_USTRCODE( *pStr1 )) | |||
154 | - static_cast<sal_Int32>(IMPL_RTL_USTRCODE( *pStr2 )); | |||
155 | ||||
156 | return nRet; | |||
157 | } | |||
158 | #endif | |||
159 | } | |||
160 | ||||
161 | /* ----------------------------------------------------------------------- */ | |||
162 | ||||
163 | sal_Int32 SAL_CALL IMPL_RTL_STRNAME( shortenedCompare_WithLength )( const IMPL_RTL_STRCODE* pStr1, | |||
164 | sal_Int32 nStr1Len, | |||
165 | const IMPL_RTL_STRCODE* pStr2, | |||
166 | sal_Int32 nStr2Len, | |||
167 | sal_Int32 nShortenedLength ) | |||
168 | SAL_THROW_EXTERN_C()throw () | |||
169 | { | |||
170 | assert(nStr1Len >= 0)(static_cast <bool> (nStr1Len >= 0) ? void (0) : __assert_fail ("nStr1Len >= 0", "/home/maarten/src/libreoffice/core/sal/rtl/strtmpl.cxx" , 170, __extension__ __PRETTY_FUNCTION__)); | |||
171 | assert(nStr2Len >= 0)(static_cast <bool> (nStr2Len >= 0) ? void (0) : __assert_fail ("nStr2Len >= 0", "/home/maarten/src/libreoffice/core/sal/rtl/strtmpl.cxx" , 171, __extension__ __PRETTY_FUNCTION__)); | |||
172 | assert(nShortenedLength >= 0)(static_cast <bool> (nShortenedLength >= 0) ? void ( 0) : __assert_fail ("nShortenedLength >= 0", "/home/maarten/src/libreoffice/core/sal/rtl/strtmpl.cxx" , 172, __extension__ __PRETTY_FUNCTION__)); | |||
173 | #if !IMPL_RTL_IS_USTRING | |||
174 | // take advantage of builtin optimisations | |||
175 | sal_Int32 nMin = std::min(std::min(nStr1Len, nStr2Len), nShortenedLength); | |||
176 | sal_Int32 nRet = memcmp(pStr1, pStr2, nMin); | |||
177 | if (nRet == 0 && nShortenedLength > std::min(nStr1Len, nStr2Len)) | |||
178 | return nStr1Len - nStr2Len; | |||
179 | return nRet; | |||
180 | #else | |||
181 | if (sizeof(IMPL_RTL_STRCODE) == sizeof(wchar_t)) | |||
182 | { | |||
183 | // take advantage of builtin optimisations | |||
184 | sal_Int32 nMin = std::min(std::min(nStr1Len, nStr2Len), nShortenedLength); | |||
185 | sal_Int32 nRet = wmemcmp(reinterpret_cast<wchar_t const *>(pStr1), reinterpret_cast<wchar_t const *>(pStr2), nMin); | |||
186 | if (nRet == 0 && nShortenedLength > std::min(nStr1Len, nStr2Len)) | |||
187 | return nStr1Len - nStr2Len; | |||
188 | return nRet; | |||
189 | } | |||
190 | else | |||
191 | { | |||
192 | const IMPL_RTL_STRCODE* pStr1End = pStr1 + nStr1Len; | |||
193 | const IMPL_RTL_STRCODE* pStr2End = pStr2 + nStr2Len; | |||
194 | sal_Int32 nRet; | |||
195 | while ( (nShortenedLength > 0) && | |||
196 | (pStr1 < pStr1End) && (pStr2 < pStr2End) ) | |||
197 | { | |||
198 | nRet = static_cast<sal_Int32>(IMPL_RTL_USTRCODE( *pStr1 ))- | |||
199 | static_cast<sal_Int32>(IMPL_RTL_USTRCODE( *pStr2 )); | |||
200 | if ( nRet ) | |||
201 | return nRet; | |||
202 | ||||
203 | nShortenedLength--; | |||
204 | pStr1++; | |||
205 | pStr2++; | |||
206 | } | |||
207 | ||||
208 | if ( nShortenedLength <= 0 ) | |||
209 | return 0; | |||
210 | return nStr1Len - nStr2Len; | |||
211 | } | |||
212 | #endif | |||
213 | } | |||
214 | ||||
215 | /* ----------------------------------------------------------------------- */ | |||
216 | ||||
217 | sal_Int32 SAL_CALL IMPL_RTL_STRNAME( reverseCompare_WithLength )( const IMPL_RTL_STRCODE* pStr1, | |||
218 | sal_Int32 nStr1Len, | |||
219 | const IMPL_RTL_STRCODE* pStr2, | |||
220 | sal_Int32 nStr2Len ) | |||
221 | SAL_THROW_EXTERN_C()throw () | |||
222 | { | |||
223 | assert(nStr1Len >= 0)(static_cast <bool> (nStr1Len >= 0) ? void (0) : __assert_fail ("nStr1Len >= 0", "/home/maarten/src/libreoffice/core/sal/rtl/strtmpl.cxx" , 223, __extension__ __PRETTY_FUNCTION__)); | |||
224 | assert(nStr2Len >= 0)(static_cast <bool> (nStr2Len >= 0) ? void (0) : __assert_fail ("nStr2Len >= 0", "/home/maarten/src/libreoffice/core/sal/rtl/strtmpl.cxx" , 224, __extension__ __PRETTY_FUNCTION__)); | |||
225 | const IMPL_RTL_STRCODE* pStr1Run = pStr1+nStr1Len; | |||
226 | const IMPL_RTL_STRCODE* pStr2Run = pStr2+nStr2Len; | |||
227 | sal_Int32 nRet; | |||
228 | while ( (pStr1 < pStr1Run) && (pStr2 < pStr2Run) ) | |||
229 | { | |||
230 | pStr1Run--; | |||
231 | pStr2Run--; | |||
232 | nRet = static_cast<sal_Int32>(IMPL_RTL_USTRCODE( *pStr1Run ))- | |||
233 | static_cast<sal_Int32>(IMPL_RTL_USTRCODE( *pStr2Run )); | |||
234 | if ( nRet ) | |||
235 | return nRet; | |||
236 | } | |||
237 | ||||
238 | return nStr1Len - nStr2Len; | |||
239 | } | |||
240 | ||||
241 | /* ----------------------------------------------------------------------- */ | |||
242 | ||||
243 | sal_Int32 SAL_CALL IMPL_RTL_STRNAME( compareIgnoreAsciiCase )( const IMPL_RTL_STRCODE* pStr1, | |||
244 | const IMPL_RTL_STRCODE* pStr2 ) | |||
245 | SAL_THROW_EXTERN_C()throw () | |||
246 | { | |||
247 | assert(pStr1)(static_cast <bool> (pStr1) ? void (0) : __assert_fail ( "pStr1", "/home/maarten/src/libreoffice/core/sal/rtl/strtmpl.cxx" , 247, __extension__ __PRETTY_FUNCTION__)); | |||
248 | assert(pStr2)(static_cast <bool> (pStr2) ? void (0) : __assert_fail ( "pStr2", "/home/maarten/src/libreoffice/core/sal/rtl/strtmpl.cxx" , 248, __extension__ __PRETTY_FUNCTION__)); | |||
249 | sal_uInt32 c1; | |||
250 | do | |||
251 | { | |||
252 | c1 = IMPL_RTL_USTRCODE(*pStr1); | |||
253 | sal_Int32 nRet = rtl::compareIgnoreAsciiCase( | |||
254 | c1, IMPL_RTL_USTRCODE(*pStr2)); | |||
255 | if ( nRet != 0 ) | |||
256 | return nRet; | |||
257 | ||||
258 | pStr1++; | |||
259 | pStr2++; | |||
260 | } | |||
261 | while (c1); | |||
262 | ||||
263 | return 0; | |||
264 | } | |||
265 | ||||
266 | /* ----------------------------------------------------------------------- */ | |||
267 | ||||
268 | sal_Int32 SAL_CALL IMPL_RTL_STRNAME( compareIgnoreAsciiCase_WithLength )( const IMPL_RTL_STRCODE* pStr1, | |||
269 | sal_Int32 nStr1Len, | |||
270 | const IMPL_RTL_STRCODE* pStr2, | |||
271 | sal_Int32 nStr2Len ) | |||
272 | SAL_THROW_EXTERN_C()throw () | |||
273 | { | |||
274 | assert(nStr1Len >= 0)(static_cast <bool> (nStr1Len >= 0) ? void (0) : __assert_fail ("nStr1Len >= 0", "/home/maarten/src/libreoffice/core/sal/rtl/strtmpl.cxx" , 274, __extension__ __PRETTY_FUNCTION__)); | |||
275 | assert(nStr2Len >= 0)(static_cast <bool> (nStr2Len >= 0) ? void (0) : __assert_fail ("nStr2Len >= 0", "/home/maarten/src/libreoffice/core/sal/rtl/strtmpl.cxx" , 275, __extension__ __PRETTY_FUNCTION__)); | |||
276 | const IMPL_RTL_STRCODE* pStr1End = pStr1 + nStr1Len; | |||
277 | const IMPL_RTL_STRCODE* pStr2End = pStr2 + nStr2Len; | |||
278 | while ( (pStr1 < pStr1End) && (pStr2 < pStr2End) ) | |||
279 | { | |||
280 | sal_Int32 nRet = rtl::compareIgnoreAsciiCase( | |||
281 | IMPL_RTL_USTRCODE(*pStr1), IMPL_RTL_USTRCODE(*pStr2)); | |||
282 | if ( nRet != 0 ) | |||
283 | return nRet; | |||
284 | ||||
285 | pStr1++; | |||
286 | pStr2++; | |||
287 | } | |||
288 | ||||
289 | return nStr1Len - nStr2Len; | |||
290 | } | |||
291 | ||||
292 | /* ----------------------------------------------------------------------- */ | |||
293 | ||||
294 | sal_Int32 SAL_CALL IMPL_RTL_STRNAME( shortenedCompareIgnoreAsciiCase_WithLength )( const IMPL_RTL_STRCODE* pStr1, | |||
295 | sal_Int32 nStr1Len, | |||
296 | const IMPL_RTL_STRCODE* pStr2, | |||
297 | sal_Int32 nStr2Len, | |||
298 | sal_Int32 nShortenedLength ) | |||
299 | SAL_THROW_EXTERN_C()throw () | |||
300 | { | |||
301 | assert(nStr1Len >= 0)(static_cast <bool> (nStr1Len >= 0) ? void (0) : __assert_fail ("nStr1Len >= 0", "/home/maarten/src/libreoffice/core/sal/rtl/strtmpl.cxx" , 301, __extension__ __PRETTY_FUNCTION__)); | |||
302 | assert(nStr2Len >= 0)(static_cast <bool> (nStr2Len >= 0) ? void (0) : __assert_fail ("nStr2Len >= 0", "/home/maarten/src/libreoffice/core/sal/rtl/strtmpl.cxx" , 302, __extension__ __PRETTY_FUNCTION__)); | |||
303 | assert(nShortenedLength >= 0)(static_cast <bool> (nShortenedLength >= 0) ? void ( 0) : __assert_fail ("nShortenedLength >= 0", "/home/maarten/src/libreoffice/core/sal/rtl/strtmpl.cxx" , 303, __extension__ __PRETTY_FUNCTION__)); | |||
304 | const IMPL_RTL_STRCODE* pStr1End = pStr1 + nStr1Len; | |||
305 | const IMPL_RTL_STRCODE* pStr2End = pStr2 + nStr2Len; | |||
306 | while ( (nShortenedLength > 0) && | |||
307 | (pStr1 < pStr1End) && (pStr2 < pStr2End) ) | |||
308 | { | |||
309 | sal_Int32 nRet = rtl::compareIgnoreAsciiCase( | |||
310 | IMPL_RTL_USTRCODE(*pStr1), IMPL_RTL_USTRCODE(*pStr2)); | |||
311 | if ( nRet != 0 ) | |||
312 | return nRet; | |||
313 | ||||
314 | nShortenedLength--; | |||
315 | pStr1++; | |||
316 | pStr2++; | |||
317 | } | |||
318 | ||||
319 | if ( nShortenedLength <= 0 ) | |||
320 | return 0; | |||
321 | return nStr1Len - nStr2Len; | |||
322 | } | |||
323 | ||||
324 | /* ----------------------------------------------------------------------- */ | |||
325 | ||||
326 | sal_Int32 SAL_CALL IMPL_RTL_STRNAME( hashCode )( const IMPL_RTL_STRCODE* pStr ) | |||
327 | SAL_THROW_EXTERN_C()throw () | |||
328 | { | |||
329 | return IMPL_RTL_STRNAME( hashCode_WithLength )( pStr, IMPL_RTL_STRNAME( getLength )( pStr ) ); | |||
330 | } | |||
331 | ||||
332 | /* ----------------------------------------------------------------------- */ | |||
333 | ||||
334 | sal_Int32 SAL_CALL IMPL_RTL_STRNAME( hashCode_WithLength )( const IMPL_RTL_STRCODE* pStr, | |||
335 | sal_Int32 nLen ) | |||
336 | SAL_THROW_EXTERN_C()throw () | |||
337 | { | |||
338 | assert(nLen >= 0)(static_cast <bool> (nLen >= 0) ? void (0) : __assert_fail ("nLen >= 0", "/home/maarten/src/libreoffice/core/sal/rtl/strtmpl.cxx" , 338, __extension__ __PRETTY_FUNCTION__)); | |||
339 | sal_uInt32 h = static_cast<sal_uInt32>(nLen); | |||
340 | while ( nLen > 0 ) | |||
341 | { | |||
342 | h = (h*37U) + IMPL_RTL_USTRCODE( *pStr ); | |||
343 | pStr++; | |||
344 | nLen--; | |||
345 | } | |||
346 | return static_cast<sal_Int32>(h); | |||
347 | } | |||
348 | ||||
349 | /* ----------------------------------------------------------------------- */ | |||
350 | ||||
351 | sal_Int32 SAL_CALL IMPL_RTL_STRNAME( indexOfChar )( const IMPL_RTL_STRCODE* pStr, | |||
352 | IMPL_RTL_STRCODE c ) | |||
353 | SAL_THROW_EXTERN_C()throw () | |||
354 | { | |||
355 | assert(pStr)(static_cast <bool> (pStr) ? void (0) : __assert_fail ( "pStr", "/home/maarten/src/libreoffice/core/sal/rtl/strtmpl.cxx" , 355, __extension__ __PRETTY_FUNCTION__)); | |||
356 | #if !IMPL_RTL_IS_USTRING | |||
357 | // take advantage of builtin optimisations | |||
358 | const IMPL_RTL_STRCODE* p = strchr(pStr, c); | |||
359 | return p ? p - pStr : -1; | |||
360 | #else | |||
361 | if (sizeof(IMPL_RTL_STRCODE) == sizeof(wchar_t)) | |||
362 | { | |||
363 | // take advantage of builtin optimisations | |||
364 | wchar_t const * p = wcschr(reinterpret_cast<wchar_t const *>(pStr), static_cast<wchar_t>(c)); | |||
365 | return p ? p - reinterpret_cast<wchar_t const *>(pStr) : -1; | |||
366 | } | |||
367 | else | |||
368 | { | |||
369 | const IMPL_RTL_STRCODE* pTempStr = pStr; | |||
370 | while ( *pTempStr ) | |||
371 | { | |||
372 | if ( *pTempStr == c ) | |||
373 | return pTempStr-pStr; | |||
374 | ||||
375 | pTempStr++; | |||
376 | } | |||
377 | ||||
378 | return -1; | |||
379 | } | |||
380 | #endif | |||
381 | } | |||
382 | ||||
383 | /* ----------------------------------------------------------------------- */ | |||
384 | ||||
385 | sal_Int32 SAL_CALL IMPL_RTL_STRNAME( indexOfChar_WithLength )( const IMPL_RTL_STRCODE* pStr, | |||
386 | sal_Int32 nLen, | |||
387 | IMPL_RTL_STRCODE c ) | |||
388 | SAL_THROW_EXTERN_C()throw () | |||
389 | { | |||
390 | // assert(nLen >= 0); | |||
391 | #if !IMPL_RTL_IS_USTRING | |||
392 | // take advantage of builtin optimisations | |||
393 | IMPL_RTL_STRCODE* p = static_cast<IMPL_RTL_STRCODE*>(std::memchr(const_cast<IMPL_RTL_STRCODE *>(pStr), c, nLen)); | |||
394 | return p ? p - pStr : -1; | |||
395 | #else | |||
396 | const IMPL_RTL_STRCODE* pTempStr = pStr; | |||
397 | while ( nLen > 0 ) | |||
398 | { | |||
399 | if ( *pTempStr == c ) | |||
400 | return pTempStr-pStr; | |||
401 | ||||
402 | pTempStr++; | |||
403 | nLen--; | |||
404 | } | |||
405 | ||||
406 | return -1; | |||
407 | #endif | |||
408 | } | |||
409 | ||||
410 | /* ----------------------------------------------------------------------- */ | |||
411 | ||||
412 | sal_Int32 SAL_CALL IMPL_RTL_STRNAME( lastIndexOfChar )( const IMPL_RTL_STRCODE* pStr, | |||
413 | IMPL_RTL_STRCODE c ) | |||
414 | SAL_THROW_EXTERN_C()throw () | |||
415 | { | |||
416 | assert(pStr)(static_cast <bool> (pStr) ? void (0) : __assert_fail ( "pStr", "/home/maarten/src/libreoffice/core/sal/rtl/strtmpl.cxx" , 416, __extension__ __PRETTY_FUNCTION__)); | |||
417 | #if !IMPL_RTL_IS_USTRING | |||
418 | // take advantage of builtin optimisations | |||
419 | const IMPL_RTL_STRCODE* p = strrchr(pStr, c); | |||
420 | return p ? p - pStr : -1; | |||
421 | #else | |||
422 | if (sizeof(IMPL_RTL_STRCODE) == sizeof(wchar_t)) | |||
423 | { | |||
424 | // take advantage of builtin optimisations | |||
425 | wchar_t const * p = wcsrchr(reinterpret_cast<wchar_t const *>(pStr), static_cast<wchar_t>(c)); | |||
426 | return p ? p - reinterpret_cast<wchar_t const *>(pStr) : -1; | |||
427 | } | |||
428 | else | |||
429 | { | |||
430 | return IMPL_RTL_STRNAME( lastIndexOfChar_WithLength )( pStr, IMPL_RTL_STRNAME( getLength )( pStr ), c ); | |||
431 | } | |||
432 | #endif | |||
433 | } | |||
434 | ||||
435 | /* ----------------------------------------------------------------------- */ | |||
436 | ||||
437 | sal_Int32 SAL_CALL IMPL_RTL_STRNAME( lastIndexOfChar_WithLength )( const IMPL_RTL_STRCODE* pStr, | |||
438 | sal_Int32 nLen, | |||
439 | IMPL_RTL_STRCODE c ) | |||
440 | SAL_THROW_EXTERN_C()throw () | |||
441 | { | |||
442 | assert(nLen >= 0)(static_cast <bool> (nLen >= 0) ? void (0) : __assert_fail ("nLen >= 0", "/home/maarten/src/libreoffice/core/sal/rtl/strtmpl.cxx" , 442, __extension__ __PRETTY_FUNCTION__)); | |||
443 | pStr += nLen; | |||
444 | while ( nLen > 0 ) | |||
445 | { | |||
446 | nLen--; | |||
447 | pStr--; | |||
448 | ||||
449 | if ( *pStr == c ) | |||
450 | return nLen; | |||
451 | } | |||
452 | ||||
453 | return -1; | |||
454 | } | |||
455 | ||||
456 | /* ----------------------------------------------------------------------- */ | |||
457 | ||||
458 | sal_Int32 SAL_CALL IMPL_RTL_STRNAME( indexOfStr )( const IMPL_RTL_STRCODE* pStr, | |||
459 | const IMPL_RTL_STRCODE* pSubStr ) | |||
460 | SAL_THROW_EXTERN_C()throw () | |||
461 | { | |||
462 | assert(pStr)(static_cast <bool> (pStr) ? void (0) : __assert_fail ( "pStr", "/home/maarten/src/libreoffice/core/sal/rtl/strtmpl.cxx" , 462, __extension__ __PRETTY_FUNCTION__)); | |||
463 | assert(pSubStr)(static_cast <bool> (pSubStr) ? void (0) : __assert_fail ("pSubStr", "/home/maarten/src/libreoffice/core/sal/rtl/strtmpl.cxx" , 463, __extension__ __PRETTY_FUNCTION__)); | |||
464 | #if !IMPL_RTL_IS_USTRING | |||
465 | // take advantage of builtin optimisations | |||
466 | const IMPL_RTL_STRCODE* p = strstr(pStr, pSubStr); | |||
467 | return p ? p - pStr : -1; | |||
468 | #else | |||
469 | if (sizeof(IMPL_RTL_STRCODE) == sizeof(wchar_t)) | |||
470 | { | |||
471 | // take advantage of builtin optimisations | |||
472 | wchar_t const * p = wcsstr(reinterpret_cast<wchar_t const *>(pStr), reinterpret_cast<wchar_t const *>(pSubStr)); | |||
473 | return p ? p - reinterpret_cast<wchar_t const *>(pStr) : -1; | |||
474 | } | |||
475 | else | |||
476 | { | |||
477 | return IMPL_RTL_STRNAME( indexOfStr_WithLength )( pStr, IMPL_RTL_STRNAME( getLength )( pStr ), | |||
478 | pSubStr, IMPL_RTL_STRNAME( getLength )( pSubStr ) ); | |||
479 | } | |||
480 | #endif | |||
481 | } | |||
482 | ||||
483 | /* ----------------------------------------------------------------------- */ | |||
484 | ||||
485 | sal_Int32 SAL_CALL IMPL_RTL_STRNAME( indexOfStr_WithLength )( const IMPL_RTL_STRCODE* pStr, | |||
486 | sal_Int32 nStrLen, | |||
487 | const IMPL_RTL_STRCODE* pSubStr, | |||
488 | sal_Int32 nSubLen ) | |||
489 | SAL_THROW_EXTERN_C()throw () | |||
490 | { | |||
491 | assert(nStrLen >= 0)(static_cast <bool> (nStrLen >= 0) ? void (0) : __assert_fail ("nStrLen >= 0", "/home/maarten/src/libreoffice/core/sal/rtl/strtmpl.cxx" , 491, __extension__ __PRETTY_FUNCTION__)); | |||
492 | assert(nSubLen >= 0)(static_cast <bool> (nSubLen >= 0) ? void (0) : __assert_fail ("nSubLen >= 0", "/home/maarten/src/libreoffice/core/sal/rtl/strtmpl.cxx" , 492, __extension__ __PRETTY_FUNCTION__)); | |||
493 | /* faster search for a single character */ | |||
494 | if ( nSubLen < 2 ) | |||
495 | { | |||
496 | /* an empty SubString is always not findable */ | |||
497 | if ( nSubLen == 1 ) | |||
498 | { | |||
499 | IMPL_RTL_STRCODE c = *pSubStr; | |||
500 | const IMPL_RTL_STRCODE* pTempStr = pStr; | |||
501 | while ( nStrLen > 0 ) | |||
502 | { | |||
503 | if ( *pTempStr == c ) | |||
504 | return pTempStr-pStr; | |||
505 | ||||
506 | pTempStr++; | |||
507 | nStrLen--; | |||
508 | } | |||
509 | } | |||
510 | } | |||
511 | else | |||
512 | { | |||
513 | const IMPL_RTL_STRCODE* pTempStr = pStr; | |||
514 | while ( nStrLen > 0 ) | |||
515 | { | |||
516 | if ( *pTempStr == *pSubStr ) | |||
517 | { | |||
518 | /* Compare SubString */ | |||
519 | if ( nSubLen <= nStrLen ) | |||
520 | { | |||
521 | const IMPL_RTL_STRCODE* pTempStr1 = pTempStr; | |||
522 | const IMPL_RTL_STRCODE* pTempStr2 = pSubStr; | |||
523 | sal_Int32 nTempLen = nSubLen; | |||
524 | while ( nTempLen ) | |||
525 | { | |||
526 | if ( *pTempStr1 != *pTempStr2 ) | |||
527 | break; | |||
528 | ||||
529 | pTempStr1++; | |||
530 | pTempStr2++; | |||
531 | nTempLen--; | |||
532 | } | |||
533 | ||||
534 | if ( !nTempLen ) | |||
535 | return pTempStr-pStr; | |||
536 | } | |||
537 | else | |||
538 | break; | |||
539 | } | |||
540 | ||||
541 | nStrLen--; | |||
542 | pTempStr++; | |||
543 | } | |||
544 | } | |||
545 | ||||
546 | return -1; | |||
547 | } | |||
548 | ||||
549 | /* ----------------------------------------------------------------------- */ | |||
550 | ||||
551 | sal_Int32 SAL_CALL IMPL_RTL_STRNAME( lastIndexOfStr )( const IMPL_RTL_STRCODE* pStr, | |||
552 | const IMPL_RTL_STRCODE* pSubStr ) | |||
553 | SAL_THROW_EXTERN_C()throw () | |||
554 | { | |||
555 | return IMPL_RTL_STRNAME( lastIndexOfStr_WithLength )( pStr, IMPL_RTL_STRNAME( getLength )( pStr ), | |||
556 | pSubStr, IMPL_RTL_STRNAME( getLength )( pSubStr ) ); | |||
557 | } | |||
558 | ||||
559 | /* ----------------------------------------------------------------------- */ | |||
560 | ||||
561 | sal_Int32 SAL_CALL IMPL_RTL_STRNAME( lastIndexOfStr_WithLength )( const IMPL_RTL_STRCODE* pStr, | |||
562 | sal_Int32 nStrLen, | |||
563 | const IMPL_RTL_STRCODE* pSubStr, | |||
564 | sal_Int32 nSubLen ) | |||
565 | SAL_THROW_EXTERN_C()throw () | |||
566 | { | |||
567 | assert(nStrLen >= 0)(static_cast <bool> (nStrLen >= 0) ? void (0) : __assert_fail ("nStrLen >= 0", "/home/maarten/src/libreoffice/core/sal/rtl/strtmpl.cxx" , 567, __extension__ __PRETTY_FUNCTION__)); | |||
568 | assert(nSubLen >= 0)(static_cast <bool> (nSubLen >= 0) ? void (0) : __assert_fail ("nSubLen >= 0", "/home/maarten/src/libreoffice/core/sal/rtl/strtmpl.cxx" , 568, __extension__ __PRETTY_FUNCTION__)); | |||
569 | /* faster search for a single character */ | |||
570 | if ( nSubLen < 2 ) | |||
571 | { | |||
572 | /* an empty SubString is always not findable */ | |||
573 | if ( nSubLen == 1 ) | |||
574 | { | |||
575 | IMPL_RTL_STRCODE c = *pSubStr; | |||
576 | pStr += nStrLen; | |||
577 | while ( nStrLen > 0 ) | |||
578 | { | |||
579 | nStrLen--; | |||
580 | pStr--; | |||
581 | ||||
582 | if ( *pStr == c ) | |||
583 | return nStrLen; | |||
584 | } | |||
585 | } | |||
586 | } | |||
587 | else | |||
588 | { | |||
589 | pStr += nStrLen; | |||
590 | nStrLen -= nSubLen; | |||
591 | pStr -= nSubLen; | |||
592 | while ( nStrLen >= 0 ) | |||
593 | { | |||
594 | const IMPL_RTL_STRCODE* pTempStr1 = pStr; | |||
595 | const IMPL_RTL_STRCODE* pTempStr2 = pSubStr; | |||
596 | sal_Int32 nTempLen = nSubLen; | |||
597 | while ( nTempLen ) | |||
598 | { | |||
599 | if ( *pTempStr1 != *pTempStr2 ) | |||
600 | break; | |||
601 | ||||
602 | pTempStr1++; | |||
603 | pTempStr2++; | |||
604 | nTempLen--; | |||
605 | } | |||
606 | ||||
607 | if ( !nTempLen ) | |||
608 | return nStrLen; | |||
609 | ||||
610 | nStrLen--; | |||
611 | pStr--; | |||
612 | } | |||
613 | } | |||
614 | ||||
615 | return -1; | |||
616 | } | |||
617 | ||||
618 | /* ----------------------------------------------------------------------- */ | |||
619 | ||||
620 | void SAL_CALL IMPL_RTL_STRNAME( replaceChar )( IMPL_RTL_STRCODE* pStr, | |||
621 | IMPL_RTL_STRCODE cOld, | |||
622 | IMPL_RTL_STRCODE cNew ) | |||
623 | SAL_THROW_EXTERN_C()throw () | |||
624 | { | |||
625 | assert(pStr)(static_cast <bool> (pStr) ? void (0) : __assert_fail ( "pStr", "/home/maarten/src/libreoffice/core/sal/rtl/strtmpl.cxx" , 625, __extension__ __PRETTY_FUNCTION__)); | |||
626 | while ( *pStr ) | |||
627 | { | |||
628 | if ( *pStr == cOld ) | |||
629 | *pStr = cNew; | |||
630 | ||||
631 | pStr++; | |||
632 | } | |||
633 | } | |||
634 | ||||
635 | /* ----------------------------------------------------------------------- */ | |||
636 | ||||
637 | void SAL_CALL IMPL_RTL_STRNAME( replaceChar_WithLength )( IMPL_RTL_STRCODE* pStr, | |||
638 | sal_Int32 nLen, | |||
639 | IMPL_RTL_STRCODE cOld, | |||
640 | IMPL_RTL_STRCODE cNew ) | |||
641 | SAL_THROW_EXTERN_C()throw () | |||
642 | { | |||
643 | assert(nLen >= 0)(static_cast <bool> (nLen >= 0) ? void (0) : __assert_fail ("nLen >= 0", "/home/maarten/src/libreoffice/core/sal/rtl/strtmpl.cxx" , 643, __extension__ __PRETTY_FUNCTION__)); | |||
644 | while ( nLen > 0 ) | |||
645 | { | |||
646 | if ( *pStr == cOld ) | |||
647 | *pStr = cNew; | |||
648 | ||||
649 | pStr++; | |||
650 | nLen--; | |||
651 | } | |||
652 | } | |||
653 | ||||
654 | /* ----------------------------------------------------------------------- */ | |||
655 | ||||
656 | void SAL_CALL IMPL_RTL_STRNAME( toAsciiLowerCase )( IMPL_RTL_STRCODE* pStr ) | |||
657 | SAL_THROW_EXTERN_C()throw () | |||
658 | { | |||
659 | assert(pStr)(static_cast <bool> (pStr) ? void (0) : __assert_fail ( "pStr", "/home/maarten/src/libreoffice/core/sal/rtl/strtmpl.cxx" , 659, __extension__ __PRETTY_FUNCTION__)); | |||
660 | while ( *pStr ) | |||
661 | { | |||
662 | *pStr = rtl::toAsciiLowerCase(IMPL_RTL_USTRCODE(*pStr)); | |||
663 | ||||
664 | pStr++; | |||
665 | } | |||
666 | } | |||
667 | ||||
668 | /* ----------------------------------------------------------------------- */ | |||
669 | ||||
670 | void SAL_CALL IMPL_RTL_STRNAME( toAsciiLowerCase_WithLength )( IMPL_RTL_STRCODE* pStr, | |||
671 | sal_Int32 nLen ) | |||
672 | SAL_THROW_EXTERN_C()throw () | |||
673 | { | |||
674 | assert(nLen >= 0)(static_cast <bool> (nLen >= 0) ? void (0) : __assert_fail ("nLen >= 0", "/home/maarten/src/libreoffice/core/sal/rtl/strtmpl.cxx" , 674, __extension__ __PRETTY_FUNCTION__)); | |||
675 | while ( nLen > 0 ) | |||
676 | { | |||
677 | *pStr = rtl::toAsciiLowerCase(IMPL_RTL_USTRCODE(*pStr)); | |||
678 | ||||
679 | pStr++; | |||
680 | nLen--; | |||
681 | } | |||
682 | } | |||
683 | ||||
684 | /* ----------------------------------------------------------------------- */ | |||
685 | ||||
686 | void SAL_CALL IMPL_RTL_STRNAME( toAsciiUpperCase )( IMPL_RTL_STRCODE* pStr ) | |||
687 | SAL_THROW_EXTERN_C()throw () | |||
688 | { | |||
689 | assert(pStr)(static_cast <bool> (pStr) ? void (0) : __assert_fail ( "pStr", "/home/maarten/src/libreoffice/core/sal/rtl/strtmpl.cxx" , 689, __extension__ __PRETTY_FUNCTION__)); | |||
690 | while ( *pStr ) | |||
691 | { | |||
692 | *pStr = rtl::toAsciiUpperCase(IMPL_RTL_USTRCODE(*pStr)); | |||
693 | ||||
694 | pStr++; | |||
695 | } | |||
696 | } | |||
697 | ||||
698 | /* ----------------------------------------------------------------------- */ | |||
699 | ||||
700 | void SAL_CALL IMPL_RTL_STRNAME( toAsciiUpperCase_WithLength )( IMPL_RTL_STRCODE* pStr, | |||
701 | sal_Int32 nLen ) | |||
702 | SAL_THROW_EXTERN_C()throw () | |||
703 | { | |||
704 | assert(nLen >= 0)(static_cast <bool> (nLen >= 0) ? void (0) : __assert_fail ("nLen >= 0", "/home/maarten/src/libreoffice/core/sal/rtl/strtmpl.cxx" , 704, __extension__ __PRETTY_FUNCTION__)); | |||
705 | while ( nLen > 0 ) | |||
706 | { | |||
707 | *pStr = rtl::toAsciiUpperCase(IMPL_RTL_USTRCODE(*pStr)); | |||
708 | ||||
709 | pStr++; | |||
710 | nLen--; | |||
711 | } | |||
712 | } | |||
713 | ||||
714 | /* ----------------------------------------------------------------------- */ | |||
715 | ||||
716 | sal_Int32 SAL_CALL IMPL_RTL_STRNAME( trim )( IMPL_RTL_STRCODE* pStr ) | |||
717 | SAL_THROW_EXTERN_C()throw () | |||
718 | { | |||
719 | return IMPL_RTL_STRNAME( trim_WithLength )( pStr, IMPL_RTL_STRNAME( getLength )( pStr ) ); | |||
720 | } | |||
721 | ||||
722 | /* ----------------------------------------------------------------------- */ | |||
723 | ||||
724 | sal_Int32 SAL_CALL IMPL_RTL_STRNAME( trim_WithLength )( IMPL_RTL_STRCODE* pStr, sal_Int32 nLen ) | |||
725 | SAL_THROW_EXTERN_C()throw () | |||
726 | { | |||
727 | assert(nLen >= 0)(static_cast <bool> (nLen >= 0) ? void (0) : __assert_fail ("nLen >= 0", "/home/maarten/src/libreoffice/core/sal/rtl/strtmpl.cxx" , 727, __extension__ __PRETTY_FUNCTION__)); | |||
728 | sal_Int32 nPreSpaces = 0; | |||
729 | sal_Int32 nPostSpaces = 0; | |||
730 | sal_Int32 nIndex = nLen-1; | |||
731 | ||||
732 | while ( (nPreSpaces < nLen) && rtl_ImplIsWhitespace( IMPL_RTL_USTRCODE(*(pStr+nPreSpaces)) ) ) | |||
733 | nPreSpaces++; | |||
734 | ||||
735 | while ( (nIndex > nPreSpaces) && rtl_ImplIsWhitespace( IMPL_RTL_USTRCODE(*(pStr+nIndex)) ) ) | |||
736 | { | |||
737 | nPostSpaces++; | |||
738 | nIndex--; | |||
739 | } | |||
740 | ||||
741 | if ( nPostSpaces ) | |||
742 | { | |||
743 | nLen -= nPostSpaces; | |||
744 | *(pStr+nLen) = 0; | |||
745 | } | |||
746 | ||||
747 | if ( nPreSpaces ) | |||
748 | { | |||
749 | nLen -= nPreSpaces; | |||
750 | memmove(pStr, pStr + nPreSpaces, nLen * sizeof(IMPL_RTL_STRCODE)); | |||
751 | pStr += nLen; | |||
752 | *pStr = 0; | |||
753 | } | |||
754 | ||||
755 | return nLen; | |||
756 | } | |||
757 | ||||
758 | /* ----------------------------------------------------------------------- */ | |||
759 | ||||
760 | sal_Int32 SAL_CALL IMPL_RTL_STRNAME( valueOfBoolean )( IMPL_RTL_STRCODE* pStr, sal_Bool b ) | |||
761 | SAL_THROW_EXTERN_C()throw () | |||
762 | { | |||
763 | assert(pStr)(static_cast <bool> (pStr) ? void (0) : __assert_fail ( "pStr", "/home/maarten/src/libreoffice/core/sal/rtl/strtmpl.cxx" , 763, __extension__ __PRETTY_FUNCTION__)); | |||
764 | if ( b ) | |||
765 | { | |||
766 | *pStr = 't'; | |||
767 | pStr++; | |||
768 | *pStr = 'r'; | |||
769 | pStr++; | |||
770 | *pStr = 'u'; | |||
771 | pStr++; | |||
772 | *pStr = 'e'; | |||
773 | pStr++; | |||
774 | *pStr = 0; | |||
775 | return 4; | |||
776 | } | |||
777 | else | |||
778 | { | |||
779 | *pStr = 'f'; | |||
780 | pStr++; | |||
781 | *pStr = 'a'; | |||
782 | pStr++; | |||
783 | *pStr = 'l'; | |||
784 | pStr++; | |||
785 | *pStr = 's'; | |||
786 | pStr++; | |||
787 | *pStr = 'e'; | |||
788 | pStr++; | |||
789 | *pStr = 0; | |||
790 | return 5; | |||
791 | } | |||
792 | } | |||
793 | ||||
794 | /* ----------------------------------------------------------------------- */ | |||
795 | ||||
796 | sal_Int32 SAL_CALL IMPL_RTL_STRNAME( valueOfChar )( IMPL_RTL_STRCODE* pStr, | |||
797 | IMPL_RTL_STRCODE c ) | |||
798 | SAL_THROW_EXTERN_C()throw () | |||
799 | { | |||
800 | assert(pStr)(static_cast <bool> (pStr) ? void (0) : __assert_fail ( "pStr", "/home/maarten/src/libreoffice/core/sal/rtl/strtmpl.cxx" , 800, __extension__ __PRETTY_FUNCTION__)); | |||
801 | *pStr++ = c; | |||
802 | *pStr = 0; | |||
803 | return 1; | |||
804 | } | |||
805 | ||||
806 | /* ----------------------------------------------------------------------- */ | |||
807 | ||||
808 | sal_Int32 SAL_CALL IMPL_RTL_STRNAME( valueOfInt32 )( IMPL_RTL_STRCODE* pStr, | |||
809 | sal_Int32 n, | |||
810 | sal_Int16 nRadix ) | |||
811 | SAL_THROW_EXTERN_C()throw () | |||
812 | { | |||
813 | assert(pStr)(static_cast <bool> (pStr) ? void (0) : __assert_fail ( "pStr", "/home/maarten/src/libreoffice/core/sal/rtl/strtmpl.cxx" , 813, __extension__ __PRETTY_FUNCTION__)); | |||
814 | assert( nRadix >= RTL_STR_MIN_RADIX && nRadix <= RTL_STR_MAX_RADIX )(static_cast <bool> (nRadix >= 2 && nRadix <= 36) ? void (0) : __assert_fail ("nRadix >= RTL_STR_MIN_RADIX && nRadix <= RTL_STR_MAX_RADIX" , "/home/maarten/src/libreoffice/core/sal/rtl/strtmpl.cxx", 814 , __extension__ __PRETTY_FUNCTION__)); | |||
815 | char aBuf[RTL_STR_MAX_VALUEOFINT3233]; | |||
816 | char* pBuf = aBuf; | |||
817 | sal_Int32 nLen = 0; | |||
818 | sal_uInt32 nValue; | |||
819 | ||||
820 | /* Radix must be valid */ | |||
821 | if ( (nRadix < RTL_STR_MIN_RADIX2) || (nRadix > RTL_STR_MAX_RADIX36) ) | |||
822 | nRadix = 10; | |||
823 | ||||
824 | /* is value negative */ | |||
825 | if ( n < 0 ) | |||
826 | { | |||
827 | *pStr = '-'; | |||
828 | pStr++; | |||
829 | nLen++; | |||
830 | nValue = n == SAL_MIN_INT32((sal_Int32) (-0x7FFFFFFF - 1)) ? static_cast<sal_uInt32>(n) : -n; | |||
831 | } | |||
832 | else | |||
833 | nValue = n; | |||
834 | ||||
835 | /* create a recursive buffer with all values, except the last one */ | |||
836 | do | |||
837 | { | |||
838 | char nDigit = static_cast<char>(nValue % nRadix); | |||
839 | nValue /= nRadix; | |||
840 | if ( nDigit > 9 ) | |||
841 | *pBuf = (nDigit-10) + 'a'; | |||
842 | else | |||
843 | *pBuf = (nDigit + '0' ); | |||
844 | pBuf++; | |||
845 | } | |||
846 | while ( nValue > 0 ); | |||
847 | ||||
848 | /* copy the values in the right direction into the destination buffer */ | |||
849 | do | |||
850 | { | |||
851 | pBuf--; | |||
852 | *pStr = *pBuf; | |||
853 | pStr++; | |||
854 | nLen++; | |||
855 | } | |||
856 | while ( pBuf != aBuf ); | |||
857 | *pStr = 0; | |||
858 | ||||
859 | return nLen; | |||
860 | } | |||
861 | ||||
862 | /* ----------------------------------------------------------------------- */ | |||
863 | ||||
864 | sal_Int32 SAL_CALL IMPL_RTL_STRNAME( valueOfInt64 )( IMPL_RTL_STRCODE* pStr, | |||
865 | sal_Int64 n, | |||
866 | sal_Int16 nRadix ) | |||
867 | SAL_THROW_EXTERN_C()throw () | |||
868 | { | |||
869 | assert(pStr)(static_cast <bool> (pStr) ? void (0) : __assert_fail ( "pStr", "/home/maarten/src/libreoffice/core/sal/rtl/strtmpl.cxx" , 869, __extension__ __PRETTY_FUNCTION__)); | |||
870 | assert( nRadix >= RTL_STR_MIN_RADIX && nRadix <= RTL_STR_MAX_RADIX )(static_cast <bool> (nRadix >= 2 && nRadix <= 36) ? void (0) : __assert_fail ("nRadix >= RTL_STR_MIN_RADIX && nRadix <= RTL_STR_MAX_RADIX" , "/home/maarten/src/libreoffice/core/sal/rtl/strtmpl.cxx", 870 , __extension__ __PRETTY_FUNCTION__)); | |||
871 | char aBuf[RTL_STR_MAX_VALUEOFINT6465]; | |||
872 | char* pBuf = aBuf; | |||
873 | sal_Int32 nLen = 0; | |||
874 | sal_uInt64 nValue; | |||
875 | ||||
876 | /* Radix must be valid */ | |||
877 | if ( (nRadix < RTL_STR_MIN_RADIX2) || (nRadix > RTL_STR_MAX_RADIX36) ) | |||
878 | nRadix = 10; | |||
879 | ||||
880 | /* is value negative */ | |||
881 | if ( n < 0 ) | |||
882 | { | |||
883 | *pStr = '-'; | |||
884 | pStr++; | |||
885 | nLen++; | |||
886 | nValue = n == SAL_MIN_INT64((sal_Int64) (-0x7FFFFFFFFFFFFFFFl - 1)) ? static_cast<sal_uInt64>(n) : -n; | |||
887 | } | |||
888 | else | |||
889 | nValue = n; | |||
890 | ||||
891 | /* create a recursive buffer with all values, except the last one */ | |||
892 | do | |||
893 | { | |||
894 | char nDigit = static_cast<char>(nValue % nRadix); | |||
895 | nValue /= nRadix; | |||
896 | if ( nDigit > 9 ) | |||
897 | *pBuf = (nDigit-10) + 'a'; | |||
898 | else | |||
899 | *pBuf = (nDigit + '0' ); | |||
900 | pBuf++; | |||
901 | } | |||
902 | while ( nValue > 0 ); | |||
903 | ||||
904 | /* copy the values in the right direction into the destination buffer */ | |||
905 | do | |||
906 | { | |||
907 | pBuf--; | |||
908 | *pStr = *pBuf; | |||
909 | pStr++; | |||
910 | nLen++; | |||
911 | } | |||
912 | while ( pBuf != aBuf ); | |||
913 | *pStr = 0; | |||
914 | ||||
915 | return nLen; | |||
916 | } | |||
917 | ||||
918 | /* ----------------------------------------------------------------------- */ | |||
919 | ||||
920 | sal_Int32 SAL_CALL IMPL_RTL_STRNAME( valueOfUInt64 )( IMPL_RTL_STRCODE* pStr, | |||
921 | sal_uInt64 n, | |||
922 | sal_Int16 nRadix ) | |||
923 | SAL_THROW_EXTERN_C()throw () | |||
924 | { | |||
925 | assert(pStr)(static_cast <bool> (pStr) ? void (0) : __assert_fail ( "pStr", "/home/maarten/src/libreoffice/core/sal/rtl/strtmpl.cxx" , 925, __extension__ __PRETTY_FUNCTION__)); | |||
926 | assert( nRadix >= RTL_STR_MIN_RADIX && nRadix <= RTL_STR_MAX_RADIX )(static_cast <bool> (nRadix >= 2 && nRadix <= 36) ? void (0) : __assert_fail ("nRadix >= RTL_STR_MIN_RADIX && nRadix <= RTL_STR_MAX_RADIX" , "/home/maarten/src/libreoffice/core/sal/rtl/strtmpl.cxx", 926 , __extension__ __PRETTY_FUNCTION__)); | |||
927 | char aBuf[RTL_STR_MAX_VALUEOFUINT6465]; | |||
928 | char* pBuf = aBuf; | |||
929 | sal_Int32 nLen = 0; | |||
930 | sal_uInt64 nValue; | |||
931 | ||||
932 | /* Radix must be valid */ | |||
933 | if ( (nRadix < RTL_STR_MIN_RADIX2) || (nRadix > RTL_STR_MAX_RADIX36) ) | |||
934 | nRadix = 10; | |||
935 | ||||
936 | nValue = n; | |||
937 | ||||
938 | /* create a recursive buffer with all values, except the last one */ | |||
939 | do | |||
940 | { | |||
941 | char nDigit = static_cast<char>(nValue % nRadix); | |||
942 | nValue /= nRadix; | |||
943 | if ( nDigit > 9 ) | |||
944 | *pBuf = (nDigit-10) + 'a'; | |||
945 | else | |||
946 | *pBuf = (nDigit + '0' ); | |||
947 | pBuf++; | |||
948 | } | |||
949 | while ( nValue > 0 ); | |||
950 | ||||
951 | /* copy the values in the right direction into the destination buffer */ | |||
952 | do | |||
953 | { | |||
954 | pBuf--; | |||
955 | *pStr = *pBuf; | |||
956 | pStr++; | |||
957 | nLen++; | |||
958 | } | |||
959 | while ( pBuf != aBuf ); | |||
960 | *pStr = 0; | |||
961 | ||||
962 | return nLen; | |||
963 | } | |||
964 | ||||
965 | /* ----------------------------------------------------------------------- */ | |||
966 | ||||
967 | sal_Bool SAL_CALL IMPL_RTL_STRNAME( toBoolean )( const IMPL_RTL_STRCODE* pStr ) | |||
968 | SAL_THROW_EXTERN_C()throw () | |||
969 | { | |||
970 | assert(pStr)(static_cast <bool> (pStr) ? void (0) : __assert_fail ( "pStr", "/home/maarten/src/libreoffice/core/sal/rtl/strtmpl.cxx" , 970, __extension__ __PRETTY_FUNCTION__)); | |||
971 | if ( *pStr == '1' ) | |||
972 | return true; | |||
973 | ||||
974 | if ( (*pStr == 'T') || (*pStr == 't') ) | |||
975 | { | |||
976 | pStr++; | |||
977 | if ( (*pStr == 'R') || (*pStr == 'r') ) | |||
978 | { | |||
979 | pStr++; | |||
980 | if ( (*pStr == 'U') || (*pStr == 'u') ) | |||
981 | { | |||
982 | pStr++; | |||
983 | if ( (*pStr == 'E') || (*pStr == 'e') ) | |||
984 | return true; | |||
985 | } | |||
986 | } | |||
987 | } | |||
988 | ||||
989 | return false; | |||
990 | } | |||
991 | ||||
992 | /* ----------------------------------------------------------------------- */ | |||
993 | namespace { | |||
994 | template<typename T, typename U> T IMPL_RTL_STRNAME( toInt_WithLength )( const IMPL_RTL_STRCODE* pStr, | |||
995 | sal_Int16 nRadix, | |||
996 | sal_Int32 nStrLength ) | |||
997 | { | |||
998 | static_assert(std::numeric_limits<T>::is_signed, "is signed"); | |||
999 | assert( nRadix >= RTL_STR_MIN_RADIX && nRadix <= RTL_STR_MAX_RADIX )(static_cast <bool> (nRadix >= 2 && nRadix <= 36) ? void (0) : __assert_fail ("nRadix >= RTL_STR_MIN_RADIX && nRadix <= RTL_STR_MAX_RADIX" , "/home/maarten/src/libreoffice/core/sal/rtl/strtmpl.cxx", 999 , __extension__ __PRETTY_FUNCTION__)); | |||
1000 | assert( nStrLength >= 0 )(static_cast <bool> (nStrLength >= 0) ? void (0) : __assert_fail ("nStrLength >= 0", "/home/maarten/src/libreoffice/core/sal/rtl/strtmpl.cxx" , 1000, __extension__ __PRETTY_FUNCTION__)); | |||
1001 | bool bNeg; | |||
1002 | sal_Int16 nDigit; | |||
1003 | U n = 0; | |||
1004 | const IMPL_RTL_STRCODE* pEnd = pStr + nStrLength; | |||
1005 | ||||
1006 | if ( (nRadix < RTL_STR_MIN_RADIX2) || (nRadix > RTL_STR_MAX_RADIX36) ) | |||
1007 | nRadix = 10; | |||
1008 | ||||
1009 | /* Skip whitespaces */ | |||
1010 | while ( pStr != pEnd && rtl_ImplIsWhitespace( IMPL_RTL_USTRCODE( *pStr ) ) ) | |||
1011 | pStr++; | |||
1012 | ||||
1013 | if ( *pStr == '-' ) | |||
1014 | { | |||
1015 | bNeg = true; | |||
1016 | pStr++; | |||
1017 | } | |||
1018 | else | |||
1019 | { | |||
1020 | if ( *pStr == '+' ) | |||
1021 | pStr++; | |||
1022 | bNeg = false; | |||
1023 | } | |||
1024 | ||||
1025 | T nDiv; | |||
1026 | sal_Int16 nMod; | |||
1027 | if ( bNeg ) | |||
1028 | { | |||
1029 | nDiv = std::numeric_limits<T>::min() / nRadix; | |||
1030 | nMod = std::numeric_limits<T>::min() % nRadix; | |||
1031 | // Cater for C++03 implementations that round the quotient down | |||
1032 | // instead of truncating towards zero as mandated by C++11: | |||
1033 | if ( nMod > 0 ) | |||
1034 | { | |||
1035 | --nDiv; | |||
1036 | nMod -= nRadix; | |||
1037 | } | |||
1038 | nDiv = -nDiv; | |||
1039 | nMod = -nMod; | |||
1040 | } | |||
1041 | else | |||
1042 | { | |||
1043 | nDiv = std::numeric_limits<T>::max() / nRadix; | |||
1044 | nMod = std::numeric_limits<T>::max() % nRadix; | |||
1045 | } | |||
1046 | ||||
1047 | while ( pStr != pEnd ) | |||
1048 | { | |||
1049 | nDigit = rtl_ImplGetDigit( IMPL_RTL_USTRCODE( *pStr ), nRadix ); | |||
1050 | if ( nDigit < 0 ) | |||
1051 | break; | |||
1052 | assert(nDiv > 0)(static_cast <bool> (nDiv > 0) ? void (0) : __assert_fail ("nDiv > 0", "/home/maarten/src/libreoffice/core/sal/rtl/strtmpl.cxx" , 1052, __extension__ __PRETTY_FUNCTION__)); | |||
1053 | if( static_cast<U>( nMod < nDigit ? nDiv-1 : nDiv ) < n ) | |||
1054 | return 0; | |||
1055 | ||||
1056 | n *= nRadix; | |||
1057 | n += nDigit; | |||
1058 | ||||
1059 | pStr++; | |||
1060 | } | |||
1061 | ||||
1062 | if ( bNeg ) | |||
1063 | return n == static_cast<U>(std::numeric_limits<T>::min()) | |||
1064 | ? std::numeric_limits<T>::min() : -static_cast<T>(n); | |||
1065 | else | |||
1066 | return static_cast<T>(n); | |||
1067 | } | |||
1068 | } | |||
1069 | ||||
1070 | sal_Int32 SAL_CALL IMPL_RTL_STRNAME( toInt32 )( const IMPL_RTL_STRCODE* pStr, | |||
1071 | sal_Int16 nRadix ) | |||
1072 | SAL_THROW_EXTERN_C()throw () | |||
1073 | { | |||
1074 | assert(pStr)(static_cast <bool> (pStr) ? void (0) : __assert_fail ( "pStr", "/home/maarten/src/libreoffice/core/sal/rtl/strtmpl.cxx" , 1074, __extension__ __PRETTY_FUNCTION__)); | |||
1075 | return IMPL_RTL_STRNAME( toInt_WithLength )<sal_Int32, sal_uInt32>(pStr, nRadix, IMPL_RTL_STRNAME( getLength )(pStr)); | |||
1076 | } | |||
1077 | ||||
1078 | sal_Int64 SAL_CALL IMPL_RTL_STRNAME( toInt64 )( const IMPL_RTL_STRCODE* pStr, | |||
1079 | sal_Int16 nRadix ) | |||
1080 | SAL_THROW_EXTERN_C()throw () | |||
1081 | { | |||
1082 | assert(pStr)(static_cast <bool> (pStr) ? void (0) : __assert_fail ( "pStr", "/home/maarten/src/libreoffice/core/sal/rtl/strtmpl.cxx" , 1082, __extension__ __PRETTY_FUNCTION__)); | |||
1083 | return IMPL_RTL_STRNAME( toInt_WithLength )<sal_Int64, sal_uInt64>(pStr, nRadix, IMPL_RTL_STRNAME( getLength )(pStr)); | |||
1084 | } | |||
1085 | ||||
1086 | sal_Int64 SAL_CALL IMPL_RTL_STRNAME( toInt64_WithLength )( const IMPL_RTL_STRCODE* pStr, | |||
1087 | sal_Int16 nRadix, | |||
1088 | sal_Int32 nStrLength) | |||
1089 | SAL_THROW_EXTERN_C()throw () | |||
1090 | { | |||
1091 | assert(pStr)(static_cast <bool> (pStr) ? void (0) : __assert_fail ( "pStr", "/home/maarten/src/libreoffice/core/sal/rtl/strtmpl.cxx" , 1091, __extension__ __PRETTY_FUNCTION__)); | |||
1092 | return IMPL_RTL_STRNAME( toInt_WithLength )<sal_Int64, sal_uInt64>(pStr, nRadix, nStrLength); | |||
1093 | } | |||
1094 | ||||
1095 | /* ----------------------------------------------------------------------- */ | |||
1096 | namespace { | |||
1097 | template <typename T> T IMPL_RTL_STRNAME( toUInt )( const IMPL_RTL_STRCODE* pStr, | |||
1098 | sal_Int16 nRadix ) | |||
1099 | { | |||
1100 | static_assert(!std::numeric_limits<T>::is_signed, "is not signed"); | |||
1101 | assert( nRadix >= RTL_STR_MIN_RADIX && nRadix <= RTL_STR_MAX_RADIX )(static_cast <bool> (nRadix >= 2 && nRadix <= 36) ? void (0) : __assert_fail ("nRadix >= RTL_STR_MIN_RADIX && nRadix <= RTL_STR_MAX_RADIX" , "/home/maarten/src/libreoffice/core/sal/rtl/strtmpl.cxx", 1101 , __extension__ __PRETTY_FUNCTION__)); | |||
1102 | sal_Int16 nDigit; | |||
1103 | T n = 0; | |||
1104 | ||||
1105 | if ( (nRadix < RTL_STR_MIN_RADIX2) || (nRadix > RTL_STR_MAX_RADIX36) ) | |||
1106 | nRadix = 10; | |||
1107 | ||||
1108 | /* Skip whitespaces */ | |||
1109 | while ( *pStr && rtl_ImplIsWhitespace( IMPL_RTL_USTRCODE( *pStr ) ) ) | |||
1110 | ++pStr; | |||
1111 | ||||
1112 | // skip optional explicit sign | |||
1113 | if ( *pStr == '+' ) | |||
1114 | ++pStr; | |||
1115 | ||||
1116 | T nDiv = std::numeric_limits<T>::max() / nRadix; | |||
1117 | sal_Int16 nMod = std::numeric_limits<T>::max() % nRadix; | |||
1118 | while ( *pStr ) | |||
1119 | { | |||
1120 | nDigit = rtl_ImplGetDigit( IMPL_RTL_USTRCODE( *pStr ), nRadix ); | |||
1121 | if ( nDigit < 0 ) | |||
1122 | break; | |||
1123 | if( ( nMod < nDigit ? nDiv-1 : nDiv ) < n ) | |||
1124 | return 0; | |||
1125 | ||||
1126 | n *= nRadix; | |||
1127 | n += nDigit; | |||
1128 | ||||
1129 | ++pStr; | |||
1130 | } | |||
1131 | ||||
1132 | return n; | |||
1133 | } | |||
1134 | } | |||
1135 | ||||
1136 | sal_uInt32 SAL_CALL IMPL_RTL_STRNAME( toUInt32 )( const IMPL_RTL_STRCODE* pStr, | |||
1137 | sal_Int16 nRadix ) | |||
1138 | SAL_THROW_EXTERN_C()throw () | |||
1139 | { | |||
1140 | assert(pStr)(static_cast <bool> (pStr) ? void (0) : __assert_fail ( "pStr", "/home/maarten/src/libreoffice/core/sal/rtl/strtmpl.cxx" , 1140, __extension__ __PRETTY_FUNCTION__)); | |||
1141 | return IMPL_RTL_STRNAME( toUInt )<sal_uInt32>(pStr, nRadix); | |||
1142 | } | |||
1143 | ||||
1144 | sal_uInt64 SAL_CALL IMPL_RTL_STRNAME( toUInt64 )( const IMPL_RTL_STRCODE* pStr, | |||
1145 | sal_Int16 nRadix ) | |||
1146 | SAL_THROW_EXTERN_C()throw () | |||
1147 | { | |||
1148 | assert(pStr)(static_cast <bool> (pStr) ? void (0) : __assert_fail ( "pStr", "/home/maarten/src/libreoffice/core/sal/rtl/strtmpl.cxx" , 1148, __extension__ __PRETTY_FUNCTION__)); | |||
1149 | return IMPL_RTL_STRNAME( toUInt )<sal_uInt64>(pStr, nRadix); | |||
1150 | } | |||
1151 | ||||
1152 | /* ======================================================================= */ | |||
1153 | /* Internal String-Class help functions */ | |||
1154 | /* ======================================================================= */ | |||
1155 | ||||
1156 | IMPL_RTL_STRINGDATA* IMPL_RTL_STRINGNAME( ImplAlloc )( sal_Int32 nLen ) | |||
1157 | { | |||
1158 | IMPL_RTL_STRINGDATA * pData | |||
1159 | = (sal::static_int_cast< sal_uInt32 >(nLen) | |||
1160 | <= ((SAL_MAX_UINT32((sal_uInt32) 0xFFFFFFFF) - sizeof (IMPL_RTL_STRINGDATA)) | |||
1161 | / sizeof (IMPL_RTL_STRCODE))) | |||
1162 | ? static_cast<IMPL_RTL_STRINGDATA *>(rtl_allocateString( | |||
1163 | sizeof (IMPL_RTL_STRINGDATA) + nLen * sizeof (IMPL_RTL_STRCODE))) | |||
1164 | : nullptr; | |||
1165 | if (pData != nullptr) { | |||
1166 | pData->refCount = 1; | |||
1167 | pData->length = nLen; | |||
1168 | pData->buffer[nLen] = 0; | |||
1169 | } | |||
1170 | return pData; | |||
1171 | } | |||
1172 | ||||
1173 | /* ----------------------------------------------------------------------- */ | |||
1174 | ||||
1175 | static IMPL_RTL_STRCODE* IMPL_RTL_STRINGNAME( ImplNewCopy )( IMPL_RTL_STRINGDATA** ppThis, | |||
1176 | IMPL_RTL_STRINGDATA* pStr, | |||
1177 | sal_Int32 nCount ) | |||
1178 | { | |||
1179 | assert(nCount >= 0)(static_cast <bool> (nCount >= 0) ? void (0) : __assert_fail ("nCount >= 0", "/home/maarten/src/libreoffice/core/sal/rtl/strtmpl.cxx" , 1179, __extension__ __PRETTY_FUNCTION__)); | |||
1180 | IMPL_RTL_STRCODE* pDest; | |||
1181 | const IMPL_RTL_STRCODE* pSrc; | |||
1182 | IMPL_RTL_STRINGDATA* pData = IMPL_RTL_STRINGNAME( ImplAlloc )( pStr->length ); | |||
1183 | OSL_ASSERT(pData != nullptr)do { if (true && (!(pData != nullptr))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/sal/rtl/strtmpl.cxx" ":" "1183" ": "), "OSL_ASSERT: %s", "pData != nullptr"); } } while (false); | |||
1184 | ||||
1185 | pDest = pData->buffer; | |||
1186 | pSrc = pStr->buffer; | |||
1187 | ||||
1188 | memcpy( pDest, pSrc, nCount * sizeof(IMPL_RTL_STRCODE)); | |||
1189 | ||||
1190 | *ppThis = pData; | |||
1191 | ||||
1192 | RTL_LOG_STRING_NEW( pData )do { ; __asm__ __volatile__ ("990: nop" "\n" ".pushsection .note.stapsdt" "," "\"?\"" "," "\"note\"" "\n" ".balign 4" "\n" ".4byte 992f-991f" "," "994f-993f" "," "3" "\n" "991: .asciz \"stapsdt\"" "\n" "992: .balign 4" "\n" "993: .8byte 990b" "\n" ".8byte _.stapsdt.base" "\n" ".8byte 0" "\n" ".asciz \"libreoffice\"" "\n" ".asciz \"new_string_RTL_LOG_STRING_BITS\"" "\n" ".asciz \"%n[_SDT_S1]@%[_SDT_A1] %n[_SDT_S2]@%[_SDT_A2] %n[_SDT_S3]@%[_SDT_A3] %n[_SDT_S4]@%[_SDT_A4]\"" "\n" "994: .balign 4" "\n" ".popsection" "\n" :: [_SDT_S1] "n" (((!(__builtin_classify_type (pData) == 14 || __builtin_classify_type (pData) == 5) && __sdt_type<__typeof (pData)>:: __sdt_signed) ? 1 : -1) * (int) ((__builtin_classify_type (pData ) == 14 || __builtin_classify_type (pData) == 5) ? sizeof (void *) : sizeof (pData))), [_SDT_A1] "nor" ((pData)), [_SDT_S2] "n" (((!(__builtin_classify_type ((pData)->refCount) == 14 || __builtin_classify_type ((pData)->refCount) == 5) && __sdt_type<__typeof ((pData)->refCount)>::__sdt_signed ) ? 1 : -1) * (int) ((__builtin_classify_type ((pData)->refCount ) == 14 || __builtin_classify_type ((pData)->refCount) == 5 ) ? sizeof (void *) : sizeof ((pData)->refCount))), [_SDT_A2 ] "nor" (((pData)->refCount)), [_SDT_S3] "n" (((!(__builtin_classify_type ((pData)->length) == 14 || __builtin_classify_type ((pData )->length) == 5) && __sdt_type<__typeof ((pData )->length)>::__sdt_signed) ? 1 : -1) * (int) ((__builtin_classify_type ((pData)->length) == 14 || __builtin_classify_type ((pData )->length) == 5) ? sizeof (void *) : sizeof ((pData)->length ))), [_SDT_A3] "nor" (((pData)->length)), [_SDT_S4] "n" (( (!(__builtin_classify_type ((pData)->buffer) == 14 || __builtin_classify_type ((pData)->buffer) == 5) && __sdt_type<__typeof ((pData)->buffer)>::__sdt_signed) ? 1 : -1) * (int) (( __builtin_classify_type ((pData)->buffer) == 14 || __builtin_classify_type ((pData)->buffer) == 5) ? sizeof (void *) : sizeof ((pData )->buffer))), [_SDT_A4] "nor" (((pData)->buffer))); __asm__ __volatile__ (".ifndef _.stapsdt.base" "\n" ".pushsection .stapsdt.base" "," "\"aG\"" "," "\"progbits\"" "," ".stapsdt.base" "," "comdat" "\n" ".weak _.stapsdt.base" "\n" ".hidden _.stapsdt.base" "\n" "_.stapsdt.base: .space 1" "\n" ".size _.stapsdt.base" "," "1" "\n" ".popsection" "\n" ".endif" "\n"); } while (0); | |||
1193 | return pDest + nCount; | |||
1194 | } | |||
1195 | ||||
1196 | /* ======================================================================= */ | |||
1197 | /* String-Class functions */ | |||
1198 | /* ======================================================================= */ | |||
1199 | ||||
1200 | namespace { | |||
1201 | ||||
1202 | void IMPL_RTL_ACQUIRE(IMPL_RTL_STRINGDATA * pThis) | |||
1203 | { | |||
1204 | if (!SAL_STRING_IS_STATIC (pThis)((pThis)->refCount & 0x40000000)) | |||
1205 | osl_atomic_increment( &((pThis)->refCount) )__sync_add_and_fetch((&((pThis)->refCount)), 1); | |||
1206 | } | |||
1207 | ||||
1208 | } | |||
1209 | ||||
1210 | /* ----------------------------------------------------------------------- */ | |||
1211 | ||||
1212 | void SAL_CALL IMPL_RTL_STRINGNAME( acquire )( IMPL_RTL_STRINGDATA* pThis ) | |||
1213 | SAL_THROW_EXTERN_C()throw () | |||
1214 | { | |||
1215 | IMPL_RTL_ACQUIRE( pThis ); | |||
1216 | } | |||
1217 | ||||
1218 | /* ----------------------------------------------------------------------- */ | |||
1219 | ||||
1220 | void SAL_CALL IMPL_RTL_STRINGNAME( release )( IMPL_RTL_STRINGDATA* pThis ) | |||
1221 | SAL_THROW_EXTERN_C()throw () | |||
1222 | { | |||
1223 | if (SAL_UNLIKELY(SAL_STRING_IS_STATIC (pThis))__builtin_expect(__extension__ ({ int sal_boolean_var_; if (( ((pThis)->refCount & 0x40000000))) sal_boolean_var_ = 1 ; else sal_boolean_var_ = 0; sal_boolean_var_; }), 0)) | |||
1224 | return; | |||
1225 | ||||
1226 | /* OString doesn't have an 'intern' */ | |||
1227 | #if IMPL_RTL_IS_USTRING | |||
1228 | if (SAL_STRING_IS_INTERN (pThis)((pThis)->refCount & 0x80000000)) | |||
1229 | { | |||
1230 | internRelease (pThis); | |||
1231 | return; | |||
1232 | } | |||
1233 | #endif | |||
1234 | ||||
1235 | if ( !osl_atomic_decrement( &(pThis->refCount) )__sync_sub_and_fetch((&(pThis->refCount)), 1) ) | |||
1236 | { | |||
1237 | RTL_LOG_STRING_DELETE( pThis )do { ; __asm__ __volatile__ ("990: nop" "\n" ".pushsection .note.stapsdt" "," "\"?\"" "," "\"note\"" "\n" ".balign 4" "\n" ".4byte 992f-991f" "," "994f-993f" "," "3" "\n" "991: .asciz \"stapsdt\"" "\n" "992: .balign 4" "\n" "993: .8byte 990b" "\n" ".8byte _.stapsdt.base" "\n" ".8byte 0" "\n" ".asciz \"libreoffice\"" "\n" ".asciz \"delete_string_RTL_LOG_STRING_BITS\"" "\n" ".asciz \"%n[_SDT_S1]@%[_SDT_A1] %n[_SDT_S2]@%[_SDT_A2] %n[_SDT_S3]@%[_SDT_A3] %n[_SDT_S4]@%[_SDT_A4]\"" "\n" "994: .balign 4" "\n" ".popsection" "\n" :: [_SDT_S1] "n" (((!(__builtin_classify_type (pThis) == 14 || __builtin_classify_type (pThis) == 5) && __sdt_type<__typeof (pThis)>:: __sdt_signed) ? 1 : -1) * (int) ((__builtin_classify_type (pThis ) == 14 || __builtin_classify_type (pThis) == 5) ? sizeof (void *) : sizeof (pThis))), [_SDT_A1] "nor" ((pThis)), [_SDT_S2] "n" (((!(__builtin_classify_type ((pThis)->refCount) == 14 || __builtin_classify_type ((pThis)->refCount) == 5) && __sdt_type<__typeof ((pThis)->refCount)>::__sdt_signed ) ? 1 : -1) * (int) ((__builtin_classify_type ((pThis)->refCount ) == 14 || __builtin_classify_type ((pThis)->refCount) == 5 ) ? sizeof (void *) : sizeof ((pThis)->refCount))), [_SDT_A2 ] "nor" (((pThis)->refCount)), [_SDT_S3] "n" (((!(__builtin_classify_type ((pThis)->length) == 14 || __builtin_classify_type ((pThis )->length) == 5) && __sdt_type<__typeof ((pThis )->length)>::__sdt_signed) ? 1 : -1) * (int) ((__builtin_classify_type ((pThis)->length) == 14 || __builtin_classify_type ((pThis )->length) == 5) ? sizeof (void *) : sizeof ((pThis)->length ))), [_SDT_A3] "nor" (((pThis)->length)), [_SDT_S4] "n" (( (!(__builtin_classify_type ((pThis)->buffer) == 14 || __builtin_classify_type ((pThis)->buffer) == 5) && __sdt_type<__typeof ((pThis)->buffer)>::__sdt_signed) ? 1 : -1) * (int) (( __builtin_classify_type ((pThis)->buffer) == 14 || __builtin_classify_type ((pThis)->buffer) == 5) ? sizeof (void *) : sizeof ((pThis )->buffer))), [_SDT_A4] "nor" (((pThis)->buffer))); __asm__ __volatile__ (".ifndef _.stapsdt.base" "\n" ".pushsection .stapsdt.base" "," "\"aG\"" "," "\"progbits\"" "," ".stapsdt.base" "," "comdat" "\n" ".weak _.stapsdt.base" "\n" ".hidden _.stapsdt.base" "\n" "_.stapsdt.base: .space 1" "\n" ".size _.stapsdt.base" "," "1" "\n" ".popsection" "\n" ".endif" "\n"); } while (0); | |||
1238 | rtl_freeString( pThis ); | |||
1239 | } | |||
1240 | } | |||
1241 | ||||
1242 | /* ----------------------------------------------------------------------- */ | |||
1243 | ||||
1244 | void SAL_CALL IMPL_RTL_STRINGNAME( new )( IMPL_RTL_STRINGDATA** ppThis ) | |||
1245 | SAL_THROW_EXTERN_C()throw () | |||
1246 | { | |||
1247 | assert(ppThis)(static_cast <bool> (ppThis) ? void (0) : __assert_fail ("ppThis", "/home/maarten/src/libreoffice/core/sal/rtl/strtmpl.cxx" , 1247, __extension__ __PRETTY_FUNCTION__)); | |||
1248 | if ( *ppThis) | |||
1249 | IMPL_RTL_STRINGNAME( release )( *ppThis ); | |||
1250 | ||||
1251 | *ppThis = const_cast<IMPL_RTL_STRINGDATA*>(&IMPL_RTL_EMPTYSTRING); | |||
1252 | } | |||
1253 | ||||
1254 | /* ----------------------------------------------------------------------- */ | |||
1255 | ||||
1256 | IMPL_RTL_STRINGDATA* SAL_CALL IMPL_RTL_STRINGNAME( alloc )( sal_Int32 nLen ) | |||
1257 | SAL_THROW_EXTERN_C()throw () | |||
1258 | { | |||
1259 | assert(nLen >= 0)(static_cast <bool> (nLen >= 0) ? void (0) : __assert_fail ("nLen >= 0", "/home/maarten/src/libreoffice/core/sal/rtl/strtmpl.cxx" , 1259, __extension__ __PRETTY_FUNCTION__)); | |||
1260 | return IMPL_RTL_STRINGNAME( ImplAlloc )( nLen ); | |||
1261 | } | |||
1262 | ||||
1263 | /* ----------------------------------------------------------------------- */ | |||
1264 | ||||
1265 | void SAL_CALL IMPL_RTL_STRINGNAME( new_WithLength )( IMPL_RTL_STRINGDATA** ppThis, sal_Int32 nLen ) | |||
1266 | SAL_THROW_EXTERN_C()throw () | |||
1267 | { | |||
1268 | assert(ppThis)(static_cast <bool> (ppThis) ? void (0) : __assert_fail ("ppThis", "/home/maarten/src/libreoffice/core/sal/rtl/strtmpl.cxx" , 1268, __extension__ __PRETTY_FUNCTION__)); | |||
1269 | assert(nLen >= 0)(static_cast <bool> (nLen >= 0) ? void (0) : __assert_fail ("nLen >= 0", "/home/maarten/src/libreoffice/core/sal/rtl/strtmpl.cxx" , 1269, __extension__ __PRETTY_FUNCTION__)); | |||
1270 | if ( nLen <= 0 ) | |||
1271 | IMPL_RTL_STRINGNAME( new )( ppThis ); | |||
1272 | else | |||
1273 | { | |||
1274 | if ( *ppThis) | |||
1275 | IMPL_RTL_STRINGNAME( release )( *ppThis ); | |||
1276 | ||||
1277 | *ppThis = IMPL_RTL_STRINGNAME( ImplAlloc )( nLen ); | |||
1278 | OSL_ASSERT(*ppThis != nullptr)do { if (true && (!(*ppThis != nullptr))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/sal/rtl/strtmpl.cxx" ":" "1278" ": "), "OSL_ASSERT: %s", "*ppThis != nullptr"); } } while (false); | |||
1279 | (*ppThis)->length = 0; | |||
1280 | ||||
1281 | IMPL_RTL_STRCODE* pTempStr = (*ppThis)->buffer; | |||
1282 | memset(pTempStr, 0, nLen*sizeof(IMPL_RTL_STRCODE)); | |||
1283 | } | |||
1284 | } | |||
1285 | ||||
1286 | /* ----------------------------------------------------------------------- */ | |||
1287 | ||||
1288 | void SAL_CALL IMPL_RTL_STRINGNAME( newFromString )( IMPL_RTL_STRINGDATA** ppThis, | |||
1289 | const IMPL_RTL_STRINGDATA* pStr ) | |||
1290 | SAL_THROW_EXTERN_C()throw () | |||
1291 | { | |||
1292 | assert(ppThis)(static_cast <bool> (ppThis) ? void (0) : __assert_fail ("ppThis", "/home/maarten/src/libreoffice/core/sal/rtl/strtmpl.cxx" , 1292, __extension__ __PRETTY_FUNCTION__)); | |||
1293 | assert(pStr)(static_cast <bool> (pStr) ? void (0) : __assert_fail ( "pStr", "/home/maarten/src/libreoffice/core/sal/rtl/strtmpl.cxx" , 1293, __extension__ __PRETTY_FUNCTION__)); | |||
1294 | IMPL_RTL_STRINGDATA* pOrg; | |||
1295 | ||||
1296 | if ( !pStr->length ) | |||
1297 | { | |||
1298 | IMPL_RTL_STRINGNAME( new )( ppThis ); | |||
1299 | return; | |||
1300 | } | |||
1301 | ||||
1302 | pOrg = *ppThis; | |||
1303 | *ppThis = IMPL_RTL_STRINGNAME( ImplAlloc )( pStr->length ); | |||
1304 | OSL_ASSERT(*ppThis != nullptr)do { if (true && (!(*ppThis != nullptr))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/sal/rtl/strtmpl.cxx" ":" "1304" ": "), "OSL_ASSERT: %s", "*ppThis != nullptr"); } } while (false); | |||
1305 | rtl_str_ImplCopy( (*ppThis)->buffer, pStr->buffer, pStr->length ); | |||
1306 | RTL_LOG_STRING_NEW( *ppThis )do { ; __asm__ __volatile__ ("990: nop" "\n" ".pushsection .note.stapsdt" "," "\"?\"" "," "\"note\"" "\n" ".balign 4" "\n" ".4byte 992f-991f" "," "994f-993f" "," "3" "\n" "991: .asciz \"stapsdt\"" "\n" "992: .balign 4" "\n" "993: .8byte 990b" "\n" ".8byte _.stapsdt.base" "\n" ".8byte 0" "\n" ".asciz \"libreoffice\"" "\n" ".asciz \"new_string_RTL_LOG_STRING_BITS\"" "\n" ".asciz \"%n[_SDT_S1]@%[_SDT_A1] %n[_SDT_S2]@%[_SDT_A2] %n[_SDT_S3]@%[_SDT_A3] %n[_SDT_S4]@%[_SDT_A4]\"" "\n" "994: .balign 4" "\n" ".popsection" "\n" :: [_SDT_S1] "n" (((!(__builtin_classify_type (*ppThis) == 14 || __builtin_classify_type (*ppThis) == 5) && __sdt_type<__typeof (*ppThis)> ::__sdt_signed) ? 1 : -1) * (int) ((__builtin_classify_type ( *ppThis) == 14 || __builtin_classify_type (*ppThis) == 5) ? sizeof (void *) : sizeof (*ppThis))), [_SDT_A1] "nor" ((*ppThis)), [ _SDT_S2] "n" (((!(__builtin_classify_type ((*ppThis)->refCount ) == 14 || __builtin_classify_type ((*ppThis)->refCount) == 5) && __sdt_type<__typeof ((*ppThis)->refCount )>::__sdt_signed) ? 1 : -1) * (int) ((__builtin_classify_type ((*ppThis)->refCount) == 14 || __builtin_classify_type (( *ppThis)->refCount) == 5) ? sizeof (void *) : sizeof ((*ppThis )->refCount))), [_SDT_A2] "nor" (((*ppThis)->refCount)) , [_SDT_S3] "n" (((!(__builtin_classify_type ((*ppThis)->length ) == 14 || __builtin_classify_type ((*ppThis)->length) == 5 ) && __sdt_type<__typeof ((*ppThis)->length)> ::__sdt_signed) ? 1 : -1) * (int) ((__builtin_classify_type ( (*ppThis)->length) == 14 || __builtin_classify_type ((*ppThis )->length) == 5) ? sizeof (void *) : sizeof ((*ppThis)-> length))), [_SDT_A3] "nor" (((*ppThis)->length)), [_SDT_S4 ] "n" (((!(__builtin_classify_type ((*ppThis)->buffer) == 14 || __builtin_classify_type ((*ppThis)->buffer) == 5) && __sdt_type<__typeof ((*ppThis)->buffer)>::__sdt_signed ) ? 1 : -1) * (int) ((__builtin_classify_type ((*ppThis)-> buffer) == 14 || __builtin_classify_type ((*ppThis)->buffer ) == 5) ? sizeof (void *) : sizeof ((*ppThis)->buffer))), [ _SDT_A4] "nor" (((*ppThis)->buffer))); __asm__ __volatile__ (".ifndef _.stapsdt.base" "\n" ".pushsection .stapsdt.base" "," "\"aG\"" "," "\"progbits\"" "," ".stapsdt.base" "," "comdat" "\n" ".weak _.stapsdt.base" "\n" ".hidden _.stapsdt.base" "\n" "_.stapsdt.base: .space 1" "\n" ".size _.stapsdt.base" "," "1" "\n" ".popsection" "\n" ".endif" "\n"); } while (0); | |||
1307 | ||||
1308 | /* must be done last, if pStr == *ppThis */ | |||
1309 | if ( pOrg ) | |||
1310 | IMPL_RTL_STRINGNAME( release )( pOrg ); | |||
1311 | } | |||
1312 | ||||
1313 | /* ----------------------------------------------------------------------- */ | |||
1314 | ||||
1315 | void SAL_CALL IMPL_RTL_STRINGNAME( newFromStr )( IMPL_RTL_STRINGDATA** ppThis, | |||
1316 | const IMPL_RTL_STRCODE* pCharStr ) | |||
1317 | SAL_THROW_EXTERN_C()throw () | |||
1318 | { | |||
1319 | assert(ppThis)(static_cast <bool> (ppThis) ? void (0) : __assert_fail ("ppThis", "/home/maarten/src/libreoffice/core/sal/rtl/strtmpl.cxx" , 1319, __extension__ __PRETTY_FUNCTION__)); | |||
1320 | IMPL_RTL_STRINGDATA* pOrg; | |||
1321 | sal_Int32 nLen; | |||
1322 | ||||
1323 | if ( pCharStr ) | |||
1324 | { | |||
1325 | nLen = IMPL_RTL_STRNAME( getLength )( pCharStr ); | |||
1326 | } | |||
1327 | else | |||
1328 | nLen = 0; | |||
1329 | ||||
1330 | if ( !nLen ) | |||
1331 | { | |||
1332 | IMPL_RTL_STRINGNAME( new )( ppThis ); | |||
1333 | return; | |||
1334 | } | |||
1335 | ||||
1336 | pOrg = *ppThis; | |||
1337 | *ppThis = IMPL_RTL_STRINGNAME( ImplAlloc )( nLen ); | |||
1338 | OSL_ASSERT(*ppThis != nullptr)do { if (true && (!(*ppThis != nullptr))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/sal/rtl/strtmpl.cxx" ":" "1338" ": "), "OSL_ASSERT: %s", "*ppThis != nullptr"); } } while (false); | |||
1339 | rtl_str_ImplCopy( (*ppThis)->buffer, pCharStr, nLen ); | |||
1340 | RTL_LOG_STRING_NEW( *ppThis )do { ; __asm__ __volatile__ ("990: nop" "\n" ".pushsection .note.stapsdt" "," "\"?\"" "," "\"note\"" "\n" ".balign 4" "\n" ".4byte 992f-991f" "," "994f-993f" "," "3" "\n" "991: .asciz \"stapsdt\"" "\n" "992: .balign 4" "\n" "993: .8byte 990b" "\n" ".8byte _.stapsdt.base" "\n" ".8byte 0" "\n" ".asciz \"libreoffice\"" "\n" ".asciz \"new_string_RTL_LOG_STRING_BITS\"" "\n" ".asciz \"%n[_SDT_S1]@%[_SDT_A1] %n[_SDT_S2]@%[_SDT_A2] %n[_SDT_S3]@%[_SDT_A3] %n[_SDT_S4]@%[_SDT_A4]\"" "\n" "994: .balign 4" "\n" ".popsection" "\n" :: [_SDT_S1] "n" (((!(__builtin_classify_type (*ppThis) == 14 || __builtin_classify_type (*ppThis) == 5) && __sdt_type<__typeof (*ppThis)> ::__sdt_signed) ? 1 : -1) * (int) ((__builtin_classify_type ( *ppThis) == 14 || __builtin_classify_type (*ppThis) == 5) ? sizeof (void *) : sizeof (*ppThis))), [_SDT_A1] "nor" ((*ppThis)), [ _SDT_S2] "n" (((!(__builtin_classify_type ((*ppThis)->refCount ) == 14 || __builtin_classify_type ((*ppThis)->refCount) == 5) && __sdt_type<__typeof ((*ppThis)->refCount )>::__sdt_signed) ? 1 : -1) * (int) ((__builtin_classify_type ((*ppThis)->refCount) == 14 || __builtin_classify_type (( *ppThis)->refCount) == 5) ? sizeof (void *) : sizeof ((*ppThis )->refCount))), [_SDT_A2] "nor" (((*ppThis)->refCount)) , [_SDT_S3] "n" (((!(__builtin_classify_type ((*ppThis)->length ) == 14 || __builtin_classify_type ((*ppThis)->length) == 5 ) && __sdt_type<__typeof ((*ppThis)->length)> ::__sdt_signed) ? 1 : -1) * (int) ((__builtin_classify_type ( (*ppThis)->length) == 14 || __builtin_classify_type ((*ppThis )->length) == 5) ? sizeof (void *) : sizeof ((*ppThis)-> length))), [_SDT_A3] "nor" (((*ppThis)->length)), [_SDT_S4 ] "n" (((!(__builtin_classify_type ((*ppThis)->buffer) == 14 || __builtin_classify_type ((*ppThis)->buffer) == 5) && __sdt_type<__typeof ((*ppThis)->buffer)>::__sdt_signed ) ? 1 : -1) * (int) ((__builtin_classify_type ((*ppThis)-> buffer) == 14 || __builtin_classify_type ((*ppThis)->buffer ) == 5) ? sizeof (void *) : sizeof ((*ppThis)->buffer))), [ _SDT_A4] "nor" (((*ppThis)->buffer))); __asm__ __volatile__ (".ifndef _.stapsdt.base" "\n" ".pushsection .stapsdt.base" "," "\"aG\"" "," "\"progbits\"" "," ".stapsdt.base" "," "comdat" "\n" ".weak _.stapsdt.base" "\n" ".hidden _.stapsdt.base" "\n" "_.stapsdt.base: .space 1" "\n" ".size _.stapsdt.base" "," "1" "\n" ".popsection" "\n" ".endif" "\n"); } while (0); | |||
1341 | ||||
1342 | /* must be done last, if pCharStr == *ppThis */ | |||
1343 | if ( pOrg ) | |||
1344 | IMPL_RTL_STRINGNAME( release )( pOrg ); | |||
1345 | } | |||
1346 | ||||
1347 | /* ----------------------------------------------------------------------- */ | |||
1348 | ||||
1349 | void SAL_CALL IMPL_RTL_STRINGNAME( newFromStr_WithLength )( IMPL_RTL_STRINGDATA** ppThis, | |||
1350 | const IMPL_RTL_STRCODE* pCharStr, | |||
1351 | sal_Int32 nLen ) | |||
1352 | SAL_THROW_EXTERN_C()throw () | |||
1353 | { | |||
1354 | assert(ppThis)(static_cast <bool> (ppThis) ? void (0) : __assert_fail ("ppThis", "/home/maarten/src/libreoffice/core/sal/rtl/strtmpl.cxx" , 1354, __extension__ __PRETTY_FUNCTION__)); | |||
1355 | assert(nLen >= 0)(static_cast <bool> (nLen >= 0) ? void (0) : __assert_fail ("nLen >= 0", "/home/maarten/src/libreoffice/core/sal/rtl/strtmpl.cxx" , 1355, __extension__ __PRETTY_FUNCTION__)); | |||
1356 | IMPL_RTL_STRINGDATA* pOrg; | |||
1357 | ||||
1358 | if ( !pCharStr || (nLen <= 0) ) | |||
1359 | { | |||
1360 | IMPL_RTL_STRINGNAME( new )( ppThis ); | |||
1361 | return; | |||
1362 | } | |||
1363 | ||||
1364 | pOrg = *ppThis; | |||
1365 | *ppThis = IMPL_RTL_STRINGNAME( ImplAlloc )( nLen ); | |||
1366 | OSL_ASSERT(*ppThis != nullptr)do { if (true && (!(*ppThis != nullptr))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/sal/rtl/strtmpl.cxx" ":" "1366" ": "), "OSL_ASSERT: %s", "*ppThis != nullptr"); } } while (false); | |||
1367 | rtl_str_ImplCopy( (*ppThis)->buffer, pCharStr, nLen ); | |||
1368 | ||||
1369 | RTL_LOG_STRING_NEW( *ppThis )do { ; __asm__ __volatile__ ("990: nop" "\n" ".pushsection .note.stapsdt" "," "\"?\"" "," "\"note\"" "\n" ".balign 4" "\n" ".4byte 992f-991f" "," "994f-993f" "," "3" "\n" "991: .asciz \"stapsdt\"" "\n" "992: .balign 4" "\n" "993: .8byte 990b" "\n" ".8byte _.stapsdt.base" "\n" ".8byte 0" "\n" ".asciz \"libreoffice\"" "\n" ".asciz \"new_string_RTL_LOG_STRING_BITS\"" "\n" ".asciz \"%n[_SDT_S1]@%[_SDT_A1] %n[_SDT_S2]@%[_SDT_A2] %n[_SDT_S3]@%[_SDT_A3] %n[_SDT_S4]@%[_SDT_A4]\"" "\n" "994: .balign 4" "\n" ".popsection" "\n" :: [_SDT_S1] "n" (((!(__builtin_classify_type (*ppThis) == 14 || __builtin_classify_type (*ppThis) == 5) && __sdt_type<__typeof (*ppThis)> ::__sdt_signed) ? 1 : -1) * (int) ((__builtin_classify_type ( *ppThis) == 14 || __builtin_classify_type (*ppThis) == 5) ? sizeof (void *) : sizeof (*ppThis))), [_SDT_A1] "nor" ((*ppThis)), [ _SDT_S2] "n" (((!(__builtin_classify_type ((*ppThis)->refCount ) == 14 || __builtin_classify_type ((*ppThis)->refCount) == 5) && __sdt_type<__typeof ((*ppThis)->refCount )>::__sdt_signed) ? 1 : -1) * (int) ((__builtin_classify_type ((*ppThis)->refCount) == 14 || __builtin_classify_type (( *ppThis)->refCount) == 5) ? sizeof (void *) : sizeof ((*ppThis )->refCount))), [_SDT_A2] "nor" (((*ppThis)->refCount)) , [_SDT_S3] "n" (((!(__builtin_classify_type ((*ppThis)->length ) == 14 || __builtin_classify_type ((*ppThis)->length) == 5 ) && __sdt_type<__typeof ((*ppThis)->length)> ::__sdt_signed) ? 1 : -1) * (int) ((__builtin_classify_type ( (*ppThis)->length) == 14 || __builtin_classify_type ((*ppThis )->length) == 5) ? sizeof (void *) : sizeof ((*ppThis)-> length))), [_SDT_A3] "nor" (((*ppThis)->length)), [_SDT_S4 ] "n" (((!(__builtin_classify_type ((*ppThis)->buffer) == 14 || __builtin_classify_type ((*ppThis)->buffer) == 5) && __sdt_type<__typeof ((*ppThis)->buffer)>::__sdt_signed ) ? 1 : -1) * (int) ((__builtin_classify_type ((*ppThis)-> buffer) == 14 || __builtin_classify_type ((*ppThis)->buffer ) == 5) ? sizeof (void *) : sizeof ((*ppThis)->buffer))), [ _SDT_A4] "nor" (((*ppThis)->buffer))); __asm__ __volatile__ (".ifndef _.stapsdt.base" "\n" ".pushsection .stapsdt.base" "," "\"aG\"" "," "\"progbits\"" "," ".stapsdt.base" "," "comdat" "\n" ".weak _.stapsdt.base" "\n" ".hidden _.stapsdt.base" "\n" "_.stapsdt.base: .space 1" "\n" ".size _.stapsdt.base" "," "1" "\n" ".popsection" "\n" ".endif" "\n"); } while (0); | |||
1370 | ||||
1371 | /* must be done last, if pCharStr == *ppThis */ | |||
1372 | if ( pOrg ) | |||
1373 | IMPL_RTL_STRINGNAME( release )( pOrg ); | |||
1374 | } | |||
1375 | ||||
1376 | /* ----------------------------------------------------------------------- */ | |||
1377 | ||||
1378 | void SAL_CALL IMPL_RTL_STRINGNAME( newFromSubString )( IMPL_RTL_STRINGDATA** ppThis, | |||
1379 | const IMPL_RTL_STRINGDATA* pFrom, | |||
1380 | sal_Int32 beginIndex, | |||
1381 | sal_Int32 count ) | |||
1382 | SAL_THROW_EXTERN_C()throw () | |||
1383 | { | |||
1384 | assert(ppThis)(static_cast <bool> (ppThis) ? void (0) : __assert_fail ("ppThis", "/home/maarten/src/libreoffice/core/sal/rtl/strtmpl.cxx" , 1384, __extension__ __PRETTY_FUNCTION__)); | |||
1385 | if ( beginIndex == 0 && count == pFrom->length ) | |||
1386 | { | |||
1387 | IMPL_RTL_STRINGNAME( assign )( ppThis, const_cast< IMPL_RTL_STRINGDATA * >( pFrom ) ); | |||
1388 | return; | |||
1389 | } | |||
1390 | if ( count < 0 || beginIndex < 0 || beginIndex + count > pFrom->length ) | |||
1391 | { | |||
1392 | assert(false)(static_cast <bool> (false) ? void (0) : __assert_fail ( "false", "/home/maarten/src/libreoffice/core/sal/rtl/strtmpl.cxx" , 1392, __extension__ __PRETTY_FUNCTION__)); // fail fast at least in debug builds | |||
1393 | IMPL_RTL_STRINGNAME( newFromLiteral )( ppThis, "!!br0ken!!", 10, 0 ); | |||
1394 | return; | |||
1395 | } | |||
1396 | ||||
1397 | IMPL_RTL_STRINGNAME( newFromStr_WithLength )( ppThis, pFrom->buffer + beginIndex, count ); | |||
1398 | } | |||
1399 | ||||
1400 | /* ----------------------------------------------------------------------- */ | |||
1401 | ||||
1402 | // Used when creating from string literals. | |||
1403 | void SAL_CALL IMPL_RTL_STRINGNAME( newFromLiteral )( IMPL_RTL_STRINGDATA** ppThis, | |||
1404 | const char* pCharStr, | |||
1405 | sal_Int32 nLen, | |||
1406 | sal_Int32 allocExtra ) | |||
1407 | SAL_THROW_EXTERN_C()throw () | |||
1408 | { | |||
1409 | assert(ppThis)(static_cast <bool> (ppThis) ? void (0) : __assert_fail ("ppThis", "/home/maarten/src/libreoffice/core/sal/rtl/strtmpl.cxx" , 1409, __extension__ __PRETTY_FUNCTION__)); | |||
1410 | assert(nLen >= 0)(static_cast <bool> (nLen >= 0) ? void (0) : __assert_fail ("nLen >= 0", "/home/maarten/src/libreoffice/core/sal/rtl/strtmpl.cxx" , 1410, __extension__ __PRETTY_FUNCTION__)); | |||
1411 | assert(allocExtra >= 0)(static_cast <bool> (allocExtra >= 0) ? void (0) : __assert_fail ("allocExtra >= 0", "/home/maarten/src/libreoffice/core/sal/rtl/strtmpl.cxx" , 1411, __extension__ __PRETTY_FUNCTION__)); | |||
1412 | if ( nLen + allocExtra == 0 ) | |||
1413 | { | |||
1414 | IMPL_RTL_STRINGNAME( new )( ppThis ); | |||
1415 | return; | |||
1416 | } | |||
1417 | ||||
1418 | if ( *ppThis ) | |||
1419 | IMPL_RTL_STRINGNAME( release )( *ppThis ); | |||
1420 | ||||
1421 | *ppThis = IMPL_RTL_STRINGNAME( ImplAlloc )( nLen + allocExtra ); | |||
1422 | assert( *ppThis != nullptr )(static_cast <bool> (*ppThis != nullptr) ? void (0) : __assert_fail ("*ppThis != nullptr", "/home/maarten/src/libreoffice/core/sal/rtl/strtmpl.cxx" , 1422, __extension__ __PRETTY_FUNCTION__)); | |||
1423 | ||||
1424 | (*ppThis)->length = nLen; // fix after possible allocExtra != 0 | |||
1425 | (*ppThis)->buffer[nLen] = 0; | |||
1426 | IMPL_RTL_STRCODE* pBuffer = (*ppThis)->buffer; | |||
1427 | sal_Int32 nCount; | |||
1428 | for( nCount = nLen; nCount > 0; --nCount ) | |||
1429 | { | |||
1430 | #if IMPL_RTL_IS_USTRING | |||
1431 | assert(static_cast<unsigned char>(*pCharStr) < 0x80)(static_cast <bool> (static_cast<unsigned char>(* pCharStr) < 0x80) ? void (0) : __assert_fail ("static_cast<unsigned char>(*pCharStr) < 0x80" , "/home/maarten/src/libreoffice/core/sal/rtl/strtmpl.cxx", 1431 , __extension__ __PRETTY_FUNCTION__)); // ASCII range | |||
1432 | #endif | |||
1433 | SAL_WARN_IF( (static_cast<unsigned char>(*pCharStr)) == '\0', "rtl.string",do { if (true && ((static_cast<unsigned char>(* pCharStr)) == '\0')) { switch (sal_detail_log_report(::SAL_DETAIL_LOG_LEVEL_WARN , "rtl.string")) { case SAL_DETAIL_LOG_ACTION_IGNORE: break; case SAL_DETAIL_LOG_ACTION_LOG: if (sizeof ::sal::detail::getResult ( ::sal::detail::StreamStart() << "rtl_uString_newFromLiteral - Found embedded \\0 character" ) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("rtl.string" ), ("/home/maarten/src/libreoffice/core/sal/rtl/strtmpl.cxx" ":" "1434" ": "), ::sal::detail::unwrapStream( ::sal::detail::StreamStart () << "rtl_uString_newFromLiteral - Found embedded \\0 character" ), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream << "rtl_uString_newFromLiteral - Found embedded \\0 character" ; ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("rtl.string" ), ("/home/maarten/src/libreoffice/core/sal/rtl/strtmpl.cxx" ":" "1434" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL : if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart () << "rtl_uString_newFromLiteral - Found embedded \\0 character" ) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("rtl.string" ), ("/home/maarten/src/libreoffice/core/sal/rtl/strtmpl.cxx" ":" "1434" ": "), ::sal::detail::unwrapStream( ::sal::detail::StreamStart () << "rtl_uString_newFromLiteral - Found embedded \\0 character" ), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream << "rtl_uString_newFromLiteral - Found embedded \\0 character" ; ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("rtl.string" ), ("/home/maarten/src/libreoffice/core/sal/rtl/strtmpl.cxx" ":" "1434" ": "), sal_detail_stream, 0); }; std::abort(); break; } } } while (false) | |||
1434 | "rtl_uString_newFromLiteral - Found embedded \\0 character" )do { if (true && ((static_cast<unsigned char>(* pCharStr)) == '\0')) { switch (sal_detail_log_report(::SAL_DETAIL_LOG_LEVEL_WARN , "rtl.string")) { case SAL_DETAIL_LOG_ACTION_IGNORE: break; case SAL_DETAIL_LOG_ACTION_LOG: if (sizeof ::sal::detail::getResult ( ::sal::detail::StreamStart() << "rtl_uString_newFromLiteral - Found embedded \\0 character" ) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("rtl.string" ), ("/home/maarten/src/libreoffice/core/sal/rtl/strtmpl.cxx" ":" "1434" ": "), ::sal::detail::unwrapStream( ::sal::detail::StreamStart () << "rtl_uString_newFromLiteral - Found embedded \\0 character" ), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream << "rtl_uString_newFromLiteral - Found embedded \\0 character" ; ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("rtl.string" ), ("/home/maarten/src/libreoffice/core/sal/rtl/strtmpl.cxx" ":" "1434" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL : if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart () << "rtl_uString_newFromLiteral - Found embedded \\0 character" ) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("rtl.string" ), ("/home/maarten/src/libreoffice/core/sal/rtl/strtmpl.cxx" ":" "1434" ": "), ::sal::detail::unwrapStream( ::sal::detail::StreamStart () << "rtl_uString_newFromLiteral - Found embedded \\0 character" ), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream << "rtl_uString_newFromLiteral - Found embedded \\0 character" ; ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("rtl.string" ), ("/home/maarten/src/libreoffice/core/sal/rtl/strtmpl.cxx" ":" "1434" ": "), sal_detail_stream, 0); }; std::abort(); break; } } } while (false); | |||
1435 | ||||
1436 | *pBuffer = *pCharStr; | |||
1437 | pBuffer++; | |||
1438 | pCharStr++; | |||
1439 | } | |||
1440 | ||||
1441 | RTL_LOG_STRING_NEW( *ppThis )do { ; __asm__ __volatile__ ("990: nop" "\n" ".pushsection .note.stapsdt" "," "\"?\"" "," "\"note\"" "\n" ".balign 4" "\n" ".4byte 992f-991f" "," "994f-993f" "," "3" "\n" "991: .asciz \"stapsdt\"" "\n" "992: .balign 4" "\n" "993: .8byte 990b" "\n" ".8byte _.stapsdt.base" "\n" ".8byte 0" "\n" ".asciz \"libreoffice\"" "\n" ".asciz \"new_string_RTL_LOG_STRING_BITS\"" "\n" ".asciz \"%n[_SDT_S1]@%[_SDT_A1] %n[_SDT_S2]@%[_SDT_A2] %n[_SDT_S3]@%[_SDT_A3] %n[_SDT_S4]@%[_SDT_A4]\"" "\n" "994: .balign 4" "\n" ".popsection" "\n" :: [_SDT_S1] "n" (((!(__builtin_classify_type (*ppThis) == 14 || __builtin_classify_type (*ppThis) == 5) && __sdt_type<__typeof (*ppThis)> ::__sdt_signed) ? 1 : -1) * (int) ((__builtin_classify_type ( *ppThis) == 14 || __builtin_classify_type (*ppThis) == 5) ? sizeof (void *) : sizeof (*ppThis))), [_SDT_A1] "nor" ((*ppThis)), [ _SDT_S2] "n" (((!(__builtin_classify_type ((*ppThis)->refCount ) == 14 || __builtin_classify_type ((*ppThis)->refCount) == 5) && __sdt_type<__typeof ((*ppThis)->refCount )>::__sdt_signed) ? 1 : -1) * (int) ((__builtin_classify_type ((*ppThis)->refCount) == 14 || __builtin_classify_type (( *ppThis)->refCount) == 5) ? sizeof (void *) : sizeof ((*ppThis )->refCount))), [_SDT_A2] "nor" (((*ppThis)->refCount)) , [_SDT_S3] "n" (((!(__builtin_classify_type ((*ppThis)->length ) == 14 || __builtin_classify_type ((*ppThis)->length) == 5 ) && __sdt_type<__typeof ((*ppThis)->length)> ::__sdt_signed) ? 1 : -1) * (int) ((__builtin_classify_type ( (*ppThis)->length) == 14 || __builtin_classify_type ((*ppThis )->length) == 5) ? sizeof (void *) : sizeof ((*ppThis)-> length))), [_SDT_A3] "nor" (((*ppThis)->length)), [_SDT_S4 ] "n" (((!(__builtin_classify_type ((*ppThis)->buffer) == 14 || __builtin_classify_type ((*ppThis)->buffer) == 5) && __sdt_type<__typeof ((*ppThis)->buffer)>::__sdt_signed ) ? 1 : -1) * (int) ((__builtin_classify_type ((*ppThis)-> buffer) == 14 || __builtin_classify_type ((*ppThis)->buffer ) == 5) ? sizeof (void *) : sizeof ((*ppThis)->buffer))), [ _SDT_A4] "nor" (((*ppThis)->buffer))); __asm__ __volatile__ (".ifndef _.stapsdt.base" "\n" ".pushsection .stapsdt.base" "," "\"aG\"" "," "\"progbits\"" "," ".stapsdt.base" "," "comdat" "\n" ".weak _.stapsdt.base" "\n" ".hidden _.stapsdt.base" "\n" "_.stapsdt.base: .space 1" "\n" ".size _.stapsdt.base" "," "1" "\n" ".popsection" "\n" ".endif" "\n"); } while (0); | |||
1442 | } | |||
1443 | ||||
1444 | /* ----------------------------------------------------------------------- */ | |||
1445 | ||||
1446 | void SAL_CALL IMPL_RTL_STRINGNAME( assign )( IMPL_RTL_STRINGDATA** ppThis, | |||
1447 | IMPL_RTL_STRINGDATA* pStr ) | |||
1448 | SAL_THROW_EXTERN_C()throw () | |||
1449 | { | |||
1450 | assert(ppThis)(static_cast <bool> (ppThis) ? void (0) : __assert_fail ("ppThis", "/home/maarten/src/libreoffice/core/sal/rtl/strtmpl.cxx" , 1450, __extension__ __PRETTY_FUNCTION__)); | |||
1451 | /* must be done at first, if pStr == *ppThis */ | |||
1452 | IMPL_RTL_ACQUIRE( pStr ); | |||
1453 | ||||
1454 | if ( *ppThis ) | |||
1455 | IMPL_RTL_STRINGNAME( release )( *ppThis ); | |||
1456 | ||||
1457 | *ppThis = pStr; | |||
1458 | } | |||
1459 | ||||
1460 | /* ----------------------------------------------------------------------- */ | |||
1461 | ||||
1462 | sal_Int32 SAL_CALL IMPL_RTL_STRINGNAME( getLength )( const IMPL_RTL_STRINGDATA* pThis ) | |||
1463 | SAL_THROW_EXTERN_C()throw () | |||
1464 | { | |||
1465 | assert(pThis)(static_cast <bool> (pThis) ? void (0) : __assert_fail ( "pThis", "/home/maarten/src/libreoffice/core/sal/rtl/strtmpl.cxx" , 1465, __extension__ __PRETTY_FUNCTION__)); | |||
1466 | return pThis->length; | |||
1467 | } | |||
1468 | ||||
1469 | /* ----------------------------------------------------------------------- */ | |||
1470 | ||||
1471 | IMPL_RTL_STRCODE* SAL_CALL IMPL_RTL_STRINGNAME( getStr )( IMPL_RTL_STRINGDATA * pThis ) | |||
1472 | SAL_THROW_EXTERN_C()throw () | |||
1473 | { | |||
1474 | assert(pThis)(static_cast <bool> (pThis) ? void (0) : __assert_fail ( "pThis", "/home/maarten/src/libreoffice/core/sal/rtl/strtmpl.cxx" , 1474, __extension__ __PRETTY_FUNCTION__)); | |||
1475 | return pThis->buffer; | |||
1476 | } | |||
1477 | ||||
1478 | /* ----------------------------------------------------------------------- */ | |||
1479 | ||||
1480 | void SAL_CALL IMPL_RTL_STRINGNAME( newConcat )( IMPL_RTL_STRINGDATA** ppThis, | |||
1481 | IMPL_RTL_STRINGDATA* pLeft, | |||
1482 | IMPL_RTL_STRINGDATA* pRight ) | |||
1483 | SAL_THROW_EXTERN_C()throw () | |||
1484 | { | |||
1485 | assert(ppThis)(static_cast <bool> (ppThis) ? void (0) : __assert_fail ("ppThis", "/home/maarten/src/libreoffice/core/sal/rtl/strtmpl.cxx" , 1485, __extension__ __PRETTY_FUNCTION__)); | |||
1486 | IMPL_RTL_STRINGDATA* pOrg = *ppThis; | |||
1487 | ||||
1488 | /* Test for 0-Pointer - if not, change newReplaceStrAt! */ | |||
1489 | if ( !pRight || !pRight->length ) | |||
1490 | { | |||
1491 | *ppThis = pLeft; | |||
1492 | IMPL_RTL_ACQUIRE( pLeft ); | |||
1493 | } | |||
1494 | else if ( !pLeft || !pLeft->length ) | |||
1495 | { | |||
1496 | *ppThis = pRight; | |||
1497 | IMPL_RTL_ACQUIRE( pRight ); | |||
1498 | } | |||
1499 | else if (pLeft->length | |||
1500 | > std::numeric_limits<sal_Int32>::max() - pRight->length) | |||
1501 | { | |||
1502 | *ppThis = nullptr; | |||
1503 | } | |||
1504 | else | |||
1505 | { | |||
1506 | IMPL_RTL_STRINGDATA* pTempStr = IMPL_RTL_STRINGNAME( ImplAlloc )( pLeft->length + pRight->length ); | |||
1507 | OSL_ASSERT(pTempStr != nullptr)do { if (true && (!(pTempStr != nullptr))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/sal/rtl/strtmpl.cxx" ":" "1507" ": "), "OSL_ASSERT: %s", "pTempStr != nullptr"); } } while (false); | |||
1508 | *ppThis = pTempStr; | |||
1509 | if (*ppThis != nullptr) { | |||
1510 | rtl_str_ImplCopy( pTempStr->buffer, pLeft->buffer, pLeft->length ); | |||
1511 | rtl_str_ImplCopy( pTempStr->buffer+pLeft->length, pRight->buffer, pRight->length ); | |||
1512 | ||||
1513 | RTL_LOG_STRING_NEW( *ppThis )do { ; __asm__ __volatile__ ("990: nop" "\n" ".pushsection .note.stapsdt" "," "\"?\"" "," "\"note\"" "\n" ".balign 4" "\n" ".4byte 992f-991f" "," "994f-993f" "," "3" "\n" "991: .asciz \"stapsdt\"" "\n" "992: .balign 4" "\n" "993: .8byte 990b" "\n" ".8byte _.stapsdt.base" "\n" ".8byte 0" "\n" ".asciz \"libreoffice\"" "\n" ".asciz \"new_string_RTL_LOG_STRING_BITS\"" "\n" ".asciz \"%n[_SDT_S1]@%[_SDT_A1] %n[_SDT_S2]@%[_SDT_A2] %n[_SDT_S3]@%[_SDT_A3] %n[_SDT_S4]@%[_SDT_A4]\"" "\n" "994: .balign 4" "\n" ".popsection" "\n" :: [_SDT_S1] "n" (((!(__builtin_classify_type (*ppThis) == 14 || __builtin_classify_type (*ppThis) == 5) && __sdt_type<__typeof (*ppThis)> ::__sdt_signed) ? 1 : -1) * (int) ((__builtin_classify_type ( *ppThis) == 14 || __builtin_classify_type (*ppThis) == 5) ? sizeof (void *) : sizeof (*ppThis))), [_SDT_A1] "nor" ((*ppThis)), [ _SDT_S2] "n" (((!(__builtin_classify_type ((*ppThis)->refCount ) == 14 || __builtin_classify_type ((*ppThis)->refCount) == 5) && __sdt_type<__typeof ((*ppThis)->refCount )>::__sdt_signed) ? 1 : -1) * (int) ((__builtin_classify_type ((*ppThis)->refCount) == 14 || __builtin_classify_type (( *ppThis)->refCount) == 5) ? sizeof (void *) : sizeof ((*ppThis )->refCount))), [_SDT_A2] "nor" (((*ppThis)->refCount)) , [_SDT_S3] "n" (((!(__builtin_classify_type ((*ppThis)->length ) == 14 || __builtin_classify_type ((*ppThis)->length) == 5 ) && __sdt_type<__typeof ((*ppThis)->length)> ::__sdt_signed) ? 1 : -1) * (int) ((__builtin_classify_type ( (*ppThis)->length) == 14 || __builtin_classify_type ((*ppThis )->length) == 5) ? sizeof (void *) : sizeof ((*ppThis)-> length))), [_SDT_A3] "nor" (((*ppThis)->length)), [_SDT_S4 ] "n" (((!(__builtin_classify_type ((*ppThis)->buffer) == 14 || __builtin_classify_type ((*ppThis)->buffer) == 5) && __sdt_type<__typeof ((*ppThis)->buffer)>::__sdt_signed ) ? 1 : -1) * (int) ((__builtin_classify_type ((*ppThis)-> buffer) == 14 || __builtin_classify_type ((*ppThis)->buffer ) == 5) ? sizeof (void *) : sizeof ((*ppThis)->buffer))), [ _SDT_A4] "nor" (((*ppThis)->buffer))); __asm__ __volatile__ (".ifndef _.stapsdt.base" "\n" ".pushsection .stapsdt.base" "," "\"aG\"" "," "\"progbits\"" "," ".stapsdt.base" "," "comdat" "\n" ".weak _.stapsdt.base" "\n" ".hidden _.stapsdt.base" "\n" "_.stapsdt.base: .space 1" "\n" ".size _.stapsdt.base" "," "1" "\n" ".popsection" "\n" ".endif" "\n"); } while (0); | |||
1514 | } | |||
1515 | } | |||
1516 | ||||
1517 | /* must be done last, if left or right == *ppThis */ | |||
1518 | if ( pOrg ) | |||
1519 | IMPL_RTL_STRINGNAME( release )( pOrg ); | |||
1520 | } | |||
1521 | ||||
1522 | /* ----------------------------------------------------------------------- */ | |||
1523 | ||||
1524 | void SAL_CALL IMPL_RTL_STRINGNAME( ensureCapacity )( IMPL_RTL_STRINGDATA** ppThis, | |||
1525 | sal_Int32 size ) | |||
1526 | SAL_THROW_EXTERN_C()throw () | |||
1527 | { | |||
1528 | assert(ppThis)(static_cast <bool> (ppThis) ? void (0) : __assert_fail ("ppThis", "/home/maarten/src/libreoffice/core/sal/rtl/strtmpl.cxx" , 1528, __extension__ __PRETTY_FUNCTION__)); | |||
1529 | IMPL_RTL_STRINGDATA* const pOrg = *ppThis; | |||
1530 | if ( pOrg->refCount == 1 && pOrg->length >= size ) | |||
1531 | return; | |||
1532 | assert( pOrg->length <= size )(static_cast <bool> (pOrg->length <= size) ? void (0) : __assert_fail ("pOrg->length <= size", "/home/maarten/src/libreoffice/core/sal/rtl/strtmpl.cxx" , 1532, __extension__ __PRETTY_FUNCTION__)); // do not truncate | |||
1533 | IMPL_RTL_STRINGDATA* pTempStr = IMPL_RTL_STRINGNAME( ImplAlloc )( size ); | |||
1534 | rtl_str_ImplCopy( pTempStr->buffer, pOrg->buffer, pOrg->length ); | |||
1535 | // right now the length is still the same as of the original | |||
1536 | pTempStr->length = pOrg->length; | |||
1537 | pTempStr->buffer[ pOrg->length ] = '\0'; | |||
1538 | *ppThis = pTempStr; | |||
1539 | RTL_LOG_STRING_NEW( *ppThis )do { ; __asm__ __volatile__ ("990: nop" "\n" ".pushsection .note.stapsdt" "," "\"?\"" "," "\"note\"" "\n" ".balign 4" "\n" ".4byte 992f-991f" "," "994f-993f" "," "3" "\n" "991: .asciz \"stapsdt\"" "\n" "992: .balign 4" "\n" "993: .8byte 990b" "\n" ".8byte _.stapsdt.base" "\n" ".8byte 0" "\n" ".asciz \"libreoffice\"" "\n" ".asciz \"new_string_RTL_LOG_STRING_BITS\"" "\n" ".asciz \"%n[_SDT_S1]@%[_SDT_A1] %n[_SDT_S2]@%[_SDT_A2] %n[_SDT_S3]@%[_SDT_A3] %n[_SDT_S4]@%[_SDT_A4]\"" "\n" "994: .balign 4" "\n" ".popsection" "\n" :: [_SDT_S1] "n" (((!(__builtin_classify_type (*ppThis) == 14 || __builtin_classify_type (*ppThis) == 5) && __sdt_type<__typeof (*ppThis)> ::__sdt_signed) ? 1 : -1) * (int) ((__builtin_classify_type ( *ppThis) == 14 || __builtin_classify_type (*ppThis) == 5) ? sizeof (void *) : sizeof (*ppThis))), [_SDT_A1] "nor" ((*ppThis)), [ _SDT_S2] "n" (((!(__builtin_classify_type ((*ppThis)->refCount ) == 14 || __builtin_classify_type ((*ppThis)->refCount) == 5) && __sdt_type<__typeof ((*ppThis)->refCount )>::__sdt_signed) ? 1 : -1) * (int) ((__builtin_classify_type ((*ppThis)->refCount) == 14 || __builtin_classify_type (( *ppThis)->refCount) == 5) ? sizeof (void *) : sizeof ((*ppThis )->refCount))), [_SDT_A2] "nor" (((*ppThis)->refCount)) , [_SDT_S3] "n" (((!(__builtin_classify_type ((*ppThis)->length ) == 14 || __builtin_classify_type ((*ppThis)->length) == 5 ) && __sdt_type<__typeof ((*ppThis)->length)> ::__sdt_signed) ? 1 : -1) * (int) ((__builtin_classify_type ( (*ppThis)->length) == 14 || __builtin_classify_type ((*ppThis )->length) == 5) ? sizeof (void *) : sizeof ((*ppThis)-> length))), [_SDT_A3] "nor" (((*ppThis)->length)), [_SDT_S4 ] "n" (((!(__builtin_classify_type ((*ppThis)->buffer) == 14 || __builtin_classify_type ((*ppThis)->buffer) == 5) && __sdt_type<__typeof ((*ppThis)->buffer)>::__sdt_signed ) ? 1 : -1) * (int) ((__builtin_classify_type ((*ppThis)-> buffer) == 14 || __builtin_classify_type ((*ppThis)->buffer ) == 5) ? sizeof (void *) : sizeof ((*ppThis)->buffer))), [ _SDT_A4] "nor" (((*ppThis)->buffer))); __asm__ __volatile__ (".ifndef _.stapsdt.base" "\n" ".pushsection .stapsdt.base" "," "\"aG\"" "," "\"progbits\"" "," ".stapsdt.base" "," "comdat" "\n" ".weak _.stapsdt.base" "\n" ".hidden _.stapsdt.base" "\n" "_.stapsdt.base: .space 1" "\n" ".size _.stapsdt.base" "," "1" "\n" ".popsection" "\n" ".endif" "\n"); } while (0); | |||
1540 | ||||
1541 | IMPL_RTL_STRINGNAME( release )( pOrg ); | |||
1542 | } | |||
1543 | ||||
1544 | /* ----------------------------------------------------------------------- */ | |||
1545 | ||||
1546 | void SAL_CALL IMPL_RTL_STRINGNAME( newReplaceStrAt )( IMPL_RTL_STRINGDATA** ppThis, | |||
1547 | IMPL_RTL_STRINGDATA* pStr, | |||
1548 | sal_Int32 nIndex, | |||
1549 | sal_Int32 nCount, | |||
1550 | IMPL_RTL_STRINGDATA* pNewSubStr ) | |||
1551 | SAL_THROW_EXTERN_C()throw () | |||
1552 | { | |||
1553 | assert(ppThis)(static_cast <bool> (ppThis) ? void (0) : __assert_fail ("ppThis", "/home/maarten/src/libreoffice/core/sal/rtl/strtmpl.cxx" , 1553, __extension__ __PRETTY_FUNCTION__)); | |||
1554 | assert(nIndex >= 0 && nIndex <= pStr->length)(static_cast <bool> (nIndex >= 0 && nIndex <= pStr->length) ? void (0) : __assert_fail ("nIndex >= 0 && nIndex <= pStr->length" , "/home/maarten/src/libreoffice/core/sal/rtl/strtmpl.cxx", 1554 , __extension__ __PRETTY_FUNCTION__)); | |||
1555 | assert(nCount >= 0)(static_cast <bool> (nCount >= 0) ? void (0) : __assert_fail ("nCount >= 0", "/home/maarten/src/libreoffice/core/sal/rtl/strtmpl.cxx" , 1555, __extension__ __PRETTY_FUNCTION__)); | |||
1556 | assert(nCount <= pStr->length - nIndex)(static_cast <bool> (nCount <= pStr->length - nIndex ) ? void (0) : __assert_fail ("nCount <= pStr->length - nIndex" , "/home/maarten/src/libreoffice/core/sal/rtl/strtmpl.cxx", 1556 , __extension__ __PRETTY_FUNCTION__)); | |||
1557 | /* Append? */ | |||
1558 | if ( nIndex >= pStr->length ) | |||
1559 | { | |||
1560 | /* newConcat test, if pNewSubStr is 0 */ | |||
1561 | IMPL_RTL_STRINGNAME( newConcat )( ppThis, pStr, pNewSubStr ); | |||
1562 | return; | |||
1563 | } | |||
1564 | ||||
1565 | /* negative index? */ | |||
1566 | if ( nIndex < 0 ) | |||
1567 | { | |||
1568 | nCount -= nIndex; | |||
1569 | nIndex = 0; | |||
1570 | } | |||
1571 | ||||
1572 | /* not more than the String length could be deleted */ | |||
1573 | if ( nCount >= pStr->length-nIndex ) | |||
1574 | { | |||
1575 | nCount = pStr->length-nIndex; | |||
1576 | ||||
1577 | /* Assign of NewSubStr? */ | |||
1578 | if ( !nIndex && (nCount >= pStr->length) ) | |||
1579 | { | |||
1580 | if ( !pNewSubStr ) | |||
1581 | IMPL_RTL_STRINGNAME( new )( ppThis ); | |||
1582 | else | |||
1583 | IMPL_RTL_STRINGNAME( assign )( ppThis, pNewSubStr ); | |||
1584 | return; | |||
1585 | } | |||
1586 | } | |||
1587 | ||||
1588 | /* Assign of Str? */ | |||
1589 | if ( !nCount && (!pNewSubStr || !pNewSubStr->length) ) | |||
1590 | { | |||
1591 | IMPL_RTL_STRINGNAME( assign )( ppThis, pStr ); | |||
1592 | return; | |||
1593 | } | |||
1594 | ||||
1595 | IMPL_RTL_STRINGDATA* pOrg = *ppThis; | |||
1596 | IMPL_RTL_STRCODE* pBuffer; | |||
1597 | sal_Int32 nNewLen; | |||
1598 | ||||
1599 | /* Calculate length of the new string */ | |||
1600 | nNewLen = pStr->length-nCount; | |||
1601 | if ( pNewSubStr ) | |||
1602 | nNewLen += pNewSubStr->length; | |||
1603 | ||||
1604 | /* Alloc New Buffer */ | |||
1605 | *ppThis = IMPL_RTL_STRINGNAME( ImplAlloc )( nNewLen ); | |||
1606 | OSL_ASSERT(*ppThis != nullptr)do { if (true && (!(*ppThis != nullptr))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/sal/rtl/strtmpl.cxx" ":" "1606" ": "), "OSL_ASSERT: %s", "*ppThis != nullptr"); } } while (false); | |||
1607 | pBuffer = (*ppThis)->buffer; | |||
1608 | if ( nIndex ) | |||
1609 | { | |||
1610 | rtl_str_ImplCopy( pBuffer, pStr->buffer, nIndex ); | |||
1611 | pBuffer += nIndex; | |||
1612 | } | |||
1613 | if ( pNewSubStr && pNewSubStr->length ) | |||
1614 | { | |||
1615 | rtl_str_ImplCopy( pBuffer, pNewSubStr->buffer, pNewSubStr->length ); | |||
1616 | pBuffer += pNewSubStr->length; | |||
1617 | } | |||
1618 | rtl_str_ImplCopy( pBuffer, pStr->buffer+nIndex+nCount, pStr->length-nIndex-nCount ); | |||
1619 | ||||
1620 | RTL_LOG_STRING_NEW( *ppThis )do { ; __asm__ __volatile__ ("990: nop" "\n" ".pushsection .note.stapsdt" "," "\"?\"" "," "\"note\"" "\n" ".balign 4" "\n" ".4byte 992f-991f" "," "994f-993f" "," "3" "\n" "991: .asciz \"stapsdt\"" "\n" "992: .balign 4" "\n" "993: .8byte 990b" "\n" ".8byte _.stapsdt.base" "\n" ".8byte 0" "\n" ".asciz \"libreoffice\"" "\n" ".asciz \"new_string_RTL_LOG_STRING_BITS\"" "\n" ".asciz \"%n[_SDT_S1]@%[_SDT_A1] %n[_SDT_S2]@%[_SDT_A2] %n[_SDT_S3]@%[_SDT_A3] %n[_SDT_S4]@%[_SDT_A4]\"" "\n" "994: .balign 4" "\n" ".popsection" "\n" :: [_SDT_S1] "n" (((!(__builtin_classify_type (*ppThis) == 14 || __builtin_classify_type (*ppThis) == 5) && __sdt_type<__typeof (*ppThis)> ::__sdt_signed) ? 1 : -1) * (int) ((__builtin_classify_type ( *ppThis) == 14 || __builtin_classify_type (*ppThis) == 5) ? sizeof (void *) : sizeof (*ppThis))), [_SDT_A1] "nor" ((*ppThis)), [ _SDT_S2] "n" (((!(__builtin_classify_type ((*ppThis)->refCount ) == 14 || __builtin_classify_type ((*ppThis)->refCount) == 5) && __sdt_type<__typeof ((*ppThis)->refCount )>::__sdt_signed) ? 1 : -1) * (int) ((__builtin_classify_type ((*ppThis)->refCount) == 14 || __builtin_classify_type (( *ppThis)->refCount) == 5) ? sizeof (void *) : sizeof ((*ppThis )->refCount))), [_SDT_A2] "nor" (((*ppThis)->refCount)) , [_SDT_S3] "n" (((!(__builtin_classify_type ((*ppThis)->length ) == 14 || __builtin_classify_type ((*ppThis)->length) == 5 ) && __sdt_type<__typeof ((*ppThis)->length)> ::__sdt_signed) ? 1 : -1) * (int) ((__builtin_classify_type ( (*ppThis)->length) == 14 || __builtin_classify_type ((*ppThis )->length) == 5) ? sizeof (void *) : sizeof ((*ppThis)-> length))), [_SDT_A3] "nor" (((*ppThis)->length)), [_SDT_S4 ] "n" (((!(__builtin_classify_type ((*ppThis)->buffer) == 14 || __builtin_classify_type ((*ppThis)->buffer) == 5) && __sdt_type<__typeof ((*ppThis)->buffer)>::__sdt_signed ) ? 1 : -1) * (int) ((__builtin_classify_type ((*ppThis)-> buffer) == 14 || __builtin_classify_type ((*ppThis)->buffer ) == 5) ? sizeof (void *) : sizeof ((*ppThis)->buffer))), [ _SDT_A4] "nor" (((*ppThis)->buffer))); __asm__ __volatile__ (".ifndef _.stapsdt.base" "\n" ".pushsection .stapsdt.base" "," "\"aG\"" "," "\"progbits\"" "," ".stapsdt.base" "," "comdat" "\n" ".weak _.stapsdt.base" "\n" ".hidden _.stapsdt.base" "\n" "_.stapsdt.base: .space 1" "\n" ".size _.stapsdt.base" "," "1" "\n" ".popsection" "\n" ".endif" "\n"); } while (0); | |||
1621 | /* must be done last, if pStr or pNewSubStr == *ppThis */ | |||
1622 | if ( pOrg ) | |||
1623 | IMPL_RTL_STRINGNAME( release )( pOrg ); | |||
1624 | } | |||
1625 | ||||
1626 | /* ----------------------------------------------------------------------- */ | |||
1627 | ||||
1628 | void SAL_CALL IMPL_RTL_STRINGNAME( newReplace )( IMPL_RTL_STRINGDATA** ppThis, | |||
1629 | IMPL_RTL_STRINGDATA* pStr, | |||
1630 | IMPL_RTL_STRCODE cOld, | |||
1631 | IMPL_RTL_STRCODE cNew ) | |||
1632 | SAL_THROW_EXTERN_C()throw () | |||
1633 | { | |||
1634 | assert(ppThis)(static_cast <bool> (ppThis) ? void (0) : __assert_fail ("ppThis", "/home/maarten/src/libreoffice/core/sal/rtl/strtmpl.cxx" , 1634, __extension__ __PRETTY_FUNCTION__)); | |||
1635 | assert(pStr)(static_cast <bool> (pStr) ? void (0) : __assert_fail ( "pStr", "/home/maarten/src/libreoffice/core/sal/rtl/strtmpl.cxx" , 1635, __extension__ __PRETTY_FUNCTION__)); | |||
1636 | IMPL_RTL_STRINGDATA* pOrg = *ppThis; | |||
1637 | bool bChanged = false; | |||
1638 | sal_Int32 nLen = pStr->length; | |||
1639 | const IMPL_RTL_STRCODE* pCharStr = pStr->buffer; | |||
1640 | ||||
1641 | while ( nLen > 0 ) | |||
1642 | { | |||
1643 | if ( *pCharStr == cOld ) | |||
1644 | { | |||
1645 | /* Copy String */ | |||
1646 | IMPL_RTL_STRCODE* pNewCharStr = IMPL_RTL_STRINGNAME( ImplNewCopy )( ppThis, pStr, pCharStr-pStr->buffer ); | |||
1647 | ||||
1648 | /* replace/copy rest of the string */ | |||
1649 | if ( pNewCharStr ) | |||
1650 | { | |||
1651 | *pNewCharStr = cNew; | |||
1652 | pNewCharStr++; | |||
1653 | pCharStr++; | |||
1654 | nLen--; | |||
1655 | ||||
1656 | while ( nLen > 0 ) | |||
1657 | { | |||
1658 | if ( *pCharStr == cOld ) | |||
1659 | *pNewCharStr = cNew; | |||
1660 | else | |||
1661 | *pNewCharStr = *pCharStr; | |||
1662 | ||||
1663 | pNewCharStr++; | |||
1664 | pCharStr++; | |||
1665 | nLen--; | |||
1666 | } | |||
1667 | } | |||
1668 | ||||
1669 | bChanged = true; | |||
1670 | break; | |||
1671 | } | |||
1672 | ||||
1673 | pCharStr++; | |||
1674 | nLen--; | |||
1675 | } | |||
1676 | ||||
1677 | if ( !bChanged ) | |||
1678 | { | |||
1679 | *ppThis = pStr; | |||
1680 | IMPL_RTL_ACQUIRE( pStr ); | |||
1681 | } | |||
1682 | ||||
1683 | RTL_LOG_STRING_NEW( *ppThis )do { ; __asm__ __volatile__ ("990: nop" "\n" ".pushsection .note.stapsdt" "," "\"?\"" "," "\"note\"" "\n" ".balign 4" "\n" ".4byte 992f-991f" "," "994f-993f" "," "3" "\n" "991: .asciz \"stapsdt\"" "\n" "992: .balign 4" "\n" "993: .8byte 990b" "\n" ".8byte _.stapsdt.base" "\n" ".8byte 0" "\n" ".asciz \"libreoffice\"" "\n" ".asciz \"new_string_RTL_LOG_STRING_BITS\"" "\n" ".asciz \"%n[_SDT_S1]@%[_SDT_A1] %n[_SDT_S2]@%[_SDT_A2] %n[_SDT_S3]@%[_SDT_A3] %n[_SDT_S4]@%[_SDT_A4]\"" "\n" "994: .balign 4" "\n" ".popsection" "\n" :: [_SDT_S1] "n" (((!(__builtin_classify_type (*ppThis) == 14 || __builtin_classify_type (*ppThis) == 5) && __sdt_type<__typeof (*ppThis)> ::__sdt_signed) ? 1 : -1) * (int) ((__builtin_classify_type ( *ppThis) == 14 || __builtin_classify_type (*ppThis) == 5) ? sizeof (void *) : sizeof (*ppThis))), [_SDT_A1] "nor" ((*ppThis)), [ _SDT_S2] "n" (((!(__builtin_classify_type ((*ppThis)->refCount ) == 14 || __builtin_classify_type ((*ppThis)->refCount) == 5) && __sdt_type<__typeof ((*ppThis)->refCount )>::__sdt_signed) ? 1 : -1) * (int) ((__builtin_classify_type ((*ppThis)->refCount) == 14 || __builtin_classify_type (( *ppThis)->refCount) == 5) ? sizeof (void *) : sizeof ((*ppThis )->refCount))), [_SDT_A2] "nor" (((*ppThis)->refCount)) , [_SDT_S3] "n" (((!(__builtin_classify_type ((*ppThis)->length ) == 14 || __builtin_classify_type ((*ppThis)->length) == 5 ) && __sdt_type<__typeof ((*ppThis)->length)> ::__sdt_signed) ? 1 : -1) * (int) ((__builtin_classify_type ( (*ppThis)->length) == 14 || __builtin_classify_type ((*ppThis )->length) == 5) ? sizeof (void *) : sizeof ((*ppThis)-> length))), [_SDT_A3] "nor" (((*ppThis)->length)), [_SDT_S4 ] "n" (((!(__builtin_classify_type ((*ppThis)->buffer) == 14 || __builtin_classify_type ((*ppThis)->buffer) == 5) && __sdt_type<__typeof ((*ppThis)->buffer)>::__sdt_signed ) ? 1 : -1) * (int) ((__builtin_classify_type ((*ppThis)-> buffer) == 14 || __builtin_classify_type ((*ppThis)->buffer ) == 5) ? sizeof (void *) : sizeof ((*ppThis)->buffer))), [ _SDT_A4] "nor" (((*ppThis)->buffer))); __asm__ __volatile__ (".ifndef _.stapsdt.base" "\n" ".pushsection .stapsdt.base" "," "\"aG\"" "," "\"progbits\"" "," ".stapsdt.base" "," "comdat" "\n" ".weak _.stapsdt.base" "\n" ".hidden _.stapsdt.base" "\n" "_.stapsdt.base: .space 1" "\n" ".size _.stapsdt.base" "," "1" "\n" ".popsection" "\n" ".endif" "\n"); } while (0); | |||
1684 | /* must be done last, if pStr == *ppThis */ | |||
1685 | if ( pOrg ) | |||
1686 | IMPL_RTL_STRINGNAME( release )( pOrg ); | |||
1687 | } | |||
1688 | ||||
1689 | /* ----------------------------------------------------------------------- */ | |||
1690 | ||||
1691 | void SAL_CALL IMPL_RTL_STRINGNAME( newToAsciiLowerCase )( IMPL_RTL_STRINGDATA** ppThis, | |||
1692 | IMPL_RTL_STRINGDATA* pStr ) | |||
1693 | SAL_THROW_EXTERN_C()throw () | |||
1694 | { | |||
1695 | assert(ppThis)(static_cast <bool> (ppThis) ? void (0) : __assert_fail ("ppThis", "/home/maarten/src/libreoffice/core/sal/rtl/strtmpl.cxx" , 1695, __extension__ __PRETTY_FUNCTION__)); | |||
1696 | assert(pStr)(static_cast <bool> (pStr) ? void (0) : __assert_fail ( "pStr", "/home/maarten/src/libreoffice/core/sal/rtl/strtmpl.cxx" , 1696, __extension__ __PRETTY_FUNCTION__)); | |||
1697 | IMPL_RTL_STRINGDATA* pOrg = *ppThis; | |||
1698 | bool bChanged = false; | |||
1699 | sal_Int32 nLen = pStr->length; | |||
1700 | const IMPL_RTL_STRCODE* pCharStr = pStr->buffer; | |||
1701 | ||||
1702 | while ( nLen > 0 ) | |||
1703 | { | |||
1704 | if ( rtl::isAsciiUpperCase(IMPL_RTL_USTRCODE(*pCharStr)) ) | |||
1705 | { | |||
1706 | /* Copy String */ | |||
1707 | IMPL_RTL_STRCODE* pNewCharStr = IMPL_RTL_STRINGNAME( ImplNewCopy )( ppThis, pStr, pCharStr-pStr->buffer ); | |||
1708 | ||||
1709 | /* replace/copy rest of the string */ | |||
1710 | if ( pNewCharStr ) | |||
1711 | { | |||
1712 | *pNewCharStr = rtl::toAsciiLowerCase(IMPL_RTL_USTRCODE(*pCharStr)); | |||
1713 | pNewCharStr++; | |||
1714 | pCharStr++; | |||
1715 | nLen--; | |||
1716 | ||||
1717 | while ( nLen > 0 ) | |||
1718 | { | |||
1719 | *pNewCharStr = rtl::toAsciiLowerCase(IMPL_RTL_USTRCODE(*pCharStr)); | |||
1720 | ||||
1721 | pNewCharStr++; | |||
1722 | pCharStr++; | |||
1723 | nLen--; | |||
1724 | } | |||
1725 | } | |||
1726 | ||||
1727 | bChanged = true; | |||
1728 | break; | |||
1729 | } | |||
1730 | ||||
1731 | pCharStr++; | |||
1732 | nLen--; | |||
1733 | } | |||
1734 | ||||
1735 | if ( !bChanged ) | |||
1736 | { | |||
1737 | *ppThis = pStr; | |||
1738 | IMPL_RTL_ACQUIRE( pStr ); | |||
1739 | } | |||
1740 | ||||
1741 | RTL_LOG_STRING_NEW( *ppThis )do { ; __asm__ __volatile__ ("990: nop" "\n" ".pushsection .note.stapsdt" "," "\"?\"" "," "\"note\"" "\n" ".balign 4" "\n" ".4byte 992f-991f" "," "994f-993f" "," "3" "\n" "991: .asciz \"stapsdt\"" "\n" "992: .balign 4" "\n" "993: .8byte 990b" "\n" ".8byte _.stapsdt.base" "\n" ".8byte 0" "\n" ".asciz \"libreoffice\"" "\n" ".asciz \"new_string_RTL_LOG_STRING_BITS\"" "\n" ".asciz \"%n[_SDT_S1]@%[_SDT_A1] %n[_SDT_S2]@%[_SDT_A2] %n[_SDT_S3]@%[_SDT_A3] %n[_SDT_S4]@%[_SDT_A4]\"" "\n" "994: .balign 4" "\n" ".popsection" "\n" :: [_SDT_S1] "n" (((!(__builtin_classify_type (*ppThis) == 14 || __builtin_classify_type (*ppThis) == 5) && __sdt_type<__typeof (*ppThis)> ::__sdt_signed) ? 1 : -1) * (int) ((__builtin_classify_type ( *ppThis) == 14 || __builtin_classify_type (*ppThis) == 5) ? sizeof (void *) : sizeof (*ppThis))), [_SDT_A1] "nor" ((*ppThis)), [ _SDT_S2] "n" (((!(__builtin_classify_type ((*ppThis)->refCount ) == 14 || __builtin_classify_type ((*ppThis)->refCount) == 5) && __sdt_type<__typeof ((*ppThis)->refCount )>::__sdt_signed) ? 1 : -1) * (int) ((__builtin_classify_type ((*ppThis)->refCount) == 14 || __builtin_classify_type (( *ppThis)->refCount) == 5) ? sizeof (void *) : sizeof ((*ppThis )->refCount))), [_SDT_A2] "nor" (((*ppThis)->refCount)) , [_SDT_S3] "n" (((!(__builtin_classify_type ((*ppThis)->length ) == 14 || __builtin_classify_type ((*ppThis)->length) == 5 ) && __sdt_type<__typeof ((*ppThis)->length)> ::__sdt_signed) ? 1 : -1) * (int) ((__builtin_classify_type ( (*ppThis)->length) == 14 || __builtin_classify_type ((*ppThis )->length) == 5) ? sizeof (void *) : sizeof ((*ppThis)-> length))), [_SDT_A3] "nor" (((*ppThis)->length)), [_SDT_S4 ] "n" (((!(__builtin_classify_type ((*ppThis)->buffer) == 14 || __builtin_classify_type ((*ppThis)->buffer) == 5) && __sdt_type<__typeof ((*ppThis)->buffer)>::__sdt_signed ) ? 1 : -1) * (int) ((__builtin_classify_type ((*ppThis)-> buffer) == 14 || __builtin_classify_type ((*ppThis)->buffer ) == 5) ? sizeof (void *) : sizeof ((*ppThis)->buffer))), [ _SDT_A4] "nor" (((*ppThis)->buffer))); __asm__ __volatile__ (".ifndef _.stapsdt.base" "\n" ".pushsection .stapsdt.base" "," "\"aG\"" "," "\"progbits\"" "," ".stapsdt.base" "," "comdat" "\n" ".weak _.stapsdt.base" "\n" ".hidden _.stapsdt.base" "\n" "_.stapsdt.base: .space 1" "\n" ".size _.stapsdt.base" "," "1" "\n" ".popsection" "\n" ".endif" "\n"); } while (0); | |||
1742 | /* must be done last, if pStr == *ppThis */ | |||
1743 | if ( pOrg ) | |||
1744 | IMPL_RTL_STRINGNAME( release )( pOrg ); | |||
1745 | } | |||
1746 | ||||
1747 | /* ----------------------------------------------------------------------- */ | |||
1748 | ||||
1749 | void SAL_CALL IMPL_RTL_STRINGNAME( newToAsciiUpperCase )( IMPL_RTL_STRINGDATA** ppThis, | |||
1750 | IMPL_RTL_STRINGDATA* pStr ) | |||
1751 | SAL_THROW_EXTERN_C()throw () | |||
1752 | { | |||
1753 | assert(ppThis)(static_cast <bool> (ppThis) ? void (0) : __assert_fail ("ppThis", "/home/maarten/src/libreoffice/core/sal/rtl/strtmpl.cxx" , 1753, __extension__ __PRETTY_FUNCTION__)); | |||
1754 | assert(pStr)(static_cast <bool> (pStr) ? void (0) : __assert_fail ( "pStr", "/home/maarten/src/libreoffice/core/sal/rtl/strtmpl.cxx" , 1754, __extension__ __PRETTY_FUNCTION__)); | |||
1755 | IMPL_RTL_STRINGDATA* pOrg = *ppThis; | |||
1756 | bool bChanged = false; | |||
1757 | sal_Int32 nLen = pStr->length; | |||
1758 | const IMPL_RTL_STRCODE* pCharStr = pStr->buffer; | |||
1759 | ||||
1760 | while ( nLen > 0 ) | |||
1761 | { | |||
1762 | if ( rtl::isAsciiLowerCase(IMPL_RTL_USTRCODE(*pCharStr)) ) | |||
1763 | { | |||
1764 | /* Copy String */ | |||
1765 | IMPL_RTL_STRCODE* pNewCharStr = IMPL_RTL_STRINGNAME( ImplNewCopy )( ppThis, pStr, pCharStr-pStr->buffer ); | |||
1766 | ||||
1767 | /* replace/copy rest of the string */ | |||
1768 | if ( pNewCharStr ) | |||
1769 | { | |||
1770 | *pNewCharStr = rtl::toAsciiUpperCase(IMPL_RTL_USTRCODE(*pCharStr)); | |||
1771 | pNewCharStr++; | |||
1772 | pCharStr++; | |||
1773 | nLen--; | |||
1774 | ||||
1775 | while ( nLen > 0 ) | |||
1776 | { | |||
1777 | *pNewCharStr = rtl::toAsciiUpperCase(IMPL_RTL_USTRCODE(*pCharStr)); | |||
1778 | ||||
1779 | pNewCharStr++; | |||
1780 | pCharStr++; | |||
1781 | nLen--; | |||
1782 | } | |||
1783 | } | |||
1784 | ||||
1785 | bChanged = true; | |||
1786 | break; | |||
1787 | } | |||
1788 | ||||
1789 | pCharStr++; | |||
1790 | nLen--; | |||
1791 | } | |||
1792 | ||||
1793 | if ( !bChanged ) | |||
1794 | { | |||
1795 | *ppThis = pStr; | |||
1796 | IMPL_RTL_ACQUIRE( pStr ); | |||
1797 | } | |||
1798 | ||||
1799 | RTL_LOG_STRING_NEW( *ppThis )do { ; __asm__ __volatile__ ("990: nop" "\n" ".pushsection .note.stapsdt" "," "\"?\"" "," "\"note\"" "\n" ".balign 4" "\n" ".4byte 992f-991f" "," "994f-993f" "," "3" "\n" "991: .asciz \"stapsdt\"" "\n" "992: .balign 4" "\n" "993: .8byte 990b" "\n" ".8byte _.stapsdt.base" "\n" ".8byte 0" "\n" ".asciz \"libreoffice\"" "\n" ".asciz \"new_string_RTL_LOG_STRING_BITS\"" "\n" ".asciz \"%n[_SDT_S1]@%[_SDT_A1] %n[_SDT_S2]@%[_SDT_A2] %n[_SDT_S3]@%[_SDT_A3] %n[_SDT_S4]@%[_SDT_A4]\"" "\n" "994: .balign 4" "\n" ".popsection" "\n" :: [_SDT_S1] "n" (((!(__builtin_classify_type (*ppThis) == 14 || __builtin_classify_type (*ppThis) == 5) && __sdt_type<__typeof (*ppThis)> ::__sdt_signed) ? 1 : -1) * (int) ((__builtin_classify_type ( *ppThis) == 14 || __builtin_classify_type (*ppThis) == 5) ? sizeof (void *) : sizeof (*ppThis))), [_SDT_A1] "nor" ((*ppThis)), [ _SDT_S2] "n" (((!(__builtin_classify_type ((*ppThis)->refCount ) == 14 || __builtin_classify_type ((*ppThis)->refCount) == 5) && __sdt_type<__typeof ((*ppThis)->refCount )>::__sdt_signed) ? 1 : -1) * (int) ((__builtin_classify_type ((*ppThis)->refCount) == 14 || __builtin_classify_type (( *ppThis)->refCount) == 5) ? sizeof (void *) : sizeof ((*ppThis )->refCount))), [_SDT_A2] "nor" (((*ppThis)->refCount)) , [_SDT_S3] "n" (((!(__builtin_classify_type ((*ppThis)->length ) == 14 || __builtin_classify_type ((*ppThis)->length) == 5 ) && __sdt_type<__typeof ((*ppThis)->length)> ::__sdt_signed) ? 1 : -1) * (int) ((__builtin_classify_type ( (*ppThis)->length) == 14 || __builtin_classify_type ((*ppThis )->length) == 5) ? sizeof (void *) : sizeof ((*ppThis)-> length))), [_SDT_A3] "nor" (((*ppThis)->length)), [_SDT_S4 ] "n" (((!(__builtin_classify_type ((*ppThis)->buffer) == 14 || __builtin_classify_type ((*ppThis)->buffer) == 5) && __sdt_type<__typeof ((*ppThis)->buffer)>::__sdt_signed ) ? 1 : -1) * (int) ((__builtin_classify_type ((*ppThis)-> buffer) == 14 || __builtin_classify_type ((*ppThis)->buffer ) == 5) ? sizeof (void *) : sizeof ((*ppThis)->buffer))), [ _SDT_A4] "nor" (((*ppThis)->buffer))); __asm__ __volatile__ (".ifndef _.stapsdt.base" "\n" ".pushsection .stapsdt.base" "," "\"aG\"" "," "\"progbits\"" "," ".stapsdt.base" "," "comdat" "\n" ".weak _.stapsdt.base" "\n" ".hidden _.stapsdt.base" "\n" "_.stapsdt.base: .space 1" "\n" ".size _.stapsdt.base" "," "1" "\n" ".popsection" "\n" ".endif" "\n"); } while (0); | |||
1800 | /* must be done last, if pStr == *ppThis */ | |||
1801 | if ( pOrg ) | |||
1802 | IMPL_RTL_STRINGNAME( release )( pOrg ); | |||
1803 | } | |||
1804 | ||||
1805 | /* ----------------------------------------------------------------------- */ | |||
1806 | ||||
1807 | void SAL_CALL IMPL_RTL_STRINGNAME( newTrim )( IMPL_RTL_STRINGDATA** ppThis, | |||
1808 | IMPL_RTL_STRINGDATA* pStr ) | |||
1809 | SAL_THROW_EXTERN_C()throw () | |||
1810 | { | |||
1811 | assert(ppThis)(static_cast <bool> (ppThis) ? void (0) : __assert_fail ("ppThis", "/home/maarten/src/libreoffice/core/sal/rtl/strtmpl.cxx" , 1811, __extension__ __PRETTY_FUNCTION__)); | |||
1812 | assert(pStr)(static_cast <bool> (pStr) ? void (0) : __assert_fail ( "pStr", "/home/maarten/src/libreoffice/core/sal/rtl/strtmpl.cxx" , 1812, __extension__ __PRETTY_FUNCTION__)); | |||
1813 | IMPL_RTL_STRINGDATA* pOrg = *ppThis; | |||
1814 | const IMPL_RTL_STRCODE* pCharStr = pStr->buffer; | |||
1815 | sal_Int32 nPreSpaces = 0; | |||
1816 | sal_Int32 nPostSpaces = 0; | |||
1817 | sal_Int32 nLen = pStr->length; | |||
1818 | sal_Int32 nIndex = nLen-1; | |||
1819 | ||||
1820 | while ( (nPreSpaces < nLen) && rtl_ImplIsWhitespace( IMPL_RTL_USTRCODE(*(pCharStr+nPreSpaces)) ) ) | |||
1821 | nPreSpaces++; | |||
1822 | ||||
1823 | while ( (nIndex > nPreSpaces) && rtl_ImplIsWhitespace( IMPL_RTL_USTRCODE(*(pCharStr+nIndex)) ) ) | |||
1824 | { | |||
1825 | nPostSpaces++; | |||
1826 | nIndex--; | |||
1827 | } | |||
1828 | ||||
1829 | if ( !nPreSpaces && !nPostSpaces ) | |||
1830 | { | |||
1831 | *ppThis = pStr; | |||
1832 | IMPL_RTL_ACQUIRE( pStr ); | |||
1833 | } | |||
1834 | else | |||
1835 | { | |||
1836 | nLen -= nPostSpaces+nPreSpaces; | |||
1837 | *ppThis = IMPL_RTL_STRINGNAME( ImplAlloc )( nLen ); | |||
1838 | assert(*ppThis)(static_cast <bool> (*ppThis) ? void (0) : __assert_fail ("*ppThis", "/home/maarten/src/libreoffice/core/sal/rtl/strtmpl.cxx" , 1838, __extension__ __PRETTY_FUNCTION__)); | |||
1839 | rtl_str_ImplCopy( (*ppThis)->buffer, pStr->buffer+nPreSpaces, nLen ); | |||
1840 | } | |||
1841 | ||||
1842 | RTL_LOG_STRING_NEW( *ppThis )do { ; __asm__ __volatile__ ("990: nop" "\n" ".pushsection .note.stapsdt" "," "\"?\"" "," "\"note\"" "\n" ".balign 4" "\n" ".4byte 992f-991f" "," "994f-993f" "," "3" "\n" "991: .asciz \"stapsdt\"" "\n" "992: .balign 4" "\n" "993: .8byte 990b" "\n" ".8byte _.stapsdt.base" "\n" ".8byte 0" "\n" ".asciz \"libreoffice\"" "\n" ".asciz \"new_string_RTL_LOG_STRING_BITS\"" "\n" ".asciz \"%n[_SDT_S1]@%[_SDT_A1] %n[_SDT_S2]@%[_SDT_A2] %n[_SDT_S3]@%[_SDT_A3] %n[_SDT_S4]@%[_SDT_A4]\"" "\n" "994: .balign 4" "\n" ".popsection" "\n" :: [_SDT_S1] "n" (((!(__builtin_classify_type (*ppThis) == 14 || __builtin_classify_type (*ppThis) == 5) && __sdt_type<__typeof (*ppThis)> ::__sdt_signed) ? 1 : -1) * (int) ((__builtin_classify_type ( *ppThis) == 14 || __builtin_classify_type (*ppThis) == 5) ? sizeof (void *) : sizeof (*ppThis))), [_SDT_A1] "nor" ((*ppThis)), [ _SDT_S2] "n" (((!(__builtin_classify_type ((*ppThis)->refCount ) == 14 || __builtin_classify_type ((*ppThis)->refCount) == 5) && __sdt_type<__typeof ((*ppThis)->refCount )>::__sdt_signed) ? 1 : -1) * (int) ((__builtin_classify_type ((*ppThis)->refCount) == 14 || __builtin_classify_type (( *ppThis)->refCount) == 5) ? sizeof (void *) : sizeof ((*ppThis )->refCount))), [_SDT_A2] "nor" (((*ppThis)->refCount)) , [_SDT_S3] "n" (((!(__builtin_classify_type ((*ppThis)->length ) == 14 || __builtin_classify_type ((*ppThis)->length) == 5 ) && __sdt_type<__typeof ((*ppThis)->length)> ::__sdt_signed) ? 1 : -1) * (int) ((__builtin_classify_type ( (*ppThis)->length) == 14 || __builtin_classify_type ((*ppThis )->length) == 5) ? sizeof (void *) : sizeof ((*ppThis)-> length))), [_SDT_A3] "nor" (((*ppThis)->length)), [_SDT_S4 ] "n" (((!(__builtin_classify_type ((*ppThis)->buffer) == 14 || __builtin_classify_type ((*ppThis)->buffer) == 5) && __sdt_type<__typeof ((*ppThis)->buffer)>::__sdt_signed ) ? 1 : -1) * (int) ((__builtin_classify_type ((*ppThis)-> buffer) == 14 || __builtin_classify_type ((*ppThis)->buffer ) == 5) ? sizeof (void *) : sizeof ((*ppThis)->buffer))), [ _SDT_A4] "nor" (((*ppThis)->buffer))); __asm__ __volatile__ (".ifndef _.stapsdt.base" "\n" ".pushsection .stapsdt.base" "," "\"aG\"" "," "\"progbits\"" "," ".stapsdt.base" "," "comdat" "\n" ".weak _.stapsdt.base" "\n" ".hidden _.stapsdt.base" "\n" "_.stapsdt.base: .space 1" "\n" ".size _.stapsdt.base" "," "1" "\n" ".popsection" "\n" ".endif" "\n"); } while (0); | |||
1843 | /* must be done last, if pStr == *ppThis */ | |||
1844 | if ( pOrg ) | |||
1845 | IMPL_RTL_STRINGNAME( release )( pOrg ); | |||
1846 | } | |||
1847 | ||||
1848 | /* ----------------------------------------------------------------------- */ | |||
1849 | ||||
1850 | sal_Int32 SAL_CALL IMPL_RTL_STRINGNAME( getToken )( IMPL_RTL_STRINGDATA** ppThis, | |||
1851 | IMPL_RTL_STRINGDATA* pStr, | |||
1852 | sal_Int32 nToken, | |||
1853 | IMPL_RTL_STRCODE cTok, | |||
1854 | sal_Int32 nIndex ) | |||
1855 | SAL_THROW_EXTERN_C()throw () | |||
1856 | { | |||
1857 | assert(ppThis)(static_cast <bool> (ppThis) ? void (0) : __assert_fail ("ppThis", "/home/maarten/src/libreoffice/core/sal/rtl/strtmpl.cxx" , 1857, __extension__ __PRETTY_FUNCTION__)); | |||
1858 | assert(pStr)(static_cast <bool> (pStr) ? void (0) : __assert_fail ( "pStr", "/home/maarten/src/libreoffice/core/sal/rtl/strtmpl.cxx" , 1858, __extension__ __PRETTY_FUNCTION__)); | |||
1859 | const IMPL_RTL_STRCODE* pCharStr = pStr->buffer; | |||
1860 | const IMPL_RTL_STRCODE* pCharStrStart; | |||
1861 | const IMPL_RTL_STRCODE* pOrgCharStr; | |||
1862 | sal_Int32 nLen = pStr->length-nIndex; | |||
1863 | sal_Int32 nTokCount = 0; | |||
1864 | ||||
1865 | // Set ppThis to an empty string and return -1 if either nToken or nIndex is | |||
1866 | // negative: | |||
1867 | if (nIndex < 0) | |||
1868 | nToken = -1; | |||
1869 | ||||
1870 | pCharStr += nIndex; | |||
1871 | pOrgCharStr = pCharStr; | |||
1872 | pCharStrStart = pCharStr; | |||
1873 | while ( nLen > 0 ) | |||
1874 | { | |||
1875 | if ( *pCharStr == cTok ) | |||
1876 | { | |||
1877 | nTokCount++; | |||
1878 | ||||
1879 | if ( nTokCount == nToken ) | |||
1880 | pCharStrStart = pCharStr+1; | |||
1881 | else | |||
1882 | { | |||
1883 | if ( nTokCount > nToken ) | |||
1884 | break; | |||
1885 | } | |||
1886 | } | |||
1887 | ||||
1888 | pCharStr++; | |||
1889 | nLen--; | |||
1890 | } | |||
1891 | ||||
1892 | if ( (nToken < 0) || (nTokCount < nToken) || (pCharStr == pCharStrStart) ) | |||
1893 | { | |||
1894 | IMPL_RTL_STRINGNAME( new )( ppThis ); | |||
1895 | if( (nToken < 0) || (nTokCount < nToken ) ) | |||
1896 | return -1; | |||
1897 | else if( nLen > 0 ) | |||
1898 | return nIndex+(pCharStr-pOrgCharStr)+1; | |||
1899 | else return -1; | |||
1900 | } | |||
1901 | else | |||
1902 | { | |||
1903 | IMPL_RTL_STRINGNAME( newFromStr_WithLength )( ppThis, pCharStrStart, pCharStr-pCharStrStart ); | |||
1904 | if ( nLen ) | |||
1905 | return nIndex+(pCharStr-pOrgCharStr)+1; | |||
1906 | else | |||
1907 | return -1; | |||
1908 | } | |||
1909 | } | |||
1910 | ||||
1911 | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |