update dev300-m58
[ooovba.git] / sal / inc / rtl / string.h
blob34a0fcf480ccbe9508110a38d31b6cd88a9eade3
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: string.h,v $
10 * $Revision: 1.17 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #ifndef _RTL_STRING_H_
32 #define _RTL_STRING_H_
34 #include <sal/types.h>
35 #include <osl/interlck.h>
36 #include <rtl/textcvt.h>
38 #ifdef __cplusplus
39 extern "C" {
40 #endif
42 /* ======================================================================= */
44 /** Return the length of a string.
46 The length is equal to the number of 8-bit characters in the string,
47 without the terminating NUL character.
49 @param str
50 a null-terminated string.
52 @return
53 the length of the sequence of characters represented by this string,
54 excluding the terminating NUL character.
56 sal_Int32 SAL_CALL rtl_str_getLength( const sal_Char * str ) SAL_THROW_EXTERN_C();
58 /** Compare two strings.
60 The comparison is based on the numeric value of each character in the
61 strings and returns a value indicating their relationship. This function
62 cannot be used for language-specific sorting. Both strings must be
63 null-terminated.
65 @param first
66 the first null-terminated string to be compared.
68 @param second
69 the second null-terminated string which is compared with the first one.
71 @return
72 0 if both strings are equal, a value less than 0 if the first string is
73 less than the second string, and a value greater than 0 if the first
74 string is greater than the second string.
76 sal_Int32 SAL_CALL rtl_str_compare( const sal_Char * first, const sal_Char * second ) SAL_THROW_EXTERN_C();
78 /** Compare two strings.
80 The comparison is based on the numeric value of each character in the
81 strings and returns a value indicating their relationship. This function
82 cannot be used for language-specific sorting.
84 @param first
85 the first string to be compared. Need not be null-terminated, but must be
86 at least as long as the specified firstLen.
88 @param firstLen
89 the length of the first string.
91 @param second
92 the second string which is compared with the first one. Need not be
93 null-terminated, but must be at least as long as the specified secondLen.
95 @param secondLen
96 the length of the second string.
98 @return
99 0 if both strings are equal, a value less than 0 if the first string is
100 less than the second string, and a value greater than 0 if the first
101 string is greater than the second string.
103 sal_Int32 SAL_CALL rtl_str_compare_WithLength( const sal_Char * first, sal_Int32 firstLen, const sal_Char * second, sal_Int32 secondLen ) SAL_THROW_EXTERN_C();
105 /** Compare two strings with a maximum count of characters.
107 The comparison is based on the numeric value of each character in the
108 strings and returns a value indicating their relationship. This function
109 cannot be used for language-specific sorting.
111 @param first
112 the first string to be compared. Need not be null-terminated, but must be
113 at least as long as the specified firstLen.
115 @param firstLen
116 the length of the first string.
118 @param second
119 the second string which is compared with the first one. Need not be
120 null-terminated, but must be at least as long as the specified secondLen.
122 @param secondLen
123 the length of the second string.
125 @param shortenedLen
126 the maximum number of characters to compare. This length can be greater
127 or smaller than the lengths of the two strings.
129 @return
130 0 if both substrings are equal, a value less than 0 if the first substring
131 is less than the second substring, and a value greater than 0 if the first
132 substring is greater than the second substring.
134 sal_Int32 SAL_CALL rtl_str_shortenedCompare_WithLength( const sal_Char * first, sal_Int32 firstLen, const sal_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.
142 @param first
143 the first string to be compared. Need not be null-terminated, but must be
144 at least as long as the specified firstLen.
146 @param firstLen
147 the length of the first string.
149 @param second
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.
153 @param secondLen
154 the length of the second string.
156 @return
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_Int32 SAL_CALL rtl_str_reverseCompare_WithLength( const sal_Char * first, sal_Int32 firstLen, const sal_Char * second, sal_Int32 secondLen ) SAL_THROW_EXTERN_C();
163 /** Compare two strings, ignoring the case of ASCII characters.
165 The comparison is based on the numeric value of each character in the
166 strings and returns a value indicating their relationship. Character
167 values between 65 and 90 (ASCII A--Z) are interpreted as values between 97
168 and 122 (ASCII a--z). This function cannot be used for language-specific
169 sorting. Both strings must be null-terminated.
171 @param first
172 the first null-terminated string to be compared.
174 @param second
175 the second null-terminated string which is compared with the first one.
177 @return
178 0 if both strings are equal, a value less than 0 if the first string is
179 less than the second string, and a value greater than 0 if the first
180 string is greater than the second string.
182 sal_Int32 SAL_CALL rtl_str_compareIgnoreAsciiCase( const sal_Char * first, const sal_Char * second ) SAL_THROW_EXTERN_C();
184 /** Compare two strings, ignoring the case of ASCII characters.
186 The comparison is based on the numeric value of each character in the
187 strings and returns a value indicating their relationship. Character
188 values between 65 and 90 (ASCII A--Z) are interpreted as values between 97
189 and 122 (ASCII a--z). This function cannot be used for language-specific
190 sorting.
192 @param first
193 the first string to be compared. Need not be null-terminated, but must be
194 at least as long as the specified firstLen.
196 @param firstLen
197 the length of the first string.
199 @param second
200 the second string which is compared with the first one. Need not be
201 null-terminated, but must be at least as long as the specified secondLen.
203 @param secondLen
204 the length of the second string.
206 @return
207 0 if both strings are equal, a value less than 0 if the first string is
208 less than the second string, and a value greater than 0 if the first
209 string is greater than the second string.
211 sal_Int32 SAL_CALL rtl_str_compareIgnoreAsciiCase_WithLength( const sal_Char * first, sal_Int32 firstLen, const sal_Char * second, sal_Int32 secondLen ) SAL_THROW_EXTERN_C();
213 /** Compare two strings with a maximum count of characters, ignoring the case
214 of ASCII characters.
216 The comparison is based on the numeric value of each character in the
217 strings and returns a value indicating their relationship. Character
218 values between 65 and 90 (ASCII A--Z) are interpreted as values between 97
219 and 122 (ASCII a--z). This function cannot be used for language-specific
220 sorting.
222 @param first
223 the first string to be compared. Need not be null-terminated, but must be
224 at least as long as the specified firstLen.
226 @param firstLen
227 the length of the first string.
229 @param second
230 the second string which is compared with the first one. Need not be
231 null-terminated, but must be at least as long as the specified secondLen.
233 @param secondLen
234 the length of the second string.
236 @param shortenedLen
237 the maximum number of characters to compare. This length can be greater
238 or smaller than the lengths of the two strings.
240 @return
241 0 if both substrings are equal, a value less than 0 if the first substring
242 is less than the second substring, and a value greater than 0 if the first
243 substring is greater than the second substring.
245 sal_Int32 SAL_CALL rtl_str_shortenedCompareIgnoreAsciiCase_WithLength( const sal_Char * first, sal_Int32 firstLen, const sal_Char * second, sal_Int32 secondLen, sal_Int32 shortenedLen ) SAL_THROW_EXTERN_C();
247 /** Return a hash code for a string.
249 It is not allowed to store the hash code persistently, because later
250 versions could return other hash codes. The string must be
251 null-terminated.
253 @param str
254 a null-terminated string.
256 @return
257 a hash code for the given string.
259 sal_Int32 SAL_CALL rtl_str_hashCode( const sal_Char * str ) SAL_THROW_EXTERN_C();
261 /** Return a hash code for a string.
263 It is not allowed to store the hash code persistently, because later
264 versions could return other hash codes.
266 @param str
267 a string. Need not be null-terminated, but must be at least as long as
268 the specified len.
270 @param len
271 the length of the string.
273 @return
274 a hash code for the given string.
276 sal_Int32 SAL_CALL rtl_str_hashCode_WithLength( const sal_Char * str, sal_Int32 len ) SAL_THROW_EXTERN_C();
278 /** Search for the first occurrence of a character within a string.
280 The string must be null-terminated.
282 @param str
283 a null-terminated string.
285 @param ch
286 the character to be searched for.
288 @return
289 the index (starting at 0) of the first occurrence of the character in the
290 string, or -1 if the character does not occur.
292 sal_Int32 SAL_CALL rtl_str_indexOfChar( const sal_Char * str, sal_Char ch ) SAL_THROW_EXTERN_C();
294 /** Search for the first occurrence of a character within a string.
296 @param str
297 a string. Need not be null-terminated, but must be at least as long as
298 the specified len.
300 @param len
301 the length of the string.
303 @param ch
304 the character to be searched for.
306 @return
307 the index (starting at 0) of the first occurrence of the character in the
308 string, or -1 if the character does not occur.
310 sal_Int32 SAL_CALL rtl_str_indexOfChar_WithLength( const sal_Char * str, sal_Int32 len, sal_Char ch ) SAL_THROW_EXTERN_C();
312 /** Search for the last occurrence of a character within a string.
314 The string must be null-terminated.
316 @param str
317 a null-terminated string.
319 @param ch
320 the character to be searched for.
322 @return
323 the index (starting at 0) of the last occurrence of the character in the
324 string, or -1 if the character does not occur. The returned value is
325 always smaller than the string length.
327 sal_Int32 SAL_CALL rtl_str_lastIndexOfChar( const sal_Char * str, sal_Char ch ) SAL_THROW_EXTERN_C();
329 /** Search for the last occurrence of a character within a string.
331 @param str
332 a string. Need not be null-terminated, but must be at least as long as
333 the specified len.
335 @param len
336 the length of the string.
338 @param ch
339 the character to be searched for.
341 @return
342 the index (starting at 0) of the last occurrence of the character in the
343 string, or -1 if the character does not occur. The returned value is
344 always smaller than the string length.
346 sal_Int32 SAL_CALL rtl_str_lastIndexOfChar_WithLength( const sal_Char * str, sal_Int32 len, sal_Char ch ) SAL_THROW_EXTERN_C();
348 /** Search for the first occurrence of a substring within a string.
350 If subStr is empty, or both str and subStr are empty, -1 is returned.
351 Both strings must be null-terminated.
353 @param str
354 a null-terminated string.
356 @param subStr
357 the null-terminated substring to be searched for.
359 @return
360 the index (starting at 0) of the first character of the first occurrence
361 of the substring within the string, or -1 if the substring does not occur.
363 sal_Int32 SAL_CALL rtl_str_indexOfStr( const sal_Char * str, const sal_Char * subStr ) SAL_THROW_EXTERN_C();
365 /** Search for the first occurrence of a substring within a string.
367 If subStr is empty, or both str and subStr are empty, -1 is returned.
369 @param str
370 a string. Need not be null-terminated, but must be at least as long as
371 the specified len.
373 @param len
374 the length of the string.
376 @param subStr
377 the substring to be searched for. Need not be null-terminated, but must
378 be at least as long as the specified subLen.
380 @param subLen
381 the length of the substring.
383 @return
384 the index (starting at 0) of the first character of the first occurrence
385 of the substring within the string, or -1 if the substring does not occur.
387 sal_Int32 SAL_CALL rtl_str_indexOfStr_WithLength( const sal_Char * str, sal_Int32 len, const sal_Char * subStr, sal_Int32 subLen ) SAL_THROW_EXTERN_C();
389 /** Search for the last occurrence of a substring within a string.
391 If subStr is empty, or both str and subStr are empty, -1 is returned.
392 Both strings must be null-terminated.
394 @param str
395 a null-terminated string.
397 @param subStr
398 the null-terminated substring to be searched for.
400 @return
401 the index (starting at 0) of the first character of the last occurrence
402 of the substring within the string, or -1 if the substring does not occur.
404 sal_Int32 SAL_CALL rtl_str_lastIndexOfStr( const sal_Char * str, const sal_Char * subStr ) SAL_THROW_EXTERN_C();
406 /** Search for the last occurrence of a substring within a string.
408 If subStr is empty, or both str and subStr are empty, -1 is returned.
410 @param str
411 a string. Need not be null-terminated, but must be at least as long as
412 the specified len.
414 @param len
415 the length of the string.
417 @param subStr
418 the substring to be searched for. Need not be null-terminated, but must
419 be at least as long as the specified subLen.
421 @param subLen
422 the length of the substring.
424 @return
425 the index (starting at 0) of the first character of the first occurrence
426 of the substring within the string, or -1 if the substring does not occur.
428 sal_Int32 SAL_CALL rtl_str_lastIndexOfStr_WithLength( const sal_Char * str, sal_Int32 len, const sal_Char * subStr, sal_Int32 subLen ) SAL_THROW_EXTERN_C();
430 /** Replace all occurrences of a single character within a string.
432 If oldChar does not occur within str, then the string is not modified.
433 The string must be null-terminated.
435 @param str
436 a null-terminated string.
438 @param oldChar
439 the old character.
441 @param newChar
442 the new character.
444 void SAL_CALL rtl_str_replaceChar( sal_Char * str, sal_Char oldChar, sal_Char newChar ) SAL_THROW_EXTERN_C();
446 /** Replace all occurrences of a single character within a string.
448 If oldChar does not occur within str, then the string is not modified.
450 @param str
451 a string. Need not be null-terminated, but must be at least as long as
452 the specified len.
454 @param len
455 the length of the string.
457 @param oldChar
458 the old character.
460 @param newChar
461 the new character.
463 void SAL_CALL rtl_str_replaceChar_WithLength( sal_Char * str, sal_Int32 len, sal_Char oldChar, sal_Char newChar ) SAL_THROW_EXTERN_C();
465 /** Convert all ASCII uppercase letters to lowercase within a string.
467 The characters with values between 65 and 90 (ASCII A--Z) are replaced
468 with values between 97 and 122 (ASCII a--z). The string must be
469 null-terminated.
471 @param str
472 a null-terminated string.
474 void SAL_CALL rtl_str_toAsciiLowerCase( sal_Char * str ) SAL_THROW_EXTERN_C();
476 /** Convert all ASCII uppercase letters to lowercase within a string.
478 The characters with values between 65 and 90 (ASCII A--Z) are replaced
479 with values between 97 and 122 (ASCII a--z).
481 @param str
482 a string. Need not be null-terminated, but must be at least as long as
483 the specified len.
485 @param len
486 the length of the string.
488 void SAL_CALL rtl_str_toAsciiLowerCase_WithLength( sal_Char * str, sal_Int32 len ) SAL_THROW_EXTERN_C();
490 /** Convert all ASCII lowercase letters to uppercase within a string.
492 The characters with values between 97 and 122 (ASCII a--z) are replaced
493 with values between 65 and 90 (ASCII A--Z). The string must be
494 null-terminated.
496 @param str
497 a null-terminated string.
499 void SAL_CALL rtl_str_toAsciiUpperCase( sal_Char * str ) SAL_THROW_EXTERN_C();
501 /** Convert all ASCII lowercase letters to uppercase within a string.
503 The characters with values between 97 and 122 (ASCII a--z) are replaced
504 with values between 65 and 90 (ASCII A--Z).
506 @param str
507 a string. Need not be null-terminated, but must be at least as long as
508 the specified len.
510 @param len
511 the length of the string.
513 void SAL_CALL rtl_str_toAsciiUpperCase_WithLength( sal_Char * str, sal_Int32 len ) SAL_THROW_EXTERN_C();
515 /** Remove white space from both ends of a string.
517 All characters with values less than or equal to 32 (the space character)
518 are considered to be white space. This function cannot be used for
519 language-specific operations. The string must be null-terminated.
521 @param str
522 a null-terminated string.
524 @return
525 the new length of the string.
527 sal_Int32 SAL_CALL rtl_str_trim( sal_Char * str ) SAL_THROW_EXTERN_C();
529 /** Remove white space from both ends of the string.
531 All characters with values less than or equal to 32 (the space character)
532 are considered to be white space. This function cannot be used for
533 language-specific operations. The string must be null-terminated.
535 @param str
536 a string. Need not be null-terminated, but must be at least as long as
537 the specified len.
539 @param len
540 the original length of the string.
542 @return
543 the new length of the string.
545 sal_Int32 SAL_CALL rtl_str_trim_WithLength( sal_Char * str, sal_Int32 len ) SAL_THROW_EXTERN_C();
547 /** Create the string representation of a boolean.
549 If b is true, the buffer is filled with the string "true" and 5 is
550 returned. If b is false, the buffer is filled with the string "false" and
551 6 is returned. This function cannot be used for language-specific
552 operations.
554 @param str
555 a buffer that is big enough to hold the result and the terminating NUL
556 character. You should use the RTL_STR_MAX_VALUEOFBOOLEAN define to create
557 a buffer that is big enough.
559 @param b
560 a boolean value.
562 @return
563 the length of the string.
565 sal_Int32 SAL_CALL rtl_str_valueOfBoolean( sal_Char * str, sal_Bool b ) SAL_THROW_EXTERN_C();
566 #define RTL_STR_MAX_VALUEOFBOOLEAN 6
568 /** Create the string representation of a character.
570 @param str
571 a buffer that is big enough to hold the result and the terminating NUL
572 character. You should use the RTL_STR_MAX_VALUEOFCHAR define to create a
573 buffer that is big enough.
575 @param ch
576 a character value.
578 @return
579 the length of the string.
581 sal_Int32 SAL_CALL rtl_str_valueOfChar( sal_Char * str, sal_Char ch ) SAL_THROW_EXTERN_C();
582 #define RTL_STR_MAX_VALUEOFCHAR 2
584 /** Create the string representation of an integer.
586 This function cannot be used for language-specific operations.
588 @param str
589 a buffer that is big enough to hold the result and the terminating NUL
590 character. You should use the RTL_STR_MAX_VALUEOFINT32 define to create a
591 buffer that is big enough.
593 @param i
594 an integer value.
596 @param radix
597 the radix. Must be between RTL_STR_MIN_RADIX (2) and RTL_STR_MAX_RADIX
598 (36), inclusive.
600 @return
601 the length of the string.
603 sal_Int32 SAL_CALL rtl_str_valueOfInt32( sal_Char * str, sal_Int32 i, sal_Int16 radix ) SAL_THROW_EXTERN_C();
604 #define RTL_STR_MIN_RADIX 2
605 #define RTL_STR_MAX_RADIX 36
606 #define RTL_STR_MAX_VALUEOFINT32 33
608 /** Create the string representation of a long integer.
610 This function cannot be used for language-specific operations.
612 @param str
613 a buffer that is big enough to hold the result and the terminating NUL
614 character. You should use the RTL_STR_MAX_VALUEOFINT64 define to create a
615 buffer that is big enough.
617 @param l
618 a long integer value.
620 @param radix
621 the radix. Must be between RTL_STR_MIN_RADIX (2) and RTL_STR_MAX_RADIX
622 (36), inclusive.
624 @return
625 the length of the string.
627 sal_Int32 SAL_CALL rtl_str_valueOfInt64( sal_Char * str, sal_Int64 l, sal_Int16 radix ) SAL_THROW_EXTERN_C();
628 #define RTL_STR_MAX_VALUEOFINT64 65
630 /** Create the string representation of a float.
632 This function cannot be used for language-specific conversion.
634 @param str
635 a buffer that is big enough to hold the result and the terminating NUL
636 character. You should use the RTL_STR_MAX_VALUEOFFLOAT define to create a
637 buffer that is big enough.
639 @param f
640 a float value.
642 @return
643 the length of the string.
645 sal_Int32 SAL_CALL rtl_str_valueOfFloat( sal_Char * str, float f ) SAL_THROW_EXTERN_C();
646 #define RTL_STR_MAX_VALUEOFFLOAT 15
648 /** Create the string representation of a double.
650 This function cannot be used for language-specific conversion.
652 @param str
653 a buffer that is big enough to hold the result and the terminating NUL
654 character. You should use the RTL_STR_MAX_VALUEOFDOUBLE define to create
655 a buffer that is big enough.
657 @param d
658 a double value.
660 @return
661 the length of the string.
663 sal_Int32 SAL_CALL rtl_str_valueOfDouble( sal_Char * str, double d ) SAL_THROW_EXTERN_C();
664 #define RTL_STR_MAX_VALUEOFDOUBLE 25
666 /** Interpret a string as a boolean.
668 This function cannot be used for language-specific conversion. The string
669 must be null-terminated.
671 @param str
672 a null-terminated string.
674 @return
675 true if the string is "1" or "true" in any ASCII case, false otherwise.
677 sal_Bool SAL_CALL rtl_str_toBoolean( const sal_Char * str ) SAL_THROW_EXTERN_C();
679 /** Interpret a string as an integer.
681 This function cannot be used for language-specific conversion. The string
682 must be null-terminated.
684 @param str
685 a null-terminated string.
687 @param radix
688 the radix. Must be between RTL_STR_MIN_RADIX (2) and RTL_STR_MAX_RADIX
689 (36), inclusive.
691 @return
692 the integer value represented by the string, or 0 if the string does not
693 represent an integer.
695 sal_Int32 SAL_CALL rtl_str_toInt32( const sal_Char * str, sal_Int16 radix ) SAL_THROW_EXTERN_C();
697 /** Interpret a string as a long integer.
699 This function cannot be used for language-specific conversion. The string
700 must be null-terminated.
702 @param str
703 a null-terminated string.
705 @param radix
706 the radix. Must be between RTL_STR_MIN_RADIX (2) and RTL_STR_MAX_RADIX
707 (36), inclusive.
709 @return
710 the long integer value represented by the string, or 0 if the string does
711 not represent a long integer.
713 sal_Int64 SAL_CALL rtl_str_toInt64( const sal_Char * str, sal_Int16 radix ) SAL_THROW_EXTERN_C();
715 /** Interpret a string as a float.
717 This function cannot be used for language-specific conversion. The string
718 must be null-terminated.
720 @param str
721 a null-terminated string.
723 @return
724 the float value represented by the string, or 0.0 if the string does not
725 represent a float.
727 float SAL_CALL rtl_str_toFloat( const sal_Char * str ) SAL_THROW_EXTERN_C();
729 /** Interpret a string as a double.
731 This function cannot be used for language-specific conversion. The string
732 must be null-terminated.
734 @param str
735 a null-terminated string.
737 @return
738 the float value represented by the string, or 0.0 if the string does not
739 represent a double.
741 double SAL_CALL rtl_str_toDouble( const sal_Char * str ) SAL_THROW_EXTERN_C();
743 /* ======================================================================= */
745 #ifdef SAL_W32
746 # pragma pack(push, 8)
747 #elif defined(SAL_OS2)
748 # pragma pack(push, 4)
749 #endif
751 /** The implementation of a byte string.
753 @internal
755 typedef struct _rtl_String
757 oslInterlockedCount refCount; /* opaque */
758 sal_Int32 length;
759 sal_Char buffer[1];
760 } rtl_String;
762 #if defined( SAL_W32) || defined(SAL_OS2)
763 #pragma pack(pop)
764 #endif
766 /* ----------------------------------------------------------------------- */
768 /** Increment the reference count of a string.
770 @param str
771 a string.
773 void SAL_CALL rtl_string_acquire( rtl_String * str ) SAL_THROW_EXTERN_C();
775 /** Decrement the reference count of a string.
777 If the count goes to zero than the string data is deleted.
779 @param str
780 a string.
782 void SAL_CALL rtl_string_release( rtl_String * str ) SAL_THROW_EXTERN_C();
784 /** Allocate a new string containing no characters.
786 @param newStr
787 pointer to the new string. The pointed-to data must be null or a valid
788 string.
790 void SAL_CALL rtl_string_new( rtl_String ** newStr ) SAL_THROW_EXTERN_C();
792 /** Allocate a new string containing space for a given number of characters.
794 If len is greater than zero, the reference count of the new string will be
795 1. The values of all characters are set to 0 and the length of the string
796 is 0. This function does not handle out-of-memory conditions.
798 @param newStr
799 pointer to the new string. The pointed-to data must be null or a valid
800 string.
802 @param len
803 the number of characters.
805 void SAL_CALL rtl_string_new_WithLength( rtl_String ** newStr, sal_Int32 len ) SAL_THROW_EXTERN_C();
807 /** Allocate a new string that contains a copy of another string.
809 If the length of value is greater than zero, the reference count of the
810 new string will be 1. This function does not handle out-of-memory
811 conditions.
813 @param newStr
814 pointer to the new string. The pointed-to data must be null or a valid
815 string.
817 @param value
818 a valid string.
820 void SAL_CALL rtl_string_newFromString( rtl_String ** newStr, const rtl_String * value ) SAL_THROW_EXTERN_C();
822 /** Allocate a new string that contains a copy of a character array.
824 If the length of value is greater than zero, the reference count of the
825 new string will be 1. This function does not handle out-of-memory
826 conditions.
828 @param newStr
829 pointer to the new string. The pointed-to data must be null or a valid
830 string.
832 @param value
833 a null-terminated character array.
835 void SAL_CALL rtl_string_newFromStr( rtl_String ** newStr, const sal_Char * value ) SAL_THROW_EXTERN_C();
837 /** Allocate a new string that contains a copy of a character array.
839 If the length of value is greater than zero, the reference count of the
840 new string will be 1. This function does not handle out-of-memory
841 conditions.
843 @param newStr
844 pointer to the new string. The pointed-to data must be null or a valid
845 string.
847 @param value
848 a character array. Need not be null-terminated, but must be at least as
849 long as the specified len.
851 @param len
852 the length of the character array.
854 void SAL_CALL rtl_string_newFromStr_WithLength( rtl_String ** newStr, const sal_Char * value, sal_Int32 len ) SAL_THROW_EXTERN_C();
856 /** Assign a new value to a string.
858 First releases any value str might currently hold, then acquires
859 rightValue.
861 @param str
862 pointer to the string. The pointed-to data must be null or a valid
863 string.
865 @param rightValue
866 a valid string.
868 void SAL_CALL rtl_string_assign( rtl_String ** str, rtl_String * rightValue ) SAL_THROW_EXTERN_C();
870 /** Return the length of a string.
872 The length is equal to the number of characters in the string.
874 @param str
875 a valid string.
877 @return
878 the length of the string.
880 sal_Int32 SAL_CALL rtl_string_getLength( const rtl_String * str ) SAL_THROW_EXTERN_C();
882 /** Return a pointer to the underlying character array of a string.
884 @param str
885 a valid string.
887 @return
888 a pointer to the null-terminated character array.
890 sal_Char * SAL_CALL rtl_string_getStr( rtl_String * str ) SAL_THROW_EXTERN_C();
892 /** Create a new string that is the concatenation of two other strings.
894 The new string does not necessarily have a reference count of 1 (in cases
895 where one of the two other strings is empty), so it must not be modified
896 without checking the reference count. This function does not handle
897 out-of-memory conditions.
899 @param newStr
900 pointer to the new string. The pointed-to data must be null or a valid
901 string.
903 @param left
904 a valid string.
906 @param right
907 a valid string.
909 void SAL_CALL rtl_string_newConcat( rtl_String ** newStr, rtl_String * left, rtl_String * right ) SAL_THROW_EXTERN_C();
911 /** Create a new string by replacing a substring of another string.
913 The new string results from replacing a number of characters (count),
914 starting at the specified position (index) in the original string (str),
915 with some new substring (subStr). If subStr is null, than only a number
916 of characters is deleted.
918 The new string does not necessarily have a reference count of 1, so it
919 must not be modified without checking the reference count. This function
920 does not handle out-of-memory conditions.
922 @param newStr
923 pointer to the new string. The pointed-to data must be null or a valid
924 string.
926 @param str
927 a valid string.
929 @param index
930 the index into str at which to start replacement. Must be between 0 and
931 the length of str, inclusive.
933 @param count
934 the number of charcters to remove. Must not be negative, and the sum of
935 index and count must not exceed the length of str.
937 @param subStr
938 either null or a valid string to be inserted.
940 void SAL_CALL rtl_string_newReplaceStrAt( rtl_String ** newStr, rtl_String * str, sal_Int32 idx, sal_Int32 count, rtl_String * subStr ) SAL_THROW_EXTERN_C();
942 /** Create a new string by replacing all occurrences of a single character
943 within another string.
945 The new string results from replacing all occurrences of oldChar in str
946 with newChar.
948 The new string does not necessarily have a reference count of 1 (in cases
949 where oldChar does not occur in str), so it must not be modified without
950 checking the reference count. This function does not handle out-of-memory
951 conditions.
953 @param newStr
954 pointer to the new string. The pointed-to data must be null or a valid
955 string.
957 @param str
958 a valid string.
960 @param oldChar
961 the old character.
963 @param newChar
964 the new character.
966 void SAL_CALL rtl_string_newReplace( rtl_String ** newStr, rtl_String * str, sal_Char oldChar, sal_Char newChar ) SAL_THROW_EXTERN_C();
968 /** Create a new string by converting all ASCII uppercase letters to lowercase
969 within another string.
971 The new string results from replacing all characters with values between
972 65 and 90 (ASCII A--Z) by values between 97 and 122 (ASCII a--z).
974 This function cannot be used for language-specific conversion. The new
975 string does not necessarily have a reference count of 1 (in cases where
976 no characters need to be converted), so it must not be modified without
977 checking the reference count. This function does not handle out-of-memory
978 conditions.
980 @param newStr
981 pointer to the new string. The pointed-to data must be null or a valid
982 string.
984 @param str
985 a valid string.
987 void SAL_CALL rtl_string_newToAsciiLowerCase( rtl_String ** newStr, rtl_String * str ) SAL_THROW_EXTERN_C();
989 /** Create a new string by converting all ASCII lowercase letters to uppercase
990 within another string.
992 The new string results from replacing all characters with values between
993 97 and 122 (ASCII a--z) by values between 65 and 90 (ASCII A--Z).
995 This function cannot be used for language-specific conversion. The new
996 string does not necessarily have a reference count of 1 (in cases where
997 no characters need to be converted), so it must not be modified without
998 checking the reference count. This function does not handle out-of-memory
999 conditions.
1001 @param newStr
1002 pointer to the new string. The pointed-to data must be null or a valid
1003 string.
1005 @param str
1006 a valid string.
1008 void SAL_CALL rtl_string_newToAsciiUpperCase( rtl_String ** newStr, rtl_String * str ) SAL_THROW_EXTERN_C();
1010 /** Create a new string by removing white space from both ends of another
1011 string.
1013 The new string results from removing all characters with values less than
1014 or equal to 32 (the space character) form both ends of str.
1016 This function cannot be used for language-specific conversion. The new
1017 string does not necessarily have a reference count of 1 (in cases where
1018 no characters need to be removed), so it must not be modified without
1019 checking the reference count. This function does not handle out-of-memory
1020 conditions.
1022 @param newStr
1023 pointer to the new string. The pointed-to data must be null or a valid
1024 string.
1026 @param str
1027 a valid string.
1029 void SAL_CALL rtl_string_newTrim( rtl_String ** newStr, rtl_String * str ) SAL_THROW_EXTERN_C();
1031 /** Create a new string by extracting a single token from another string.
1033 Starting at index, the token's next token is searched for. If there is no
1034 such token, the result is an empty string. Otherwise, all characters from
1035 the start of that token and up to, but not including the next occurrence
1036 of cTok make up the resulting token. The return value is the position of
1037 the next token, or -1 if no more tokens follow.
1039 Example code could look like
1040 rtl_String * pToken = NULL;
1041 sal_Int32 nIndex = 0;
1045 nIndex = rtl_string_getToken(&pToken, pStr, 0, ';', nIndex);
1048 while (nIndex >= 0);
1050 The new string does not necessarily have a reference count of 1, so it
1051 must not be modified without checking the reference count. This function
1052 does not handle out-of-memory conditions.
1054 @param newStr
1055 pointer to the new string. The pointed-to data must be null or a valid
1056 string. If either token or index is negative, an empty token is stored in
1057 newStr (and -1 is returned).
1059 @param str
1060 a valid string.
1062 @param token
1063 the number of the token to return, starting at index.
1065 @param cTok
1066 the character that seperates the tokens.
1068 @param index
1069 the position at which searching for the token starts. Must not be greater
1070 than the length of str.
1072 @return
1073 the index of the next token, or -1 if no more tokens follow.
1075 sal_Int32 SAL_CALL rtl_string_getToken( rtl_String ** newStr , rtl_String * str, sal_Int32 token, sal_Char cTok, sal_Int32 idx ) SAL_THROW_EXTERN_C();
1077 /* ======================================================================= */
1079 /** Supply an ASCII string literal together with its length.
1081 This macro can be used to compute (some of) the arguments in function calls
1082 like rtl::OString(RTL_CONSTASCII_STRINGPARAM("foo")) or
1083 rtl::OUString::equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("foo")).
1085 @param constAsciiStr
1086 must be an expression of type "(possibly cv-qualified reference to) array of
1087 (possibly cv-qualified) char." Each element of the referenced array must
1088 represent an ASCII value in the range 0x00--0x7F. The last element of the
1089 referenced array is not considered part of the represented ASCII string, and
1090 its value should be 0x00. Depending on where this macro is used, the nature
1091 of the supplied expression might be further restricted.
1093 #define RTL_CONSTASCII_STRINGPARAM( constAsciiStr ) constAsciiStr, ((sal_Int32)sizeof(constAsciiStr)-1)
1095 /** Supply the length of an ASCII string literal.
1097 This macro can be used to compute arguments in function calls like
1098 rtl::OUString::match(other, RTL_CONSTASCII_LENGTH("prefix")).
1100 @param constAsciiStr
1101 must be an expression of type "(possibly cv-qualified reference to) array of
1102 (possibly cv-qualified) char." Each element of the referenced array must
1103 represent an ASCII value in the range 0x00--0x7F. The last element of the
1104 referenced array is not considered part of the represented ASCII string, and
1105 its value should be 0x00. Depending on where this macro is used, the nature
1106 of the supplied expression might be further restricted.
1108 #define RTL_CONSTASCII_LENGTH( constAsciiStr ) ((sal_Int32)(sizeof(constAsciiStr)-1))
1110 /* ======================================================================= */
1112 /* predefined constants for String-Conversion */
1113 #define OUSTRING_TO_OSTRING_CVTFLAGS (RTL_UNICODETOTEXT_FLAGS_UNDEFINED_DEFAULT |\
1114 RTL_UNICODETOTEXT_FLAGS_INVALID_DEFAULT |\
1115 RTL_UNICODETOTEXT_FLAGS_UNDEFINED_REPLACE |\
1116 RTL_UNICODETOTEXT_FLAGS_PRIVATE_MAPTO0 |\
1117 RTL_UNICODETOTEXT_FLAGS_NOCOMPOSITE)
1119 /* ----------------------------------------------------------------------- */
1121 /** Create a new byte string by converting a Unicode string, using a specific
1122 text encoding.
1124 The lengths of the byte string and the Unicode string may differ (e.g.,
1125 for double-byte encodings, UTF-7, UTF-8).
1127 If the length of the Unicode string is greater than zero, the reference
1128 count of the new string will be 1.
1130 If an out-of-memory condition occurs, newStr will point to a null pointer
1131 upon return.
1133 @param newStr
1134 pointer to the new string. The pointed-to data must be null or a valid
1135 string.
1137 @param str
1138 a Unicode character array. Need not be null-terminated, but must be at
1139 least as long as the specified len.
1141 @param len
1142 the length of the Unicode character array.
1144 @param encoding
1145 the text encoding to use for conversion.
1147 @param convertFlags
1148 flags which control the conversion. Either use
1149 OUSTRING_TO_OSTRING_CVTFLAGS, or see
1150 <http://udk.openoffice.org/cpp/man/spec/textconversion.html> for more
1151 details.
1153 void SAL_CALL rtl_uString2String( rtl_String ** newStr, const sal_Unicode * str, sal_Int32 len, rtl_TextEncoding encoding, sal_uInt32 convertFlags ) SAL_THROW_EXTERN_C();
1156 Converts a Unicode string to a byte string, signalling failure.
1158 @param pTarget
1159 An out parameter receiving the converted string. Must not be null itself, and
1160 must contain either null or a pointer to a valid rtl_String; the contents are
1161 not modified if conversion fails (rtl_convertUStringToString returns false).
1163 @param pSource
1164 The Unicode string. May only be null if nLength is zero.
1166 @param nLength
1167 The length of the Unicode string. Must be non-negative.
1169 @param nEncoding
1170 The text encoding to convert into. Must be an octet encoding (i.e.,
1171 rtl_isOctetTextEncoding(nEncoding) must return true).
1173 @param nFlags
1174 A combination of RTL_UNICODETOTEXT_FLAGS that detail how to do the conversion
1175 (see rtl_convertUnicodeToText). RTL_UNICODETOTEXT_FLAGS_FLUSH need not be
1176 included, it is implicitly assumed. Typical uses are either
1177 RTL_UNICODETOTEXT_FLAGS_UNDEFINED_ERROR |
1178 RTL_UNICODETOTEXT_FLAGS_INVALID_ERROR (fail if a Unicode character cannot be
1179 converted to the target nEncoding) or OUSTRING_TO_OSTRING_CVTFLAGS (make a
1180 best efforts conversion).
1182 @return
1183 True if the conversion succeeded, false otherwise.
1185 sal_Bool SAL_CALL rtl_convertUStringToString(rtl_String ** pTarget,
1186 sal_Unicode const * pSource,
1187 sal_Int32 nLength,
1188 rtl_TextEncoding nEncoding,
1189 sal_uInt32 nFlags)
1190 SAL_THROW_EXTERN_C();
1192 #ifdef __cplusplus
1194 #endif
1196 #endif /* _RTL_STRING_H_ */