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 #if defined _WIN32
37 // Temporary check to verify that the #pragma pack around rtl_String is indeed cargo cult and can
38 // safely be removed:
39 static_assert(alignof (rtl_String) == 4);
40 static_assert(sizeof (rtl_String) == 12);
41 #endif
42 
43 /* ======================================================================= */
44 
45 #if USE_SDT_PROBES
46 #define RTL_LOG_STRING_BITS         8
47 #endif
48 
49 #include "strtmpl.hxx"
50 
51 /* static data to be referenced by all empty strings
52  * the refCount is predefined to 1 and must never become 0 !
53  */
54 template<>
55 rtl_String rtl::str::EmptyStringImpl<rtl_String>::data =
56 {
57     SAL_STRING_STATIC_FLAG|1,
58             /* sal_Int32    refCount;   */
59     0,      /* sal_Int32    length;     */
60     { 0 }   /* char     buffer[1];  */
61 };
62 
63 /* ======================================================================= */
64 
rtl_str_valueOfFloat(char * pStr,float f)65 sal_Int32 SAL_CALL rtl_str_valueOfFloat(char * pStr, float f)
66     SAL_THROW_EXTERN_C()
67 {
68     assert(pStr);
69     rtl_String * pResult = nullptr;
70     sal_Int32 nLen;
71     rtl_math_doubleToString(
72         &pResult, nullptr, 0, f, rtl_math_StringFormat_G,
73         RTL_STR_MAX_VALUEOFFLOAT - RTL_CONSTASCII_LENGTH("-x.E-xxx"), '.', nullptr, 0,
74         true);
75     nLen = pResult->length;
76     OSL_ASSERT(nLen < RTL_STR_MAX_VALUEOFFLOAT);
77     memcpy(pStr, pResult->buffer, (nLen + 1) * sizeof(char));
78     rtl_string_release(pResult);
79     return nLen;
80 }
81 
rtl_str_valueOfDouble(char * pStr,double d)82 sal_Int32 SAL_CALL rtl_str_valueOfDouble(char * pStr, double d)
83     SAL_THROW_EXTERN_C()
84 {
85     assert(pStr);
86     rtl_String * pResult = nullptr;
87     sal_Int32 nLen;
88     rtl_math_doubleToString(
89         &pResult, nullptr, 0, d, rtl_math_StringFormat_G,
90         RTL_STR_MAX_VALUEOFDOUBLE - RTL_CONSTASCII_LENGTH("-x.E-xxx"), '.', nullptr,
91         0, true);
92     nLen = pResult->length;
93     OSL_ASSERT(nLen < RTL_STR_MAX_VALUEOFDOUBLE);
94     memcpy(pStr, pResult->buffer, (nLen + 1) * sizeof(char));
95     rtl_string_release(pResult);
96     return nLen;
97 }
98 
rtl_str_toFloat(char const * pStr)99 float SAL_CALL rtl_str_toFloat(char const * pStr) SAL_THROW_EXTERN_C()
100 {
101     assert(pStr);
102     return static_cast<float>(rtl_math_stringToDouble(pStr, pStr + rtl_str_getLength(pStr),
103                                            '.', 0, nullptr, nullptr));
104 }
105 
rtl_str_toDouble(char const * pStr)106 double SAL_CALL rtl_str_toDouble(char const * pStr) SAL_THROW_EXTERN_C()
107 {
108     assert(pStr);
109     return rtl_math_stringToDouble(pStr, pStr + rtl_str_getLength(pStr), '.', 0,
110                                    nullptr, nullptr);
111 }
112 
113 /* ======================================================================= */
114 
rtl_ImplGetFastUTF8ByteLen(const sal_Unicode * pStr,sal_Int32 nLen)115 static int rtl_ImplGetFastUTF8ByteLen( const sal_Unicode* pStr, sal_Int32 nLen )
116 {
117     int                 n;
118     sal_Unicode         c;
119     sal_uInt32          nUCS4Char;
120     const sal_Unicode*  pEndStr;
121 
122     n = 0;
123     pEndStr  = pStr+nLen;
124     while ( pStr < pEndStr )
125     {
126         c = *pStr;
127 
128         if ( c < 0x80 )
129             n++;
130         else if ( c < 0x800 )
131             n += 2;
132         else
133         {
134             if ( !rtl::isHighSurrogate(c) )
135                 n += 3;
136             else
137             {
138                 nUCS4Char = c;
139 
140                 if ( pStr+1 < pEndStr )
141                 {
142                     c = *(pStr+1);
143                     if ( rtl::isLowSurrogate(c) )
144                     {
145                         nUCS4Char = rtl::combineSurrogates(nUCS4Char, c);
146                         pStr++;
147                     }
148                 }
149 
150                 if ( nUCS4Char < 0x10000 )
151                     n += 3;
152                 else if ( nUCS4Char < 0x200000 )
153                     n += 4;
154                 else if ( nUCS4Char < 0x4000000 )
155                     n += 5;
156                 else
157                     n += 6;
158             }
159         }
160 
161         pStr++;
162     }
163 
164     return n;
165 }
166 
167 /* ----------------------------------------------------------------------- */
168 
rtl_impl_convertUStringToString(rtl_String ** pTarget,sal_Unicode const * pSource,sal_Int32 nLength,rtl_TextEncoding nEncoding,sal_uInt32 nFlags,bool bCheckErrors)169 static bool rtl_impl_convertUStringToString(rtl_String ** pTarget,
170                                                   sal_Unicode const * pSource,
171                                                   sal_Int32 nLength,
172                                                   rtl_TextEncoding nEncoding,
173                                                   sal_uInt32 nFlags,
174                                                   bool bCheckErrors)
175 {
176     assert(pTarget != nullptr);
177     assert(pSource != nullptr || nLength == 0);
178     assert(nLength >= 0);
179     OSL_ASSERT(nLength == 0 || rtl_isOctetTextEncoding(nEncoding));
180 
181     if ( !nLength )
182         rtl_string_new( pTarget );
183     else
184     {
185         rtl_String*                 pTemp;
186         rtl_UnicodeToTextConverter  hConverter;
187         sal_uInt32                  nInfo;
188         sal_Size                    nSrcChars;
189         sal_Size                    nDestBytes;
190         sal_Size                    nNewLen;
191         sal_Size                    nNotConvertedChars;
192         sal_Size                    nMaxCharLen;
193 
194         /* Optimization for UTF-8 - we try to calculate the exact length */
195         /* For all other encoding we try a good estimation */
196         if ( nEncoding == RTL_TEXTENCODING_UTF8 )
197         {
198             nNewLen = rtl_ImplGetFastUTF8ByteLen( pSource, nLength );
199             /* Includes the string only ASCII, then we could copy
200                the buffer faster */
201             if ( nNewLen == static_cast<sal_Size>(nLength) )
202             {
203                 char* pBuffer;
204                 if ( *pTarget )
205                     rtl_string_release( *pTarget );
206                 *pTarget = rtl_string_ImplAlloc( nLength );
207                 OSL_ASSERT(*pTarget != nullptr);
208                 pBuffer = (*pTarget)->buffer;
209                 do
210                 {
211                     /* Check ASCII range */
212                     OSL_ENSURE( *pSource <= 127,
213                                 "rtl_uString2String() - UTF8 test is encoding is wrong" );
214 
215                     *pBuffer = static_cast<char>(static_cast<unsigned char>(*pSource));
216                     pBuffer++;
217                     pSource++;
218                     nLength--;
219                 }
220                 while ( nLength );
221                 return true;
222             }
223 
224             nMaxCharLen = 4;
225         }
226         else
227         {
228             rtl_TextEncodingInfo aTextEncInfo;
229             aTextEncInfo.StructSize = sizeof( aTextEncInfo );
230             if ( !rtl_getTextEncodingInfo( nEncoding, &aTextEncInfo ) )
231             {
232                 aTextEncInfo.AverageCharSize    = 1;
233                 aTextEncInfo.MaximumCharSize    = 8;
234             }
235 
236             nNewLen = nLength * static_cast<sal_Size>(aTextEncInfo.AverageCharSize);
237             nMaxCharLen = aTextEncInfo.MaximumCharSize;
238         }
239 
240         nFlags |= RTL_UNICODETOTEXT_FLAGS_FLUSH;
241         hConverter = rtl_createUnicodeToTextConverter( nEncoding );
242 
243         for (;;)
244         {
245             pTemp = rtl_string_ImplAlloc( nNewLen );
246             OSL_ASSERT(pTemp != nullptr);
247             nDestBytes = rtl_convertUnicodeToText( hConverter, nullptr,
248                                                    pSource, nLength,
249                                                    pTemp->buffer, nNewLen,
250                                                    nFlags,
251                                                    &nInfo, &nSrcChars );
252             if (bCheckErrors && (nInfo & RTL_UNICODETOTEXT_INFO_ERROR) != 0)
253             {
254                 rtl_freeString(pTemp);
255                 rtl_destroyUnicodeToTextConverter(hConverter);
256                 return false;
257             }
258 
259             if ((nInfo & RTL_UNICODETOTEXT_INFO_DESTBUFFERTOSMALL) == 0)
260                 break;
261 
262             /* Buffer not big enough, try again with enough space */
263             rtl_freeString( pTemp );
264 
265             /* Try with the max. count of characters with
266                additional overhead for replacing functionality */
267             nNotConvertedChars = nLength-nSrcChars;
268             nNewLen = nDestBytes+(nNotConvertedChars*nMaxCharLen)+nNotConvertedChars+4;
269         }
270 
271         /* Set the buffer to the correct size or is there to
272            much overhead, reallocate to the correct size */
273         if ( nNewLen > nDestBytes+8 )
274         {
275             rtl_String* pTemp2 = rtl_string_ImplAlloc( nDestBytes );
276             OSL_ASSERT(pTemp2 != nullptr);
277             rtl::str::Copy(pTemp2->buffer, pTemp->buffer, nDestBytes);
278             rtl_freeString( pTemp );
279             pTemp = pTemp2;
280         }
281         else
282         {
283             pTemp->length = nDestBytes;
284             pTemp->buffer[nDestBytes] = 0;
285         }
286 
287         rtl_destroyUnicodeToTextConverter( hConverter );
288         if ( *pTarget )
289             rtl_string_release( *pTarget );
290         *pTarget = pTemp;
291 
292         /* Results the conversion in an empty buffer -
293            create an empty string */
294         if ( pTemp && !nDestBytes )
295             rtl_string_new( pTarget );
296     }
297     return true;
298 }
299 
rtl_uString2String(rtl_String ** ppThis,const sal_Unicode * pUStr,sal_Int32 nULen,rtl_TextEncoding eTextEncoding,sal_uInt32 nCvtFlags)300 void SAL_CALL rtl_uString2String( rtl_String** ppThis,
301                                   const sal_Unicode* pUStr,
302                                   sal_Int32 nULen,
303                                   rtl_TextEncoding eTextEncoding,
304                                   sal_uInt32 nCvtFlags )
305     SAL_THROW_EXTERN_C()
306 {
307     rtl_impl_convertUStringToString(ppThis, pUStr, nULen, eTextEncoding,
308                                     nCvtFlags, false);
309 }
310 
rtl_convertUStringToString(rtl_String ** pTarget,sal_Unicode const * pSource,sal_Int32 nLength,rtl_TextEncoding nEncoding,sal_uInt32 nFlags)311 sal_Bool SAL_CALL rtl_convertUStringToString(rtl_String ** pTarget,
312                                              sal_Unicode const * pSource,
313                                              sal_Int32 nLength,
314                                              rtl_TextEncoding nEncoding,
315                                              sal_uInt32 nFlags)
316     SAL_THROW_EXTERN_C()
317 {
318     return rtl_impl_convertUStringToString(pTarget, pSource, nLength, nEncoding,
319                                            nFlags, true);
320 }
321 
rtl_string_newReplaceFirst(rtl_String ** newStr,rtl_String * str,char const * from,sal_Int32 fromLength,char const * to,sal_Int32 toLength,sal_Int32 * index)322 void rtl_string_newReplaceFirst(
323     rtl_String ** newStr, rtl_String * str, char const * from,
324     sal_Int32 fromLength, char const * to, sal_Int32 toLength,
325     sal_Int32 * index) SAL_THROW_EXTERN_C()
326 {
327     assert(str != nullptr);
328     assert(index != nullptr);
329     assert(*index >= 0 && *index <= str->length);
330     assert(fromLength >= 0);
331     assert(toLength >= 0);
332     sal_Int32 i = rtl_str_indexOfStr_WithLength(
333         str->buffer + *index, str->length - *index, from, fromLength);
334     if (i == -1) {
335         rtl_string_assign(newStr, str);
336     } else {
337         assert(i <= str->length - *index);
338         i += *index;
339         assert(fromLength <= str->length);
340         if (str->length - fromLength > SAL_MAX_INT32 - toLength) {
341             std::abort();
342         }
343         sal_Int32 n = str->length - fromLength + toLength;
344         rtl_string_acquire(str); // in case *newStr == str
345         rtl_string_new_WithLength(newStr, n);
346         if (n != 0) {
347             (*newStr)->length = n;
348             assert(i >= 0 && i < str->length);
349             memcpy((*newStr)->buffer, str->buffer, i);
350             memcpy((*newStr)->buffer + i, to, toLength);
351             memcpy(
352                 (*newStr)->buffer + i + toLength, str->buffer + i + fromLength,
353                 str->length - i - fromLength);
354         }
355         rtl_string_release(str);
356     }
357     *index = i;
358 }
359 
rtl_string_newReplaceAll(rtl_String ** newStr,rtl_String * str,char const * from,sal_Int32 fromLength,char const * to,sal_Int32 toLength)360 void rtl_string_newReplaceAll(
361     rtl_String ** newStr, rtl_String * str, char const * from,
362     sal_Int32 fromLength, char const * to, sal_Int32 toLength)
363     SAL_THROW_EXTERN_C()
364 {
365     rtl_string_assign(newStr, str);
366     for (sal_Int32 i = 0;; i += toLength) {
367         rtl_string_newReplaceFirst(
368             newStr, *newStr, from, fromLength, to, toLength, &i);
369         if (i == -1) {
370             break;
371         }
372     }
373 }
374 
rtl_str_getLength(const char * pStr)375 sal_Int32 SAL_CALL rtl_str_getLength(const char* pStr) SAL_THROW_EXTERN_C()
376 {
377     return rtl::str::getLength(pStr);
378 }
379 
rtl_str_compare(const char * pStr1,const char * pStr2)380 sal_Int32 SAL_CALL rtl_str_compare(const char* pStr1, const char* pStr2) SAL_THROW_EXTERN_C()
381 {
382     return rtl::str::compare(pStr1, pStr2);
383 }
384 
rtl_str_compare_WithLength(const char * pStr1,sal_Int32 nStr1Len,const char * pStr2,sal_Int32 nStr2Len)385 sal_Int32 SAL_CALL rtl_str_compare_WithLength(const char* pStr1, sal_Int32 nStr1Len,
386                                               const char* pStr2, sal_Int32 nStr2Len)
387     SAL_THROW_EXTERN_C()
388 {
389     return rtl::str::compare_WithLength(pStr1, nStr1Len, pStr2, nStr2Len);
390 }
391 
rtl_str_shortenedCompare_WithLength(const char * pStr1,sal_Int32 nStr1Len,const char * pStr2,sal_Int32 nStr2Len,sal_Int32 nShortenedLength)392 sal_Int32 SAL_CALL rtl_str_shortenedCompare_WithLength(const char* pStr1, sal_Int32 nStr1Len,
393                                                        const char* pStr2, sal_Int32 nStr2Len,
394                                                        sal_Int32 nShortenedLength)
395     SAL_THROW_EXTERN_C()
396 {
397     return rtl::str::shortenedCompare_WithLength(pStr1, nStr1Len, pStr2, nStr2Len, nShortenedLength);
398 }
399 
rtl_str_reverseCompare_WithLength(const char * pStr1,sal_Int32 nStr1Len,const char * pStr2,sal_Int32 nStr2Len)400 sal_Int32 SAL_CALL rtl_str_reverseCompare_WithLength(const char* pStr1, sal_Int32 nStr1Len,
401                                                      const char* pStr2, sal_Int32 nStr2Len)
402     SAL_THROW_EXTERN_C()
403 {
404     return rtl::str::reverseCompare_WithLength(pStr1, nStr1Len, pStr2, nStr2Len);
405 }
406 
rtl_str_compareIgnoreAsciiCase(const char * pStr1,const char * pStr2)407 sal_Int32 SAL_CALL rtl_str_compareIgnoreAsciiCase(const char* pStr1, const char* pStr2)
408     SAL_THROW_EXTERN_C()
409 {
410     return rtl::str::compareIgnoreAsciiCase(pStr1, pStr2);
411 }
412 
rtl_str_compareIgnoreAsciiCase_WithLength(const char * pStr1,sal_Int32 nStr1Len,const char * pStr2,sal_Int32 nStr2Len)413 sal_Int32 SAL_CALL rtl_str_compareIgnoreAsciiCase_WithLength(const char* pStr1, sal_Int32 nStr1Len,
414                                                              const char* pStr2, sal_Int32 nStr2Len)
415     SAL_THROW_EXTERN_C()
416 {
417     return rtl::str::compareIgnoreAsciiCase_WithLength(pStr1, nStr1Len, pStr2, nStr2Len);
418 }
419 
rtl_str_shortenedCompareIgnoreAsciiCase_WithLength(const char * pStr1,sal_Int32 nStr1Len,const char * pStr2,sal_Int32 nStr2Len,sal_Int32 nShortenedLength)420 sal_Int32 SAL_CALL rtl_str_shortenedCompareIgnoreAsciiCase_WithLength(
421     const char* pStr1, sal_Int32 nStr1Len, const char* pStr2, sal_Int32 nStr2Len,
422     sal_Int32 nShortenedLength) SAL_THROW_EXTERN_C()
423 {
424     return rtl::str::shortenedCompareIgnoreAsciiCase_WithLength(pStr1, nStr1Len, pStr2, nStr2Len,
425                                                               nShortenedLength);
426 }
427 
rtl_str_hashCode(const char * pStr)428 sal_Int32 SAL_CALL rtl_str_hashCode(const char* pStr) SAL_THROW_EXTERN_C()
429 {
430     return rtl::str::hashCode(pStr);
431 }
432 
rtl_str_hashCode_WithLength(const char * pStr,sal_Int32 nLen)433 sal_Int32 SAL_CALL rtl_str_hashCode_WithLength(const char* pStr, sal_Int32 nLen)
434     SAL_THROW_EXTERN_C()
435 {
436     return rtl::str::hashCode_WithLength(pStr, nLen);
437 }
438 
rtl_str_indexOfChar(const char * pStr,char c)439 sal_Int32 SAL_CALL rtl_str_indexOfChar(const char* pStr, char c) SAL_THROW_EXTERN_C()
440 {
441     return rtl::str::indexOfChar(pStr, c);
442 }
443 
rtl_str_indexOfChar_WithLength(const char * pStr,sal_Int32 nLen,char c)444 sal_Int32 SAL_CALL rtl_str_indexOfChar_WithLength(const char* pStr, sal_Int32 nLen, char c)
445     SAL_THROW_EXTERN_C()
446 {
447     return rtl::str::indexOfChar_WithLength(pStr, nLen, c);
448 }
449 
rtl_str_lastIndexOfChar(const char * pStr,char c)450 sal_Int32 SAL_CALL rtl_str_lastIndexOfChar(const char* pStr, char c) SAL_THROW_EXTERN_C()
451 {
452     return rtl::str::lastIndexOfChar(pStr, c);
453 }
454 
rtl_str_lastIndexOfChar_WithLength(const char * pStr,sal_Int32 nLen,char c)455 sal_Int32 SAL_CALL rtl_str_lastIndexOfChar_WithLength(const char* pStr, sal_Int32 nLen, char c)
456     SAL_THROW_EXTERN_C()
457 {
458     return rtl::str::lastIndexOfChar_WithLength(pStr, nLen, c);
459 }
460 
rtl_str_indexOfStr(const char * pStr,const char * pSubStr)461 sal_Int32 SAL_CALL rtl_str_indexOfStr(const char* pStr, const char* pSubStr) SAL_THROW_EXTERN_C()
462 {
463     return rtl::str::indexOfStr(pStr, pSubStr);
464 }
465 
rtl_str_indexOfStr_WithLength(const char * pStr,sal_Int32 nStrLen,const char * pSubStr,sal_Int32 nSubLen)466 sal_Int32 SAL_CALL rtl_str_indexOfStr_WithLength(const char* pStr, sal_Int32 nStrLen,
467                                                  const char* pSubStr, sal_Int32 nSubLen)
468     SAL_THROW_EXTERN_C()
469 {
470     return rtl::str::indexOfStr_WithLength(pStr, nStrLen, pSubStr, nSubLen);
471 }
472 
rtl_str_lastIndexOfStr(const char * pStr,const char * pSubStr)473 sal_Int32 SAL_CALL rtl_str_lastIndexOfStr(const char* pStr, const char* pSubStr)
474     SAL_THROW_EXTERN_C()
475 {
476     return rtl::str::lastIndexOfStr(pStr, pSubStr);
477 }
478 
rtl_str_lastIndexOfStr_WithLength(const char * pStr,sal_Int32 nStrLen,const char * pSubStr,sal_Int32 nSubLen)479 sal_Int32 SAL_CALL rtl_str_lastIndexOfStr_WithLength(const char* pStr, sal_Int32 nStrLen,
480                                                      const char* pSubStr, sal_Int32 nSubLen)
481     SAL_THROW_EXTERN_C()
482 {
483     return rtl::str::lastIndexOfStr_WithLength(pStr, nStrLen, pSubStr, nSubLen);
484 }
485 
rtl_str_replaceChar(char * pStr,char cOld,char cNew)486 void SAL_CALL rtl_str_replaceChar(char* pStr, char cOld, char cNew) SAL_THROW_EXTERN_C()
487 {
488     return rtl::str::replaceChar(pStr, cOld, cNew);
489 }
490 
rtl_str_replaceChar_WithLength(char * pStr,sal_Int32 nLen,char cOld,char cNew)491 void SAL_CALL rtl_str_replaceChar_WithLength(char* pStr, sal_Int32 nLen, char cOld, char cNew)
492     SAL_THROW_EXTERN_C()
493 {
494     return rtl::str::replaceChar_WithLength(pStr, nLen, cOld, cNew);
495 }
496 
rtl_str_toAsciiLowerCase(char * pStr)497 void SAL_CALL rtl_str_toAsciiLowerCase(char* pStr) SAL_THROW_EXTERN_C()
498 {
499     return rtl::str::toAsciiLowerCase(pStr);
500 }
501 
rtl_str_toAsciiLowerCase_WithLength(char * pStr,sal_Int32 nLen)502 void SAL_CALL rtl_str_toAsciiLowerCase_WithLength(char* pStr, sal_Int32 nLen) SAL_THROW_EXTERN_C()
503 {
504     return rtl::str::toAsciiLowerCase_WithLength(pStr, nLen);
505 }
506 
rtl_str_toAsciiUpperCase(char * pStr)507 void SAL_CALL rtl_str_toAsciiUpperCase(char* pStr) SAL_THROW_EXTERN_C()
508 {
509     return rtl::str::toAsciiUpperCase(pStr);
510 }
511 
rtl_str_toAsciiUpperCase_WithLength(char * pStr,sal_Int32 nLen)512 void SAL_CALL rtl_str_toAsciiUpperCase_WithLength(char* pStr, sal_Int32 nLen) SAL_THROW_EXTERN_C()
513 {
514     return rtl::str::toAsciiUpperCase_WithLength(pStr, nLen);
515 }
516 
rtl_str_trim(char * pStr)517 sal_Int32 SAL_CALL rtl_str_trim(char* pStr) SAL_THROW_EXTERN_C() { return rtl::str::trim(pStr); }
518 
rtl_str_trim_WithLength(char * pStr,sal_Int32 nLen)519 sal_Int32 SAL_CALL rtl_str_trim_WithLength(char* pStr, sal_Int32 nLen) SAL_THROW_EXTERN_C()
520 {
521     return rtl::str::trim_WithLength(pStr, nLen);
522 }
523 
rtl_str_valueOfBoolean(char * pStr,sal_Bool b)524 sal_Int32 SAL_CALL rtl_str_valueOfBoolean(char* pStr, sal_Bool b) SAL_THROW_EXTERN_C()
525 {
526     return rtl::str::valueOfBoolean(pStr, b);
527 }
528 
rtl_str_valueOfChar(char * pStr,char c)529 sal_Int32 SAL_CALL rtl_str_valueOfChar(char* pStr, char c) SAL_THROW_EXTERN_C()
530 {
531     return rtl::str::valueOfChar(pStr, c);
532 }
533 
rtl_str_valueOfInt32(char * pStr,sal_Int32 n,sal_Int16 nRadix)534 sal_Int32 SAL_CALL rtl_str_valueOfInt32(char* pStr, sal_Int32 n, sal_Int16 nRadix)
535     SAL_THROW_EXTERN_C()
536 {
537     return rtl::str::valueOfInt32(pStr, n, nRadix);
538 }
539 
rtl_str_valueOfInt64(char * pStr,sal_Int64 n,sal_Int16 nRadix)540 sal_Int32 SAL_CALL rtl_str_valueOfInt64(char* pStr, sal_Int64 n, sal_Int16 nRadix)
541     SAL_THROW_EXTERN_C()
542 {
543     return rtl::str::valueOfInt64(pStr, n, nRadix);
544 }
545 
rtl_str_valueOfUInt64(char * pStr,sal_uInt64 n,sal_Int16 nRadix)546 sal_Int32 SAL_CALL rtl_str_valueOfUInt64(char* pStr, sal_uInt64 n, sal_Int16 nRadix)
547     SAL_THROW_EXTERN_C()
548 {
549     return rtl::str::valueOfUInt64(pStr, n, nRadix);
550 }
551 
rtl_str_toBoolean(const char * pStr)552 sal_Bool SAL_CALL rtl_str_toBoolean(const char* pStr) SAL_THROW_EXTERN_C()
553 {
554     return rtl::str::toBoolean(pStr);
555 }
556 
rtl_str_toInt32(const char * pStr,sal_Int16 nRadix)557 sal_Int32 SAL_CALL rtl_str_toInt32(const char* pStr, sal_Int16 nRadix) SAL_THROW_EXTERN_C()
558 {
559     return rtl::str::toInt32(pStr, nRadix);
560 }
561 
rtl_str_toInt64(const char * pStr,sal_Int16 nRadix)562 sal_Int64 SAL_CALL rtl_str_toInt64(const char* pStr, sal_Int16 nRadix) SAL_THROW_EXTERN_C()
563 {
564     return rtl::str::toInt64(pStr, nRadix);
565 }
566 
rtl_str_toInt64_WithLength(const char * pStr,sal_Int16 nRadix,sal_Int32 nStrLength)567 sal_Int64 SAL_CALL rtl_str_toInt64_WithLength(const char* pStr, sal_Int16 nRadix,
568                                               sal_Int32 nStrLength) SAL_THROW_EXTERN_C()
569 {
570     return rtl::str::toInt64_WithLength(pStr, nRadix, nStrLength);
571 }
572 
rtl_str_toUInt32(const char * pStr,sal_Int16 nRadix)573 sal_uInt32 SAL_CALL rtl_str_toUInt32(const char* pStr, sal_Int16 nRadix) SAL_THROW_EXTERN_C()
574 {
575     return rtl::str::toUInt32(pStr, nRadix);
576 }
577 
rtl_str_toUInt64(const char * pStr,sal_Int16 nRadix)578 sal_uInt64 SAL_CALL rtl_str_toUInt64(const char* pStr, sal_Int16 nRadix) SAL_THROW_EXTERN_C()
579 {
580     return rtl::str::toUInt64(pStr, nRadix);
581 }
582 
rtl_string_ImplAlloc(sal_Int32 nLen)583 rtl_String* rtl_string_ImplAlloc(sal_Int32 nLen) { return rtl::str::Alloc<rtl_String>(nLen); }
584 
rtl_string_acquire(rtl_String * pThis)585 void SAL_CALL rtl_string_acquire(rtl_String* pThis) SAL_THROW_EXTERN_C()
586 {
587     return rtl::str::acquire(pThis);
588 }
589 
rtl_string_release(rtl_String * pThis)590 void SAL_CALL rtl_string_release(rtl_String* pThis) SAL_THROW_EXTERN_C()
591 {
592     return rtl::str::release(pThis);
593 }
594 
rtl_string_new(rtl_String ** ppThis)595 void SAL_CALL rtl_string_new(rtl_String** ppThis) SAL_THROW_EXTERN_C()
596 {
597     return rtl::str::new_(ppThis);
598 }
599 
rtl_string_alloc(sal_Int32 nLen)600 rtl_String* SAL_CALL rtl_string_alloc(sal_Int32 nLen) SAL_THROW_EXTERN_C()
601 {
602     return rtl::str::alloc<rtl_String>(nLen);
603 }
604 
rtl_string_new_WithLength(rtl_String ** ppThis,sal_Int32 nLen)605 void SAL_CALL rtl_string_new_WithLength(rtl_String** ppThis, sal_Int32 nLen) SAL_THROW_EXTERN_C()
606 {
607     rtl::str::new_WithLength(ppThis, nLen);
608 }
609 
rtl_string_newFromString(rtl_String ** ppThis,const rtl_String * pStr)610 void SAL_CALL rtl_string_newFromString(rtl_String** ppThis, const rtl_String* pStr)
611     SAL_THROW_EXTERN_C()
612 {
613     rtl::str::newFromString(ppThis, pStr);
614 }
615 
rtl_string_newFromStr(rtl_String ** ppThis,const char * pCharStr)616 void SAL_CALL rtl_string_newFromStr(rtl_String** ppThis, const char* pCharStr) SAL_THROW_EXTERN_C()
617 {
618     rtl::str::newFromStr(ppThis, pCharStr);
619 }
620 
rtl_string_newFromStr_WithLength(rtl_String ** ppThis,const char * pCharStr,sal_Int32 nLen)621 void SAL_CALL rtl_string_newFromStr_WithLength(rtl_String** ppThis, const char* pCharStr,
622                                                sal_Int32 nLen) SAL_THROW_EXTERN_C()
623 {
624     rtl::str::newFromStr_WithLength(ppThis, pCharStr, nLen);
625 }
626 
rtl_string_newFromSubString(rtl_String ** ppThis,const rtl_String * pFrom,sal_Int32 beginIndex,sal_Int32 count)627 void SAL_CALL rtl_string_newFromSubString(rtl_String** ppThis, const rtl_String* pFrom,
628                                           sal_Int32 beginIndex, sal_Int32 count)
629     SAL_THROW_EXTERN_C()
630 {
631     rtl::str::newFromSubString(ppThis, pFrom, beginIndex, count);
632 }
633 
634 // Used when creating from string literals.
rtl_string_newFromLiteral(rtl_String ** ppThis,const char * pCharStr,sal_Int32 nLen,sal_Int32 allocExtra)635 void SAL_CALL rtl_string_newFromLiteral(rtl_String** ppThis, const char* pCharStr, sal_Int32 nLen,
636                                         sal_Int32 allocExtra) SAL_THROW_EXTERN_C()
637 {
638     rtl::str::newFromLiteral(ppThis, pCharStr, nLen, allocExtra);
639 }
640 
rtl_string_assign(rtl_String ** ppThis,rtl_String * pStr)641 void SAL_CALL rtl_string_assign(rtl_String** ppThis, rtl_String* pStr) SAL_THROW_EXTERN_C()
642 {
643     rtl::str::assign(ppThis, pStr);
644 }
645 
rtl_string_getLength(const rtl_String * pThis)646 sal_Int32 SAL_CALL rtl_string_getLength(const rtl_String* pThis) SAL_THROW_EXTERN_C()
647 {
648     return rtl::str::getLength(pThis);
649 }
650 
rtl_string_getStr(rtl_String * pThis)651 char* SAL_CALL rtl_string_getStr(rtl_String* pThis) SAL_THROW_EXTERN_C()
652 {
653     return rtl::str::getStr(pThis);
654 }
655 
rtl_string_newConcat(rtl_String ** ppThis,rtl_String * pLeft,rtl_String * pRight)656 void SAL_CALL rtl_string_newConcat(rtl_String** ppThis, rtl_String* pLeft, rtl_String* pRight)
657     SAL_THROW_EXTERN_C()
658 {
659     rtl::str::newConcat(ppThis, pLeft, pRight);
660 }
661 
rtl_string_ensureCapacity(rtl_String ** ppThis,sal_Int32 size)662 void SAL_CALL rtl_string_ensureCapacity(rtl_String** ppThis, sal_Int32 size) SAL_THROW_EXTERN_C()
663 {
664     rtl::str::ensureCapacity(ppThis, size);
665 }
666 
rtl_string_newReplaceStrAt(rtl_String ** ppThis,rtl_String * pStr,sal_Int32 nIndex,sal_Int32 nCount,rtl_String * pNewSubStr)667 void SAL_CALL rtl_string_newReplaceStrAt(rtl_String** ppThis, rtl_String* pStr, sal_Int32 nIndex,
668                                          sal_Int32 nCount, rtl_String* pNewSubStr)
669     SAL_THROW_EXTERN_C()
670 {
671     rtl::str::newReplaceStrAt(ppThis, pStr, nIndex, nCount, pNewSubStr);
672 }
673 
rtl_string_newReplace(rtl_String ** ppThis,rtl_String * pStr,char cOld,char cNew)674 void SAL_CALL rtl_string_newReplace(rtl_String** ppThis, rtl_String* pStr, char cOld, char cNew)
675     SAL_THROW_EXTERN_C()
676 {
677     rtl::str::newReplace(ppThis, pStr, cOld, cNew);
678 }
679 
rtl_string_newToAsciiLowerCase(rtl_String ** ppThis,rtl_String * pStr)680 void SAL_CALL rtl_string_newToAsciiLowerCase(rtl_String** ppThis, rtl_String* pStr)
681     SAL_THROW_EXTERN_C()
682 {
683     rtl::str::newToAsciiLowerCase(ppThis, pStr);
684 }
685 
rtl_string_newToAsciiUpperCase(rtl_String ** ppThis,rtl_String * pStr)686 void SAL_CALL rtl_string_newToAsciiUpperCase(rtl_String** ppThis, rtl_String* pStr)
687     SAL_THROW_EXTERN_C()
688 {
689     rtl::str::newToAsciiUpperCase(ppThis, pStr);
690 }
691 
rtl_string_newTrim(rtl_String ** ppThis,rtl_String * pStr)692 void SAL_CALL rtl_string_newTrim(rtl_String** ppThis, rtl_String* pStr) SAL_THROW_EXTERN_C()
693 {
694     rtl::str::newTrim(ppThis, pStr);
695 }
696 
rtl_string_getToken(rtl_String ** ppThis,rtl_String * pStr,sal_Int32 nToken,char cTok,sal_Int32 nIndex)697 sal_Int32 SAL_CALL rtl_string_getToken(rtl_String** ppThis, rtl_String* pStr, sal_Int32 nToken,
698                                        char cTok, sal_Int32 nIndex) SAL_THROW_EXTERN_C()
699 {
700     return rtl::str::getToken(ppThis, pStr, nToken, cTok, nIndex);
701 }
702 
703 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
704