1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
21 * This file is part of LibreOffice published API.
24 #ifndef INCLUDED_RTL_STRING_H
25 #define INCLUDED_RTL_STRING_H
27 #include "sal/config.h"
29 #include "osl/interlck.h"
30 #include "rtl/textcvt.h"
31 #include "sal/saldllapi.h"
32 #include "sal/types.h"
38 /* ======================================================================= */
40 /** Return the length of a string.
42 The length is equal to the number of 8-bit characters in the string,
43 without the terminating NUL character.
46 a null-terminated string.
49 the length of the sequence of characters represented by this string,
50 excluding the terminating NUL character.
52 SAL_DLLPUBLIC sal_Int32 SAL_CALL
rtl_str_getLength(
53 const char * str
) SAL_THROW_EXTERN_C();
55 /** Compare two strings.
57 The comparison is based on the numeric value of each character in the
58 strings and returns a value indicating their relationship. This function
59 cannot be used for language-specific sorting. Both strings must be
63 the first null-terminated string to be compared.
66 the second null-terminated string which is compared with the first one.
69 0 if both strings are equal, a value less than 0 if the first string is
70 less than the second string, and a value greater than 0 if the first
71 string is greater than the second string.
73 SAL_DLLPUBLIC sal_Int32 SAL_CALL
rtl_str_compare(
74 const char * first
, const char * second
) SAL_THROW_EXTERN_C();
76 /** Compare two strings.
78 The comparison is based on the numeric value of each character in the
79 strings and returns a value indicating their relationship. This function
80 cannot be used for language-specific sorting.
83 the first string to be compared. Need not be null-terminated, but must be
84 at least as long as the specified firstLen.
87 the length of the first string.
90 the second string which is compared with the first one. Need not be
91 null-terminated, but must be at least as long as the specified secondLen.
94 the length of the second string.
97 0 if both strings are equal, a value less than 0 if the first string is
98 less than the second string, and a value greater than 0 if the first
99 string is greater than the second string.
101 SAL_DLLPUBLIC sal_Int32 SAL_CALL
rtl_str_compare_WithLength(
102 const char * first
, sal_Int32 firstLen
, const char * second
, sal_Int32 secondLen
) SAL_THROW_EXTERN_C();
104 /** Compare two strings with a maximum count of characters.
106 The comparison is based on the numeric value of each character in the
107 strings and returns a value indicating their relationship. This function
108 cannot be used for language-specific sorting.
111 the first string to be compared. Need not be null-terminated, but must be
112 at least as long as the specified firstLen.
115 the length of the first string.
118 the second string which is compared with the first one. Need not be
119 null-terminated, but must be at least as long as the specified secondLen.
122 the length of the second string.
125 the maximum number of characters to compare. This length can be greater
126 or smaller than the lengths of the two strings.
129 0 if both substrings are equal, a value less than 0 if the first substring
130 is less than the second substring, and a value greater than 0 if the first
131 substring is greater than the second substring.
133 SAL_DLLPUBLIC sal_Int32 SAL_CALL
rtl_str_shortenedCompare_WithLength(
134 const char * first
, sal_Int32 firstLen
, const char * second
, sal_Int32 secondLen
, sal_Int32 shortenedLen
) SAL_THROW_EXTERN_C();
136 /** Compare two strings from back to front.
138 The comparison is based on the numeric value of each character in the
139 strings and returns a value indicating their relationship. This function
140 cannot be used for language-specific sorting.
143 the first string to be compared. Need not be null-terminated, but must be
144 at least as long as the specified firstLen.
147 the length of the first string.
150 the second string which is compared with the first one. Need not be
151 null-terminated, but must be at least as long as the specified secondLen.
154 the length of the second string.
157 0 if both strings are equal, a value less than 0 if the first string
158 compares less than the second string, and a value greater than 0 if the
159 first string compares greater than the second string.
161 SAL_DLLPUBLIC sal_Int32 SAL_CALL
rtl_str_reverseCompare_WithLength(
162 const char * first
, sal_Int32 firstLen
, const char * second
, sal_Int32 secondLen
) SAL_THROW_EXTERN_C();
164 /** Compare two strings, ignoring the case of ASCII characters.
166 The comparison is based on the numeric value of each character in the
167 strings and returns a value indicating their relationship. Character
168 values between 65 and 90 (ASCII A--Z) are interpreted as values between 97
169 and 122 (ASCII a--z). This function cannot be used for language-specific
170 sorting. Both strings must be null-terminated.
173 the first null-terminated string to be compared.
176 the second null-terminated string which is compared with the first one.
179 0 if both strings are equal, a value less than 0 if the first string is
180 less than the second string, and a value greater than 0 if the first
181 string is greater than the second string.
183 SAL_DLLPUBLIC sal_Int32 SAL_CALL
rtl_str_compareIgnoreAsciiCase(
184 const char * first
, const char * second
) SAL_THROW_EXTERN_C();
186 /** Compare two strings, ignoring the case of ASCII characters.
188 The comparison is based on the numeric value of each character in the
189 strings and returns a value indicating their relationship. Character
190 values between 65 and 90 (ASCII A--Z) are interpreted as values between 97
191 and 122 (ASCII a--z). This function cannot be used for language-specific
195 the first string to be compared. Need not be null-terminated, but must be
196 at least as long as the specified firstLen.
199 the length of the first string.
202 the second string which is compared with the first one. Need not be
203 null-terminated, but must be at least as long as the specified secondLen.
206 the length of the second string.
209 0 if both strings are equal, a value less than 0 if the first string is
210 less than the second string, and a value greater than 0 if the first
211 string is greater than the second string.
213 SAL_DLLPUBLIC sal_Int32 SAL_CALL
rtl_str_compareIgnoreAsciiCase_WithLength(
214 const char * first
, sal_Int32 firstLen
, const char * second
, sal_Int32 secondLen
) SAL_THROW_EXTERN_C();
216 /** Compare two strings with a maximum count of characters, ignoring the case
219 The comparison is based on the numeric value of each character in the
220 strings and returns a value indicating their relationship. Character
221 values between 65 and 90 (ASCII A--Z) are interpreted as values between 97
222 and 122 (ASCII a--z). This function cannot be used for language-specific
226 the first string to be compared. Need not be null-terminated, but must be
227 at least as long as the specified firstLen.
230 the length of the first string.
233 the second string which is compared with the first one. Need not be
234 null-terminated, but must be at least as long as the specified secondLen.
237 the length of the second string.
240 the maximum number of characters to compare. This length can be greater
241 or smaller than the lengths of the two strings.
244 0 if both substrings are equal, a value less than 0 if the first substring
245 is less than the second substring, and a value greater than 0 if the first
246 substring is greater than the second substring.
248 SAL_DLLPUBLIC sal_Int32 SAL_CALL
rtl_str_shortenedCompareIgnoreAsciiCase_WithLength(
249 const char * first
, sal_Int32 firstLen
, const char * second
, sal_Int32 secondLen
, sal_Int32 shortenedLen
) SAL_THROW_EXTERN_C();
251 /** Return a hash code for a string.
253 It is not allowed to store the hash code persistently, because later
254 versions could return other hash codes. The string must be
258 a null-terminated string.
261 a hash code for the given string.
263 SAL_DLLPUBLIC sal_Int32 SAL_CALL
rtl_str_hashCode(
264 const char * str
) SAL_THROW_EXTERN_C();
266 /** Return a hash code for a string.
268 It is not allowed to store the hash code persistently, because later
269 versions could return other hash codes.
272 a string. Need not be null-terminated, but must be at least as long as
276 the length of the string.
279 a hash code for the given string.
281 SAL_DLLPUBLIC sal_Int32 SAL_CALL
rtl_str_hashCode_WithLength(
282 const char * str
, sal_Int32 len
) SAL_THROW_EXTERN_C();
284 /** Search for the first occurrence of a character within a string.
286 The string must be null-terminated.
289 a null-terminated string.
292 the character to be searched for.
295 the index (starting at 0) of the first occurrence of the character in the
296 string, or -1 if the character does not occur.
298 SAL_DLLPUBLIC sal_Int32 SAL_CALL
rtl_str_indexOfChar(
299 const char * str
, char ch
) SAL_THROW_EXTERN_C();
301 /** Search for the first occurrence of a character within a string.
304 a string. Need not be null-terminated, but must be at least as long as
308 the length of the string.
311 the character to be searched for.
314 the index (starting at 0) of the first occurrence of the character in the
315 string, or -1 if the character does not occur.
317 SAL_DLLPUBLIC sal_Int32 SAL_CALL
rtl_str_indexOfChar_WithLength(
318 const char * str
, sal_Int32 len
, char ch
) SAL_THROW_EXTERN_C();
320 /** Search for the last occurrence of a character within a string.
322 The string must be null-terminated.
325 a null-terminated string.
328 the character to be searched for.
331 the index (starting at 0) of the last occurrence of the character in the
332 string, or -1 if the character does not occur. The returned value is
333 always smaller than the string length.
335 SAL_DLLPUBLIC sal_Int32 SAL_CALL
rtl_str_lastIndexOfChar(
336 const char * str
, char ch
) SAL_THROW_EXTERN_C();
338 /** Search for the last occurrence of a character within a string.
341 a string. Need not be null-terminated, but must be at least as long as
345 the length of the string.
348 the character to be searched for.
351 the index (starting at 0) of the last occurrence of the character in the
352 string, or -1 if the character does not occur. The returned value is
353 always smaller than the string length.
355 SAL_DLLPUBLIC sal_Int32 SAL_CALL
rtl_str_lastIndexOfChar_WithLength(
356 const char * str
, sal_Int32 len
, char ch
) SAL_THROW_EXTERN_C();
358 /** Search for the first occurrence of a substring within a string.
360 If subStr is empty, or both str and subStr are empty, -1 is returned.
361 Both strings must be null-terminated.
364 a null-terminated string.
367 the null-terminated substring to be searched for.
370 the index (starting at 0) of the first character of the first occurrence
371 of the substring within the string, or -1 if the substring does not occur.
373 SAL_DLLPUBLIC sal_Int32 SAL_CALL
rtl_str_indexOfStr(
374 const char * str
, const char * subStr
) SAL_THROW_EXTERN_C();
376 /** Search for the first occurrence of a substring within a string.
378 If subStr is empty, or both str and subStr are empty, -1 is returned.
381 a string. Need not be null-terminated, but must be at least as long as
385 the length of the string.
388 the substring to be searched for. Need not be null-terminated, but must
389 be at least as long as the specified subLen.
392 the length of the substring.
395 the index (starting at 0) of the first character of the first occurrence
396 of the substring within the string, or -1 if the substring does not occur.
398 SAL_DLLPUBLIC sal_Int32 SAL_CALL
rtl_str_indexOfStr_WithLength(
399 const char * str
, sal_Int32 len
, const char * subStr
, sal_Int32 subLen
) SAL_THROW_EXTERN_C();
401 /** Search for the last occurrence of a substring within a string.
403 If subStr is empty, or both str and subStr are empty, -1 is returned.
404 Both strings must be null-terminated.
407 a null-terminated string.
410 the null-terminated substring to be searched for.
413 the index (starting at 0) of the first character of the last occurrence
414 of the substring within the string, or -1 if the substring does not occur.
416 SAL_DLLPUBLIC sal_Int32 SAL_CALL
rtl_str_lastIndexOfStr(
417 const char * str
, const char * subStr
) SAL_THROW_EXTERN_C();
419 /** Search for the last occurrence of a substring within a string.
421 If subStr is empty, or both str and subStr are empty, -1 is returned.
424 a string. Need not be null-terminated, but must be at least as long as
428 the length of the string.
431 the substring to be searched for. Need not be null-terminated, but must
432 be at least as long as the specified subLen.
435 the length of the substring.
438 the index (starting at 0) of the first character of the first occurrence
439 of the substring within the string, or -1 if the substring does not occur.
441 SAL_DLLPUBLIC sal_Int32 SAL_CALL
rtl_str_lastIndexOfStr_WithLength(
442 const char * str
, sal_Int32 len
, const char * subStr
, sal_Int32 subLen
) SAL_THROW_EXTERN_C();
444 /** Replace all occurrences of a single character within a string.
446 If oldChar does not occur within str, then the string is not modified.
447 The string must be null-terminated.
450 a null-terminated string.
458 SAL_DLLPUBLIC
void SAL_CALL
rtl_str_replaceChar(
459 char * str
, char oldChar
, char newChar
) SAL_THROW_EXTERN_C();
461 /** Replace all occurrences of a single character within a string.
463 If oldChar does not occur within str, then the string is not modified.
466 a string. Need not be null-terminated, but must be at least as long as
470 the length of the string.
478 SAL_DLLPUBLIC
void SAL_CALL
rtl_str_replaceChar_WithLength(
479 char * str
, sal_Int32 len
, char oldChar
, char newChar
) SAL_THROW_EXTERN_C();
481 /** Convert all ASCII uppercase letters to lowercase within a string.
483 The characters with values between 65 and 90 (ASCII A--Z) are replaced
484 with values between 97 and 122 (ASCII a--z). The string must be
488 a null-terminated string.
490 SAL_DLLPUBLIC
void SAL_CALL
rtl_str_toAsciiLowerCase(
491 char * str
) SAL_THROW_EXTERN_C();
493 /** Convert all ASCII uppercase letters to lowercase within a string.
495 The characters with values between 65 and 90 (ASCII A--Z) are replaced
496 with values between 97 and 122 (ASCII a--z).
499 a string. Need not be null-terminated, but must be at least as long as
503 the length of the string.
505 SAL_DLLPUBLIC
void SAL_CALL
rtl_str_toAsciiLowerCase_WithLength(
506 char * str
, sal_Int32 len
) SAL_THROW_EXTERN_C();
508 /** Convert all ASCII lowercase letters to uppercase within a string.
510 The characters with values between 97 and 122 (ASCII a--z) are replaced
511 with values between 65 and 90 (ASCII A--Z). The string must be
515 a null-terminated string.
517 SAL_DLLPUBLIC
void SAL_CALL
rtl_str_toAsciiUpperCase(
518 char * str
) SAL_THROW_EXTERN_C();
520 /** Convert all ASCII lowercase letters to uppercase within a string.
522 The characters with values between 97 and 122 (ASCII a--z) are replaced
523 with values between 65 and 90 (ASCII A--Z).
526 a string. Need not be null-terminated, but must be at least as long as
530 the length of the string.
532 SAL_DLLPUBLIC
void SAL_CALL
rtl_str_toAsciiUpperCase_WithLength(
533 char * str
, sal_Int32 len
) SAL_THROW_EXTERN_C();
535 /** Remove white space from both ends of a string.
537 All characters with values less than or equal to 32 (the space character)
538 are considered to be white space. This function cannot be used for
539 language-specific operations. The string must be null-terminated.
542 a null-terminated string.
545 the new length of the string.
547 SAL_DLLPUBLIC sal_Int32 SAL_CALL
rtl_str_trim(
548 char * str
) SAL_THROW_EXTERN_C();
550 /** Remove white space from both ends of the string.
552 All characters with values less than or equal to 32 (the space character)
553 are considered to be white space. This function cannot be used for
554 language-specific operations. The string must be null-terminated.
557 a string. Need not be null-terminated, but must be at least as long as
561 the original length of the string.
564 the new length of the string.
566 SAL_DLLPUBLIC sal_Int32 SAL_CALL
rtl_str_trim_WithLength(
567 char * str
, sal_Int32 len
) SAL_THROW_EXTERN_C();
569 /** Create the string representation of a boolean.
571 If b is true, the buffer is filled with the string "true" and 5 is
572 returned. If b is false, the buffer is filled with the string "false" and
573 6 is returned. This function cannot be used for language-specific
577 a buffer that is big enough to hold the result and the terminating NUL
578 character. You should use the RTL_STR_MAX_VALUEOFBOOLEAN define to create
579 a buffer that is big enough.
585 the length of the string.
587 SAL_DLLPUBLIC sal_Int32 SAL_CALL
rtl_str_valueOfBoolean(
588 char * str
, sal_Bool b
) SAL_THROW_EXTERN_C();
589 #define RTL_STR_MAX_VALUEOFBOOLEAN 6
591 /** Create the string representation of a character.
594 a buffer that is big enough to hold the result and the terminating NUL
595 character. You should use the RTL_STR_MAX_VALUEOFCHAR define to create a
596 buffer that is big enough.
602 the length of the string.
604 SAL_DLLPUBLIC sal_Int32 SAL_CALL
rtl_str_valueOfChar(
605 char * str
, char ch
) SAL_THROW_EXTERN_C();
606 #define RTL_STR_MAX_VALUEOFCHAR 2
608 /** Create the string representation of an integer.
610 This function cannot be used for language-specific operations.
613 a buffer that is big enough to hold the result and the terminating NUL
614 character. You should use the RTL_STR_MAX_VALUEOFINT32 define to create a
615 buffer that is big enough.
621 the radix. Must be between RTL_STR_MIN_RADIX (2) and RTL_STR_MAX_RADIX
625 the length of the string.
627 SAL_DLLPUBLIC sal_Int32 SAL_CALL
rtl_str_valueOfInt32(
628 char * str
, sal_Int32 i
, sal_Int16 radix
) SAL_THROW_EXTERN_C();
629 #define RTL_STR_MIN_RADIX 2
630 #define RTL_STR_MAX_RADIX 36
631 #define RTL_STR_MAX_VALUEOFINT32 33
633 /** Create the string representation of a long integer.
635 This function cannot be used for language-specific operations.
638 a buffer that is big enough to hold the result and the terminating NUL
639 character. You should use the RTL_STR_MAX_VALUEOFINT64 define to create a
640 buffer that is big enough.
643 a long integer value.
646 the radix. Must be between RTL_STR_MIN_RADIX (2) and RTL_STR_MAX_RADIX
650 the length of the string.
652 SAL_DLLPUBLIC sal_Int32 SAL_CALL
rtl_str_valueOfInt64(
653 char * str
, sal_Int64 l
, sal_Int16 radix
) SAL_THROW_EXTERN_C();
654 #define RTL_STR_MAX_VALUEOFINT64 65
656 /** Create the string representation of an unsigned long integer.
658 This function cannot be used for language-specific operations.
661 a buffer that is big enough to hold the result and the terminating NUL
662 character. You should use the RTL_STR_MAX_VALUEOFUINT64 define to create a
663 buffer that is big enough.
666 a long integer value.
669 the radix. Must be between RTL_STR_MIN_RADIX (2) and RTL_STR_MAX_RADIX
673 the length of the string.
675 SAL_DLLPUBLIC sal_Int32 SAL_CALL
rtl_str_valueOfUInt64(
676 char * str
, sal_uInt64 l
, sal_Int16 radix
) SAL_THROW_EXTERN_C();
677 #define RTL_STR_MAX_VALUEOFUINT64 65
679 /** Create the string representation of a float.
681 This function cannot be used for language-specific conversion.
684 a buffer that is big enough to hold the result and the terminating NUL
685 character. You should use the RTL_STR_MAX_VALUEOFFLOAT define to create a
686 buffer that is big enough.
692 the length of the string.
694 SAL_DLLPUBLIC sal_Int32 SAL_CALL
rtl_str_valueOfFloat(
695 char * str
, float f
) SAL_THROW_EXTERN_C();
696 #define RTL_STR_MAX_VALUEOFFLOAT 15
698 /** Create the string representation of a double.
700 This function cannot be used for language-specific conversion.
703 a buffer that is big enough to hold the result and the terminating NUL
704 character. You should use the RTL_STR_MAX_VALUEOFDOUBLE define to create
705 a buffer that is big enough.
711 the length of the string.
713 SAL_DLLPUBLIC sal_Int32 SAL_CALL
rtl_str_valueOfDouble(
714 char * str
, double d
) SAL_THROW_EXTERN_C();
715 #define RTL_STR_MAX_VALUEOFDOUBLE 25
717 /** Interpret a string as a boolean.
719 This function cannot be used for language-specific conversion. The string
720 must be null-terminated.
723 a null-terminated string.
726 true if the string is "1" or "true" in any ASCII case, false otherwise.
728 SAL_DLLPUBLIC sal_Bool SAL_CALL
rtl_str_toBoolean(
729 const char * str
) SAL_THROW_EXTERN_C();
731 /** Interpret a string as an integer.
733 This function cannot be used for language-specific conversion. The string
734 must be null-terminated.
737 a null-terminated string.
740 the radix. Must be between RTL_STR_MIN_RADIX (2) and RTL_STR_MAX_RADIX
744 the integer value represented by the string, or 0 if the string does not
745 represent an integer.
747 SAL_DLLPUBLIC sal_Int32 SAL_CALL
rtl_str_toInt32(
748 const char * str
, sal_Int16 radix
) SAL_THROW_EXTERN_C();
750 /** Interpret a string as an unsigned integer.
752 This function cannot be used for language-specific conversion. The string
753 must be null-terminated.
756 a null-terminated string.
759 the radix. Must be between RTL_USTR_MIN_RADIX (2) and RTL_USTR_MAX_RADIX
763 the unsigned integer value represented by the string, or 0 if the string
764 does not represent an unsigned integer.
766 @since LibreOffice 4.2
768 SAL_DLLPUBLIC sal_uInt32 SAL_CALL
rtl_str_toUInt32(
769 const char * str
, sal_Int16 radix
) SAL_THROW_EXTERN_C();
771 /** Interpret a string as a long integer.
773 This function cannot be used for language-specific conversion. The string
774 must be null-terminated.
777 a null-terminated string.
780 the radix. Must be between RTL_STR_MIN_RADIX (2) and RTL_STR_MAX_RADIX
784 the long integer value represented by the string, or 0 if the string does
785 not represent a long integer.
787 SAL_DLLPUBLIC sal_Int64 SAL_CALL
rtl_str_toInt64(
788 const char * str
, sal_Int16 radix
) SAL_THROW_EXTERN_C();
790 /** Interpret a string as a long integer.
792 This function cannot be used for language-specific conversion.
798 the radix. Must be between RTL_STR_MIN_RADIX (2) and RTL_STR_MAX_RADIX
802 number of chars to process
805 the long integer value represented by the string, or 0 if the string does
806 not represent a long integer.
809 @since LibreOffice 6.4
811 SAL_DLLPUBLIC sal_Int64 SAL_CALL
rtl_str_toInt64_WithLength(
812 const char * str
, sal_Int16 radix
, sal_Int32 nStrLength
) SAL_THROW_EXTERN_C();
814 /** Interpret a string as an unsigned long integer.
816 This function cannot be used for language-specific conversion. The string
817 must be null-terminated.
820 a null-terminated string.
823 the radix. Must be between RTL_USTR_MIN_RADIX (2) and RTL_USTR_MAX_RADIX
827 the unsigned long integer value represented by the string, or 0 if the
828 string does not represent an unsigned long integer.
830 @since LibreOffice 4.1
832 SAL_DLLPUBLIC sal_uInt64 SAL_CALL
rtl_str_toUInt64(
833 const char * str
, sal_Int16 radix
) SAL_THROW_EXTERN_C();
835 /** Interpret a string as a float.
837 This function cannot be used for language-specific conversion. The string
838 must be null-terminated.
841 a null-terminated string.
844 the float value represented by the string, or 0.0 if the string does not
847 SAL_DLLPUBLIC
float SAL_CALL
rtl_str_toFloat(
848 const char * str
) SAL_THROW_EXTERN_C();
850 /** Interpret a string as a double.
852 This function cannot be used for language-specific conversion. The string
853 must be null-terminated.
856 a null-terminated string.
859 the float value represented by the string, or 0.0 if the string does not
862 SAL_DLLPUBLIC
double SAL_CALL
rtl_str_toDouble(
863 const char * str
) SAL_THROW_EXTERN_C();
865 /* ======================================================================= */
868 # pragma pack(push, 8)
871 /** @cond INTERNAL */
872 /** The implementation of a byte string.
874 typedef struct _rtl_String
876 oslInterlockedCount refCount
; /* opaque */
886 /* ----------------------------------------------------------------------- */
888 /** Increment the reference count of a string.
893 SAL_DLLPUBLIC
void SAL_CALL
rtl_string_acquire( rtl_String
* str
) SAL_THROW_EXTERN_C();
895 /** Decrement the reference count of a string.
897 If the count goes to zero than the string data is deleted.
902 SAL_DLLPUBLIC
void SAL_CALL
rtl_string_release( rtl_String
* str
) SAL_THROW_EXTERN_C();
904 /** Allocate a new string containing no characters.
907 pointer to the new string. The pointed-to data must be null or a valid
910 SAL_DLLPUBLIC
void SAL_CALL
rtl_string_new( rtl_String
** newStr
) SAL_THROW_EXTERN_C();
912 /** Allocate a new string containing space for a given number of characters.
914 The reference count of the new string will be 1. The length of the string
915 will be nLen. This function does not handle out-of-memory conditions.
917 For failed allocation this method returns NULL.
919 The characters of the capacity are not cleared, and the length is set to
920 nLen, unlike the similar method of rtl_String_new_WithLength which
921 zeros out the buffer, and sets the length to 0. So should be somewhat
922 more efficient for allocating a new string.
924 call rtl_String_release to release the string
925 alternatively pass ownership to an OUString with
926 rtl::OUString(newStr, SAL_NO_ACQUIRE);
928 @param[out] nLen the number of characters. Must be >= 0.
930 @return pointer to the new string.
932 @since LibreOffice 4.1
934 SAL_DLLPUBLIC rtl_String
* SAL_CALL
rtl_string_alloc(sal_Int32 nLen
) SAL_THROW_EXTERN_C();
936 /** Allocate a new string containing space for a given number of characters.
938 If len is greater than zero, the reference count of the new string will be
939 1. The values of all characters are set to 0 and the length of the string
940 is 0. This function does not handle out-of-memory conditions.
943 pointer to the new string. The pointed-to data must be null or a valid
947 the number of characters.
949 SAL_DLLPUBLIC
void SAL_CALL
rtl_string_new_WithLength( rtl_String
** newStr
, sal_Int32 len
) SAL_THROW_EXTERN_C();
951 /** Allocate a new string that contains a copy of another string.
953 If the length of value is greater than zero, the reference count of the
954 new string will be 1. This function does not handle out-of-memory
958 pointer to the new string. The pointed-to data must be null or a valid
964 SAL_DLLPUBLIC
void SAL_CALL
rtl_string_newFromString( rtl_String
** newStr
, const rtl_String
* value
) SAL_THROW_EXTERN_C();
966 /** Allocate a new string that contains a copy of a character array.
968 If the length of value is greater than zero, the reference count of the
969 new string will be 1. This function does not handle out-of-memory
973 pointer to the new string. The pointed-to data must be null or a valid
977 a null-terminated character array.
979 SAL_DLLPUBLIC
void SAL_CALL
rtl_string_newFromStr( rtl_String
** newStr
, const char * value
) SAL_THROW_EXTERN_C();
981 /** Allocate a new string that contains a copy of a character array.
983 If the length of value is greater than zero, the reference count of the
984 new string will be 1. This function does not handle out-of-memory
988 pointer to the new string. The pointed-to data must be null or a valid
992 a character array. Need not be null-terminated, but must be at least as
993 long as the specified len.
996 the length of the character array.
998 SAL_DLLPUBLIC
void SAL_CALL
rtl_string_newFromStr_WithLength( rtl_String
** newStr
, const char * value
, sal_Int32 len
) SAL_THROW_EXTERN_C();
1000 /** Allocate a new string that is a substring of this string.
1002 The substring begins at the specified beginIndex and contains count
1003 characters. Meaningless combinations such as negative beginIndex,
1004 or beginIndex + count greater than the length of the string have
1005 undefined behaviour.
1007 @param[out] newStr the specified substring.
1008 @param[in] from the String to take the substring from.
1009 @param[in] beginIndex the beginning index, inclusive.
1010 @param[in] count the number of characters.
1012 @since LibreOffice 4.0
1014 SAL_DLLPUBLIC
void SAL_CALL
rtl_string_newFromSubString(
1015 rtl_String
** newStr
, const rtl_String
* from
,
1016 sal_Int32 beginIndex
, sal_Int32 count
) SAL_THROW_EXTERN_C();
1020 @since LibreOffice 3.6
1022 SAL_DLLPUBLIC
void SAL_CALL
rtl_string_newFromLiteral( rtl_String
** newStr
, const char * value
, sal_Int32 len
, sal_Int32 allocExtra
) SAL_THROW_EXTERN_C();
1024 /** Assign a new value to a string.
1026 First releases any value str might currently hold, then acquires
1030 pointer to the string. The pointed-to data must be null or a valid
1036 SAL_DLLPUBLIC
void SAL_CALL
rtl_string_assign( rtl_String
** str
, rtl_String
* rightValue
) SAL_THROW_EXTERN_C();
1038 /** Return the length of a string.
1040 The length is equal to the number of characters in the string.
1046 the length of the string.
1048 SAL_DLLPUBLIC sal_Int32 SAL_CALL
rtl_string_getLength( const rtl_String
* str
) SAL_THROW_EXTERN_C();
1050 /** Return a pointer to the underlying character array of a string.
1056 a pointer to the null-terminated character array.
1058 SAL_DLLPUBLIC
char * SAL_CALL
rtl_string_getStr( rtl_String
* str
) SAL_THROW_EXTERN_C();
1060 /** Create a new string that is the concatenation of two other strings.
1062 The new string does not necessarily have a reference count of 1 (in cases
1063 where one of the two other strings is empty), so it must not be modified
1064 without checking the reference count. This function does not handle
1065 out-of-memory conditions.
1068 pointer to the new string. The pointed-to data must be null or a valid
1077 SAL_DLLPUBLIC
void SAL_CALL
rtl_string_newConcat( rtl_String
** newStr
, rtl_String
* left
, rtl_String
* right
) SAL_THROW_EXTERN_C();
1079 /** Create a new string by replacing a substring of another string.
1081 The new string results from replacing a number of characters (count),
1082 starting at the specified position (index) in the original string (str),
1083 with some new substring (subStr). If subStr is null, then only a number
1084 of characters is deleted.
1086 The new string does not necessarily have a reference count of 1, so it
1087 must not be modified without checking the reference count. This function
1088 does not handle out-of-memory conditions.
1091 pointer to the new string. The pointed-to data must be null or a valid
1098 the index into str at which to start replacement. Must be between 0 and
1099 the length of str, inclusive.
1102 the number of characters to remove. Must not be negative, and the sum of
1103 index and count must not exceed the length of str.
1106 either null or a valid string to be inserted.
1108 SAL_DLLPUBLIC
void SAL_CALL
rtl_string_newReplaceStrAt(
1109 rtl_String
** newStr
, rtl_String
* str
, sal_Int32 idx
, sal_Int32 count
, rtl_String
* subStr
) SAL_THROW_EXTERN_C();
1111 #ifdef LIBO_INTERNAL_ONLY
1112 SAL_DLLPUBLIC
void SAL_CALL
rtl_string_newReplaceStrAt_WithLength (
1113 rtl_String
** newStr
, rtl_String
* str
, sal_Int32 idx
, sal_Int32 count
, char const * subStr
, sal_Int32 substrLen
) SAL_THROW_EXTERN_C();
1116 /** Create a new string by replacing all occurrences of a single character
1117 within another string.
1119 The new string results from replacing all occurrences of oldChar in str
1122 The new string does not necessarily have a reference count of 1 (in cases
1123 where oldChar does not occur in str), so it must not be modified without
1124 checking the reference count. This function does not handle out-of-memory
1128 pointer to the new string. The pointed-to data must be null or a valid
1140 SAL_DLLPUBLIC
void SAL_CALL
rtl_string_newReplace(
1141 rtl_String
** newStr
, rtl_String
* str
, char oldChar
, char newChar
) SAL_THROW_EXTERN_C();
1143 /** Create a new string by replacing the first occurrence of a given substring
1144 with another substring.
1146 @param[in, out] newStr pointer to the new string; must not be null; must
1147 point to null or a valid rtl_String
1149 @param str pointer to the original string; must not be null
1151 @param from pointer to the substring to be replaced; must not be null and
1152 must point to memory of at least \p fromLength bytes
1154 @param fromLength the length of the \p from substring; must be non-negative
1156 @param to pointer to the replacing substring; must not be null and must
1157 point to memory of at least \p toLength bytes
1159 @param toLength the length of the \p to substring; must be non-negative
1161 @param[in,out] index pointer to a start index, must not be null; upon entry
1162 to the function its value is the index into the original string at which to
1163 start searching for the \p from substring, the value must be non-negative
1164 and not greater than the original string's length; upon exit from the
1165 function its value is the index into the original string at which the
1166 replacement took place or -1 if no replacement took place
1168 @since LibreOffice 3.6
1170 SAL_DLLPUBLIC
void SAL_CALL
rtl_string_newReplaceFirst(
1171 rtl_String
** newStr
, rtl_String
* str
, char const * from
,
1172 sal_Int32 fromLength
, char const * to
, sal_Int32 toLength
,
1173 sal_Int32
* index
) SAL_THROW_EXTERN_C();
1175 /** Create a new string by replacing all occurrences of a given substring with
1178 Replacing subsequent occurrences picks up only after a given replacement.
1179 That is, replacing from "xa" to "xx" in "xaa" results in "xxa", not "xxx".
1181 @param[in, out] newStr pointer to the new string; must not be null; must
1182 point to null or a valid rtl_String
1184 @param str pointer to the original string; must not be null
1186 @param from pointer to the substring to be replaced; must not be null and
1187 must point to memory of at least \p fromLength bytes
1189 @param fromLength the length of the \p from substring; must be non-negative
1191 @param to pointer to the replacing substring; must not be null and must
1192 point to memory of at least \p toLength bytes
1194 @param toLength the length of the \p to substring; must be non-negative
1196 @since LibreOffice 3.6
1198 SAL_DLLPUBLIC
void SAL_CALL
rtl_string_newReplaceAll(
1199 rtl_String
** newStr
, rtl_String
* str
, char const * from
,
1200 sal_Int32 fromLength
, char const * to
, sal_Int32 toLength
)
1201 SAL_THROW_EXTERN_C();
1203 /** Create a new string by converting all ASCII uppercase letters to lowercase
1204 within another string.
1206 The new string results from replacing all characters with values between
1207 65 and 90 (ASCII A--Z) by values between 97 and 122 (ASCII a--z).
1209 This function cannot be used for language-specific conversion. The new
1210 string does not necessarily have a reference count of 1 (in cases where
1211 no characters need to be converted), so it must not be modified without
1212 checking the reference count. This function does not handle out-of-memory
1216 pointer to the new string. The pointed-to data must be null or a valid
1222 SAL_DLLPUBLIC
void SAL_CALL
rtl_string_newToAsciiLowerCase(
1223 rtl_String
** newStr
, rtl_String
* str
) SAL_THROW_EXTERN_C();
1225 /** Create a new string by converting all ASCII lowercase letters to uppercase
1226 within another string.
1228 The new string results from replacing all characters with values between
1229 97 and 122 (ASCII a--z) by values between 65 and 90 (ASCII A--Z).
1231 This function cannot be used for language-specific conversion. The new
1232 string does not necessarily have a reference count of 1 (in cases where
1233 no characters need to be converted), so it must not be modified without
1234 checking the reference count. This function does not handle out-of-memory
1238 pointer to the new string. The pointed-to data must be null or a valid
1244 SAL_DLLPUBLIC
void SAL_CALL
rtl_string_newToAsciiUpperCase(
1245 rtl_String
** newStr
, rtl_String
* str
) SAL_THROW_EXTERN_C();
1247 /** Create a new string by removing white space from both ends of another
1250 The new string results from removing all characters with values less than
1251 or equal to 32 (the space character) form both ends of str.
1253 This function cannot be used for language-specific conversion. The new
1254 string does not necessarily have a reference count of 1 (in cases where
1255 no characters need to be removed), so it must not be modified without
1256 checking the reference count. This function does not handle out-of-memory
1260 pointer to the new string. The pointed-to data must be null or a valid
1266 SAL_DLLPUBLIC
void SAL_CALL
rtl_string_newTrim(
1267 rtl_String
** newStr
, rtl_String
* str
) SAL_THROW_EXTERN_C();
1269 /** Create a new string by extracting a single token from another string.
1271 Starting at index, the next token is searched for. If there is no
1272 such token, the result is an empty string. Otherwise, all characters from
1273 the start of that token and up to, but not including the next occurrence
1274 of cTok make up the resulting token. The return value is the position of
1275 the next token, or -1 if no more tokens follow.
1277 Example code could look like
1278 rtl_String * pToken = NULL;
1279 sal_Int32 nIndex = 0;
1283 nIndex = rtl_string_getToken(&pToken, pStr, 0, ';', nIndex);
1286 while (nIndex >= 0);
1288 The new string does not necessarily have a reference count of 1, so it
1289 must not be modified without checking the reference count. This function
1290 does not handle out-of-memory conditions.
1293 pointer to the new string. The pointed-to data must be null or a valid
1294 string. If either token or index is negative, an empty token is stored in
1295 newStr (and -1 is returned).
1301 the number of the token to return, starting at index.
1304 the character that separates the tokens.
1307 the position at which searching for the token starts. Must not be greater
1308 than the length of str.
1311 the index of the next token, or -1 if no more tokens follow.
1313 SAL_DLLPUBLIC sal_Int32 SAL_CALL
rtl_string_getToken(
1314 rtl_String
** newStr
, rtl_String
* str
, sal_Int32 token
, char cTok
, sal_Int32 idx
) SAL_THROW_EXTERN_C();
1316 /* ======================================================================= */
1318 /** Supply an ASCII string literal together with its length.
1320 This macro can be used to compute (some of) the arguments in function calls
1321 like rtl::OString(RTL_CONSTASCII_STRINGPARAM("foo")) or
1322 rtl::OUString::equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("foo")).
1324 @param constAsciiStr
1325 must be an expression of type "(possibly cv-qualified reference to) array of
1326 (possibly cv-qualified) char." Each element of the referenced array must
1327 represent an ASCII value in the range 0x00--0x7F. The last element of the
1328 referenced array is not considered part of the represented ASCII string, and
1329 its value should be 0x00. Depending on where this macro is used, the nature
1330 of the supplied expression might be further restricted.
1332 // The &foo[0] trick is intentional, it makes sure the type is char* or const char*
1333 // (plain cast to const char* would not work with non-const char foo[]="a", which seems to be allowed).
1334 // This is to avoid mistaken use with functions that accept string literals
1335 // (i.e. const char (&)[N]) where usage of this macro otherwise could match
1336 // the argument and a following int argument with a default value (e.g. OString::match()).
1337 #define RTL_CONSTASCII_STRINGPARAM( constAsciiStr ) (&(constAsciiStr)[0]), \
1338 ((sal_Int32)SAL_N_ELEMENTS(constAsciiStr)-1)
1340 /** Supply the length of an ASCII string literal.
1342 This macro can be used to compute arguments in function calls like
1343 rtl::OUString::match(other, RTL_CONSTASCII_LENGTH("prefix")).
1345 @param constAsciiStr
1346 must be an expression of type "(possibly cv-qualified reference to) array of
1347 (possibly cv-qualified) char." Each element of the referenced array must
1348 represent an ASCII value in the range 0x00--0x7F. The last element of the
1349 referenced array is not considered part of the represented ASCII string, and
1350 its value should be 0x00. Depending on where this macro is used, the nature
1351 of the supplied expression might be further restricted.
1353 #define RTL_CONSTASCII_LENGTH( constAsciiStr ) ((sal_Int32)(SAL_N_ELEMENTS(constAsciiStr)-1))
1355 /* ======================================================================= */
1357 /* predefined constants for String-Conversion */
1358 #define OUSTRING_TO_OSTRING_CVTFLAGS (RTL_UNICODETOTEXT_FLAGS_UNDEFINED_DEFAULT |\
1359 RTL_UNICODETOTEXT_FLAGS_INVALID_DEFAULT |\
1360 RTL_UNICODETOTEXT_FLAGS_UNDEFINED_REPLACE |\
1361 RTL_UNICODETOTEXT_FLAGS_PRIVATE_MAPTO0)
1363 /* ----------------------------------------------------------------------- */
1365 /** Create a new byte string by converting a Unicode string, using a specific
1368 The lengths of the byte string and the Unicode string may differ (e.g.,
1369 for double-byte encodings, UTF-7, UTF-8).
1371 If the length of the Unicode string is greater than zero, the reference
1372 count of the new string will be 1.
1374 If an out-of-memory condition occurs, newStr will point to a null pointer
1378 pointer to the new string. The pointed-to data must be null or a valid
1382 a Unicode character array. Need not be null-terminated, but must be at
1383 least as long as the specified len.
1386 the length of the Unicode character array.
1389 the text encoding to use for conversion.
1392 flags which control the conversion. Either use
1393 OUSTRING_TO_OSTRING_CVTFLAGS, or see
1394 <http://udk.openoffice.org/cpp/man/spec/textconversion.html> for more
1397 SAL_DLLPUBLIC
void SAL_CALL
rtl_uString2String(
1398 rtl_String
** newStr
, const sal_Unicode
* str
, sal_Int32 len
, rtl_TextEncoding encoding
, sal_uInt32 convertFlags
) SAL_THROW_EXTERN_C();
1401 Converts a Unicode string to a byte string, signalling failure.
1404 An out parameter receiving the converted string. Must not be null itself, and
1405 must contain either null or a pointer to a valid rtl_String; the contents are
1406 not modified if conversion fails (rtl_convertUStringToString returns false).
1409 The Unicode string. May only be null if nLength is zero.
1412 The length of the Unicode string. Must be non-negative.
1415 The text encoding to convert into. Must be an octet encoding (i.e.,
1416 rtl_isOctetTextEncoding(nEncoding) must return true).
1419 A combination of RTL_UNICODETOTEXT_FLAGS that detail how to do the conversion
1420 (see rtl_convertUnicodeToText). RTL_UNICODETOTEXT_FLAGS_FLUSH need not be
1421 included, it is implicitly assumed. Typical uses are either
1422 RTL_UNICODETOTEXT_FLAGS_UNDEFINED_ERROR |
1423 RTL_UNICODETOTEXT_FLAGS_INVALID_ERROR (fail if a Unicode character cannot be
1424 converted to the target nEncoding) or OUSTRING_TO_OSTRING_CVTFLAGS (make a
1425 best efforts conversion).
1428 True if the conversion succeeded, false otherwise.
1430 SAL_DLLPUBLIC sal_Bool SAL_CALL
rtl_convertUStringToString(
1431 rtl_String
** pTarget
,
1432 sal_Unicode
const * pSource
,
1434 rtl_TextEncoding nEncoding
,
1436 SAL_THROW_EXTERN_C();
1438 /** Ensure a string has enough space for a given number of characters.
1440 If the given string is large enough and has refcount of 1, it is not altered in any way.
1441 Otherwise it is replaced by a copy that has enough space for the given number of characters,
1442 data from the source string is copied to the beginning of it, the content of the remaining
1443 capacity undefined, the string has refcount of 1, and refcount of the original string is decreased.
1446 pointer to the string. The pointed-to data must be a valid string.
1449 the number of characters
1451 @since LibreOffice 4.1
1454 SAL_DLLPUBLIC
void SAL_CALL
rtl_string_ensureCapacity( rtl_String
** str
, sal_Int32 size
) SAL_THROW_EXTERN_C();
1460 #endif // INCLUDED_RTL_STRING_H
1462 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */