xref: /aoo42x/main/sal/inc/rtl/string.h (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 #ifndef _RTL_STRING_H_
29 #define _RTL_STRING_H_
30 
31 #include <sal/types.h>
32 #include <osl/interlck.h>
33 #include <rtl/textcvt.h>
34 
35 #ifdef __cplusplus
36 extern "C" {
37 #endif
38 
39 /* ======================================================================= */
40 
41 /** Return the length of a string.
42 
43     The length is equal to the number of 8-bit characters in the string,
44     without the terminating NUL character.
45 
46     @param str
47     a null-terminated string.
48 
49     @return
50     the length of the sequence of characters represented by this string,
51     excluding the terminating NUL character.
52  */
53 sal_Int32 SAL_CALL rtl_str_getLength( const sal_Char * str ) SAL_THROW_EXTERN_C();
54 
55 /** Compare two strings.
56 
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
60     null-terminated.
61 
62     @param first
63     the first null-terminated string to be compared.
64 
65     @param second
66     the second null-terminated string which is compared with the first one.
67 
68     @return
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.
72  */
73 sal_Int32 SAL_CALL rtl_str_compare( const sal_Char * first, const sal_Char * second ) SAL_THROW_EXTERN_C();
74 
75 /** Compare two strings.
76 
77     The comparison is based on the numeric value of each character in the
78     strings and returns a value indicating their relationship.  This function
79     cannot be used for language-specific sorting.
80 
81     @param first
82     the first string to be compared.  Need not be null-terminated, but must be
83     at least as long as the specified firstLen.
84 
85     @param firstLen
86     the length of the first string.
87 
88     @param second
89     the second string which is compared with the first one.  Need not be
90     null-terminated, but must be at least as long as the specified secondLen.
91 
92     @param secondLen
93     the length of the second string.
94 
95     @return
96     0 if both strings are equal, a value less than 0 if the first string is
97     less than the second string, and a value greater than 0 if the first
98     string is greater than the second string.
99  */
100 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();
101 
102 /** Compare two strings with a maximum count of characters.
103 
104     The comparison is based on the numeric value of each character in the
105     strings and returns a value indicating their relationship.  This function
106     cannot be used for language-specific sorting.
107 
108     @param first
109     the first string to be compared.  Need not be null-terminated, but must be
110     at least as long as the specified firstLen.
111 
112     @param firstLen
113     the length of the first string.
114 
115     @param second
116     the second string which is compared with the first one.  Need not be
117     null-terminated, but must be at least as long as the specified secondLen.
118 
119     @param secondLen
120     the length of the second string.
121 
122     @param shortenedLen
123     the maximum number of characters to compare.  This length can be greater
124     or smaller than the lengths of the two strings.
125 
126     @return
127     0 if both substrings are equal, a value less than 0 if the first substring
128     is less than the second substring, and a value greater than 0 if the first
129     substring is greater than the second substring.
130  */
131 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();
132 
133 /** Compare two strings from back to front.
134 
135     The comparison is based on the numeric value of each character in the
136     strings and returns a value indicating their relationship.  This function
137     cannot be used for language-specific sorting.
138 
139     @param first
140     the first string to be compared.  Need not be null-terminated, but must be
141     at least as long as the specified firstLen.
142 
143     @param firstLen
144     the length of the first string.
145 
146     @param second
147     the second string which is compared with the first one.  Need not be
148     null-terminated, but must be at least as long as the specified secondLen.
149 
150     @param secondLen
151     the length of the second string.
152 
153     @return
154     0 if both strings are equal, a value less than 0 if the first string
155     compares less than the second string, and a value greater than 0 if the
156     first string compares greater than the second string.
157  */
158 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();
159 
160 /** Compare two strings, ignoring the case of ASCII characters.
161 
162     The comparison is based on the numeric value of each character in the
163     strings and returns a value indicating their relationship.  Character
164     values between 65 and 90 (ASCII A--Z) are interpreted as values between 97
165     and 122 (ASCII a--z).  This function cannot be used for language-specific
166     sorting.  Both strings must be null-terminated.
167 
168     @param first
169     the first null-terminated string to be compared.
170 
171     @param second
172     the second null-terminated string which is compared with the first one.
173 
174     @return
175     0 if both strings are equal, a value less than 0 if the first string is
176     less than the second string, and a value greater than 0 if the first
177     string is greater than the second string.
178  */
179 sal_Int32 SAL_CALL rtl_str_compareIgnoreAsciiCase( const sal_Char * first, const sal_Char * second ) SAL_THROW_EXTERN_C();
180 
181 /** Compare two strings, ignoring the case of ASCII characters.
182 
183     The comparison is based on the numeric value of each character in the
184     strings and returns a value indicating their relationship.  Character
185     values between 65 and 90 (ASCII A--Z) are interpreted as values between 97
186     and 122 (ASCII a--z).  This function cannot be used for language-specific
187     sorting.
188 
189     @param first
190     the first string to be compared.  Need not be null-terminated, but must be
191     at least as long as the specified firstLen.
192 
193     @param firstLen
194     the length of the first string.
195 
196     @param second
197     the second string which is compared with the first one.  Need not be
198     null-terminated, but must be at least as long as the specified secondLen.
199 
200     @param secondLen
201     the length of the second string.
202 
203     @return
204     0 if both strings are equal, a value less than 0 if the first string is
205     less than the second string, and a value greater than 0 if the first
206     string is greater than the second string.
207  */
208 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();
209 
210 /** Compare two strings with a maximum count of characters, ignoring the case
211     of ASCII characters.
212 
213     The comparison is based on the numeric value of each character in the
214     strings and returns a value indicating their relationship.  Character
215     values between 65 and 90 (ASCII A--Z) are interpreted as values between 97
216     and 122 (ASCII a--z).  This function cannot be used for language-specific
217     sorting.
218 
219     @param first
220     the first string to be compared.  Need not be null-terminated, but must be
221     at least as long as the specified firstLen.
222 
223     @param firstLen
224     the length of the first string.
225 
226     @param second
227     the second string which is compared with the first one.  Need not be
228     null-terminated, but must be at least as long as the specified secondLen.
229 
230     @param secondLen
231     the length of the second string.
232 
233     @param shortenedLen
234     the maximum number of characters to compare.  This length can be greater
235     or smaller than the lengths of the two strings.
236 
237     @return
238     0 if both substrings are equal, a value less than 0 if the first substring
239     is less than the second substring, and a value greater than 0 if the first
240     substring is greater than the second substring.
241  */
242 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();
243 
244 /** Return a hash code for a string.
245 
246     It is not allowed to store the hash code persistently, because later
247     versions could return other hash codes.  The string must be
248     null-terminated.
249 
250     @param str
251     a null-terminated string.
252 
253     @return
254     a hash code for the given string.
255  */
256 sal_Int32 SAL_CALL rtl_str_hashCode( const sal_Char * str ) SAL_THROW_EXTERN_C();
257 
258 /** Return a hash code for a string.
259 
260     It is not allowed to store the hash code persistently, because later
261     versions could return other hash codes.
262 
263     @param str
264     a string.  Need not be null-terminated, but must be at least as long as
265     the specified len.
266 
267     @param len
268     the length of the string.
269 
270     @return
271     a hash code for the given string.
272  */
273 sal_Int32 SAL_CALL rtl_str_hashCode_WithLength( const sal_Char * str, sal_Int32 len ) SAL_THROW_EXTERN_C();
274 
275 /** Search for the first occurrence of a character within a string.
276 
277     The string must be null-terminated.
278 
279     @param str
280     a null-terminated string.
281 
282     @param ch
283     the character to be searched for.
284 
285     @return
286     the index (starting at 0) of the first occurrence of the character in the
287     string, or -1 if the character does not occur.
288  */
289 sal_Int32 SAL_CALL rtl_str_indexOfChar( const sal_Char * str, sal_Char ch ) SAL_THROW_EXTERN_C();
290 
291 /** Search for the first occurrence of a character within a string.
292 
293     @param str
294     a string.  Need not be null-terminated, but must be at least as long as
295     the specified len.
296 
297     @param len
298     the length of the string.
299 
300     @param ch
301     the character to be searched for.
302 
303     @return
304     the index (starting at 0) of the first occurrence of the character in the
305     string, or -1 if the character does not occur.
306  */
307 sal_Int32 SAL_CALL rtl_str_indexOfChar_WithLength( const sal_Char * str, sal_Int32 len, sal_Char ch ) SAL_THROW_EXTERN_C();
308 
309 /** Search for the last occurrence of a character within a string.
310 
311     The string must be null-terminated.
312 
313     @param str
314     a null-terminated string.
315 
316     @param ch
317     the character to be searched for.
318 
319     @return
320     the index (starting at 0) of the last occurrence of the character in the
321     string, or -1 if the character does not occur.  The returned value is
322     always smaller than the string length.
323  */
324 sal_Int32 SAL_CALL rtl_str_lastIndexOfChar( const sal_Char * str, sal_Char ch ) SAL_THROW_EXTERN_C();
325 
326 /** Search for the last occurrence of a character within a string.
327 
328     @param str
329     a string.  Need not be null-terminated, but must be at least as long as
330     the specified len.
331 
332     @param len
333     the length of the string.
334 
335     @param ch
336     the character to be searched for.
337 
338     @return
339     the index (starting at 0) of the last occurrence of the character in the
340     string, or -1 if the character does not occur.  The returned value is
341     always smaller than the string length.
342  */
343 sal_Int32 SAL_CALL rtl_str_lastIndexOfChar_WithLength( const sal_Char * str, sal_Int32 len, sal_Char ch ) SAL_THROW_EXTERN_C();
344 
345 /** Search for the first occurrence of a substring within a string.
346 
347     If subStr is empty, or both str and subStr are empty, -1 is returned.
348     Both strings must be null-terminated.
349 
350     @param str
351     a null-terminated string.
352 
353     @param subStr
354     the null-terminated substring to be searched for.
355 
356     @return
357     the index (starting at 0) of the first character of the first occurrence
358     of the substring within the string, or -1 if the substring does not occur.
359  */
360 sal_Int32 SAL_CALL rtl_str_indexOfStr( const sal_Char * str, const sal_Char * subStr ) SAL_THROW_EXTERN_C();
361 
362 /** Search for the first occurrence of a substring within a string.
363 
364     If subStr is empty, or both str and subStr are empty, -1 is returned.
365 
366     @param str
367     a string.  Need not be null-terminated, but must be at least as long as
368     the specified len.
369 
370     @param len
371     the length of the string.
372 
373     @param subStr
374     the substring to be searched for.  Need not be null-terminated, but must
375     be at least as long as the specified subLen.
376 
377     @param subLen
378     the length of the substring.
379 
380     @return
381     the index (starting at 0) of the first character of the first occurrence
382     of the substring within the string, or -1 if the substring does not occur.
383  */
384 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();
385 
386 /** Search for the last occurrence of a substring within a string.
387 
388     If subStr is empty, or both str and subStr are empty, -1 is returned.
389     Both strings must be null-terminated.
390 
391     @param str
392     a null-terminated string.
393 
394     @param subStr
395     the null-terminated substring to be searched for.
396 
397     @return
398     the index (starting at 0) of the first character of the last occurrence
399     of the substring within the string, or -1 if the substring does not occur.
400  */
401 sal_Int32 SAL_CALL rtl_str_lastIndexOfStr( const sal_Char * str, const sal_Char * subStr ) SAL_THROW_EXTERN_C();
402 
403 /** Search for the last occurrence of a substring within a string.
404 
405     If subStr is empty, or both str and subStr are empty, -1 is returned.
406 
407     @param str
408     a string.  Need not be null-terminated, but must be at least as long as
409     the specified len.
410 
411     @param len
412     the length of the string.
413 
414     @param subStr
415     the substring to be searched for.  Need not be null-terminated, but must
416     be at least as long as the specified subLen.
417 
418     @param subLen
419     the length of the substring.
420 
421     @return
422     the index (starting at 0) of the first character of the first occurrence
423     of the substring within the string, or -1 if the substring does not occur.
424  */
425 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();
426 
427 /** Replace all occurrences of a single character within a string.
428 
429     If oldChar does not occur within str, then the string is not modified.
430     The string must be null-terminated.
431 
432     @param str
433     a null-terminated string.
434 
435     @param oldChar
436     the old character.
437 
438     @param newChar
439     the new character.
440  */
441 void SAL_CALL rtl_str_replaceChar( sal_Char * str, sal_Char oldChar, sal_Char newChar ) SAL_THROW_EXTERN_C();
442 
443 /** Replace all occurrences of a single character within a string.
444 
445     If oldChar does not occur within str, then the string is not modified.
446 
447     @param str
448     a string.  Need not be null-terminated, but must be at least as long as
449     the specified len.
450 
451     @param len
452     the length of the string.
453 
454     @param oldChar
455     the old character.
456 
457     @param newChar
458     the new character.
459  */
460 void SAL_CALL rtl_str_replaceChar_WithLength( sal_Char * str, sal_Int32 len, sal_Char oldChar, sal_Char newChar ) SAL_THROW_EXTERN_C();
461 
462 /** Convert all ASCII uppercase letters to lowercase within a string.
463 
464     The characters with values between 65 and 90 (ASCII A--Z) are replaced
465     with values between 97 and 122 (ASCII a--z).  The string must be
466     null-terminated.
467 
468     @param str
469     a null-terminated string.
470  */
471 void SAL_CALL rtl_str_toAsciiLowerCase( sal_Char * str ) SAL_THROW_EXTERN_C();
472 
473 /** Convert all ASCII uppercase letters to lowercase within a string.
474 
475     The characters with values between 65 and 90 (ASCII A--Z) are replaced
476     with values between 97 and 122 (ASCII a--z).
477 
478     @param str
479     a string.  Need not be null-terminated, but must be at least as long as
480     the specified len.
481 
482     @param len
483     the length of the string.
484  */
485 void SAL_CALL rtl_str_toAsciiLowerCase_WithLength( sal_Char * str, sal_Int32 len ) SAL_THROW_EXTERN_C();
486 
487 /** Convert all ASCII lowercase letters to uppercase within a string.
488 
489     The characters with values between 97 and 122 (ASCII a--z) are replaced
490     with values between 65 and 90 (ASCII A--Z).  The string must be
491     null-terminated.
492 
493     @param str
494     a null-terminated string.
495  */
496 void SAL_CALL rtl_str_toAsciiUpperCase( sal_Char * str ) SAL_THROW_EXTERN_C();
497 
498 /** Convert all ASCII lowercase letters to uppercase within a string.
499 
500     The characters with values between 97 and 122 (ASCII a--z) are replaced
501     with values between 65 and 90 (ASCII A--Z).
502 
503     @param str
504     a string.  Need not be null-terminated, but must be at least as long as
505     the specified len.
506 
507     @param len
508     the length of the string.
509  */
510 void SAL_CALL rtl_str_toAsciiUpperCase_WithLength( sal_Char * str, sal_Int32 len ) SAL_THROW_EXTERN_C();
511 
512 /** Remove white space from both ends of a string.
513 
514     All characters with values less than or equal to 32 (the space character)
515     are considered to be white space.  This function cannot be used for
516     language-specific operations.  The string must be null-terminated.
517 
518     @param str
519     a null-terminated string.
520 
521     @return
522     the new length of the string.
523  */
524 sal_Int32 SAL_CALL rtl_str_trim( sal_Char * str ) SAL_THROW_EXTERN_C();
525 
526 /** Remove white space from both ends of the string.
527 
528     All characters with values less than or equal to 32 (the space character)
529     are considered to be white space.  This function cannot be used for
530     language-specific operations.  The string must be null-terminated.
531 
532     @param str
533     a string.  Need not be null-terminated, but must be at least as long as
534     the specified len.
535 
536     @param len
537     the original length of the string.
538 
539     @return
540     the new length of the string.
541  */
542 sal_Int32 SAL_CALL rtl_str_trim_WithLength( sal_Char * str, sal_Int32 len ) SAL_THROW_EXTERN_C();
543 
544 /** Create the string representation of a boolean.
545 
546     If b is true, the buffer is filled with the string "true" and 5 is
547     returned.  If b is false, the buffer is filled with the string "false" and
548     6 is returned.  This function cannot be used for language-specific
549     operations.
550 
551     @param str
552     a buffer that is big enough to hold the result and the terminating NUL
553     character.  You should use the RTL_STR_MAX_VALUEOFBOOLEAN define to create
554     a buffer that is big enough.
555 
556     @param b
557     a boolean value.
558 
559     @return
560     the length of the string.
561  */
562 sal_Int32 SAL_CALL rtl_str_valueOfBoolean( sal_Char * str, sal_Bool b ) SAL_THROW_EXTERN_C();
563 #define RTL_STR_MAX_VALUEOFBOOLEAN 6
564 
565 /** Create the string representation of a character.
566 
567     @param str
568     a buffer that is big enough to hold the result and the terminating NUL
569     character.  You should use the RTL_STR_MAX_VALUEOFCHAR define to create a
570     buffer that is big enough.
571 
572     @param ch
573     a character value.
574 
575     @return
576     the length of the string.
577  */
578 sal_Int32 SAL_CALL rtl_str_valueOfChar( sal_Char * str, sal_Char ch ) SAL_THROW_EXTERN_C();
579 #define RTL_STR_MAX_VALUEOFCHAR 2
580 
581 /** Create the string representation of an integer.
582 
583     This function cannot be used for language-specific operations.
584 
585     @param str
586     a buffer that is big enough to hold the result and the terminating NUL
587     character.  You should use the RTL_STR_MAX_VALUEOFINT32 define to create a
588     buffer that is big enough.
589 
590     @param i
591     an integer value.
592 
593     @param radix
594     the radix.  Must be between RTL_STR_MIN_RADIX (2) and RTL_STR_MAX_RADIX
595     (36), inclusive.
596 
597     @return
598     the length of the string.
599  */
600 sal_Int32 SAL_CALL rtl_str_valueOfInt32( sal_Char * str, sal_Int32 i, sal_Int16 radix ) SAL_THROW_EXTERN_C();
601 #define RTL_STR_MIN_RADIX           2
602 #define RTL_STR_MAX_RADIX           36
603 #define RTL_STR_MAX_VALUEOFINT32    33
604 
605 /** Create the string representation of a long integer.
606 
607     This function cannot be used for language-specific operations.
608 
609     @param str
610     a buffer that is big enough to hold the result and the terminating NUL
611     character.  You should use the RTL_STR_MAX_VALUEOFINT64 define to create a
612     buffer that is big enough.
613 
614     @param l
615     a long integer value.
616 
617     @param radix
618     the radix.  Must be between RTL_STR_MIN_RADIX (2) and RTL_STR_MAX_RADIX
619     (36), inclusive.
620 
621     @return
622     the length of the string.
623  */
624 sal_Int32 SAL_CALL rtl_str_valueOfInt64( sal_Char * str, sal_Int64 l, sal_Int16 radix ) SAL_THROW_EXTERN_C();
625 #define RTL_STR_MAX_VALUEOFINT64 65
626 
627 /** Create the string representation of a float.
628 
629     This function cannot be used for language-specific conversion.
630 
631     @param str
632     a buffer that is big enough to hold the result and the terminating NUL
633     character.  You should use the RTL_STR_MAX_VALUEOFFLOAT define to create a
634     buffer that is big enough.
635 
636     @param f
637     a float value.
638 
639     @return
640     the length of the string.
641  */
642 sal_Int32 SAL_CALL rtl_str_valueOfFloat( sal_Char * str, float f ) SAL_THROW_EXTERN_C();
643 #define RTL_STR_MAX_VALUEOFFLOAT 15
644 
645 /** Create the string representation of a double.
646 
647     This function cannot be used for language-specific conversion.
648 
649     @param str
650     a buffer that is big enough to hold the result and the terminating NUL
651     character.  You should use the RTL_STR_MAX_VALUEOFDOUBLE define to create
652     a buffer that is big enough.
653 
654     @param d
655     a double value.
656 
657     @return
658     the length of the string.
659  */
660 sal_Int32 SAL_CALL rtl_str_valueOfDouble( sal_Char * str, double d ) SAL_THROW_EXTERN_C();
661 #define RTL_STR_MAX_VALUEOFDOUBLE 25
662 
663 /** Interpret a string as a boolean.
664 
665     This function cannot be used for language-specific conversion.  The string
666     must be null-terminated.
667 
668     @param str
669     a null-terminated string.
670 
671     @return
672     true if the string is "1" or "true" in any ASCII case, false otherwise.
673  */
674 sal_Bool SAL_CALL rtl_str_toBoolean( const sal_Char * str ) SAL_THROW_EXTERN_C();
675 
676 /** Interpret a string as an integer.
677 
678     This function cannot be used for language-specific conversion.  The string
679     must be null-terminated.
680 
681     @param str
682     a null-terminated string.
683 
684     @param radix
685     the radix.  Must be between RTL_STR_MIN_RADIX (2) and RTL_STR_MAX_RADIX
686     (36), inclusive.
687 
688     @return
689     the integer value represented by the string, or 0 if the string does not
690     represent an integer.
691  */
692 sal_Int32 SAL_CALL rtl_str_toInt32( const sal_Char * str, sal_Int16 radix ) SAL_THROW_EXTERN_C();
693 
694 /** Interpret a string as a long integer.
695 
696     This function cannot be used for language-specific conversion.  The string
697     must be null-terminated.
698 
699     @param str
700     a null-terminated string.
701 
702     @param radix
703     the radix.  Must be between RTL_STR_MIN_RADIX (2) and RTL_STR_MAX_RADIX
704     (36), inclusive.
705 
706     @return
707     the long integer value represented by the string, or 0 if the string does
708     not represent a long integer.
709  */
710 sal_Int64 SAL_CALL rtl_str_toInt64( const sal_Char * str, sal_Int16 radix ) SAL_THROW_EXTERN_C();
711 
712 /** Interpret a string as a float.
713 
714     This function cannot be used for language-specific conversion.  The string
715     must be null-terminated.
716 
717     @param str
718     a null-terminated string.
719 
720     @return
721     the float value represented by the string, or 0.0 if the string does not
722     represent a float.
723  */
724 float SAL_CALL rtl_str_toFloat( const sal_Char * str ) SAL_THROW_EXTERN_C();
725 
726 /** Interpret a string as a double.
727 
728     This function cannot be used for language-specific conversion.  The string
729     must be null-terminated.
730 
731     @param str
732     a null-terminated string.
733 
734     @return
735     the float value represented by the string, or 0.0 if the string does not
736     represent a double.
737  */
738 double SAL_CALL rtl_str_toDouble( const sal_Char * str ) SAL_THROW_EXTERN_C();
739 
740 /* ======================================================================= */
741 
742 #ifdef SAL_W32
743 #	pragma pack(push, 8)
744 #elif defined(SAL_OS2)
745 #	pragma pack(push, 4)
746 #endif
747 
748 /** The implementation of a byte string.
749 
750     @internal
751  */
752 typedef struct _rtl_String
753 {
754     oslInterlockedCount refCount; /* opaque */
755     sal_Int32           length;
756     sal_Char            buffer[1];
757 } rtl_String;
758 
759 #if defined( SAL_W32) ||  defined(SAL_OS2)
760 #pragma pack(pop)
761 #endif
762 
763 /* ----------------------------------------------------------------------- */
764 
765 /** Increment the reference count of a string.
766 
767     @param str
768     a string.
769  */
770 void SAL_CALL rtl_string_acquire( rtl_String * str ) SAL_THROW_EXTERN_C();
771 
772 /** Decrement the reference count of a string.
773 
774     If the count goes to zero than the string data is deleted.
775 
776     @param str
777     a string.
778  */
779 void SAL_CALL rtl_string_release( rtl_String * str ) SAL_THROW_EXTERN_C();
780 
781 /** Allocate a new string containing no characters.
782 
783     @param newStr
784     pointer to the new string.  The pointed-to data must be null or a valid
785     string.
786  */
787 void SAL_CALL rtl_string_new( rtl_String ** newStr ) SAL_THROW_EXTERN_C();
788 
789 /** Allocate a new string containing space for a given number of characters.
790 
791     If len is greater than zero, the reference count of the new string will be
792     1.  The values of all characters are set to 0 and the length of the string
793     is 0.  This function does not handle out-of-memory conditions.
794 
795     @param newStr
796     pointer to the new string.  The pointed-to data must be null or a valid
797     string.
798 
799     @param len
800     the number of characters.
801  */
802 void SAL_CALL rtl_string_new_WithLength( rtl_String ** newStr, sal_Int32 len ) SAL_THROW_EXTERN_C();
803 
804 /** Allocate a new string that contains a copy of another string.
805 
806     If the length of value is greater than zero, the reference count of the
807     new string will be 1.  This function does not handle out-of-memory
808     conditions.
809 
810     @param newStr
811     pointer to the new string.  The pointed-to data must be null or a valid
812     string.
813 
814     @param value
815     a valid string.
816  */
817 void SAL_CALL rtl_string_newFromString( rtl_String ** newStr, const rtl_String * value ) SAL_THROW_EXTERN_C();
818 
819 /** Allocate a new string that contains a copy of a character array.
820 
821     If the length of value is greater than zero, the reference count of the
822     new string will be 1.  This function does not handle out-of-memory
823     conditions.
824 
825     @param newStr
826     pointer to the new string.  The pointed-to data must be null or a valid
827     string.
828 
829     @param value
830     a null-terminated character array.
831  */
832 void SAL_CALL rtl_string_newFromStr( rtl_String ** newStr, const sal_Char * value ) SAL_THROW_EXTERN_C();
833 
834 /** Allocate a new string that contains a copy of a character array.
835 
836     If the length of value is greater than zero, the reference count of the
837     new string will be 1.  This function does not handle out-of-memory
838     conditions.
839 
840     @param newStr
841     pointer to the new string.  The pointed-to data must be null or a valid
842     string.
843 
844     @param value
845     a character array.  Need not be null-terminated, but must be at least as
846     long as the specified len.
847 
848     @param len
849     the length of the character array.
850  */
851 void SAL_CALL rtl_string_newFromStr_WithLength( rtl_String ** newStr, const sal_Char * value, sal_Int32 len ) SAL_THROW_EXTERN_C();
852 
853 /** Assign a new value to a string.
854 
855     First releases any value str might currently hold, then acquires
856     rightValue.
857 
858     @param str
859     pointer to the string.  The pointed-to data must be null or a valid
860     string.
861 
862     @param rightValue
863     a valid string.
864  */
865 void SAL_CALL rtl_string_assign( rtl_String ** str, rtl_String * rightValue ) SAL_THROW_EXTERN_C();
866 
867 /** Return the length of a string.
868 
869     The length is equal to the number of characters in the string.
870 
871     @param str
872     a valid string.
873 
874     @return
875     the length of the string.
876  */
877 sal_Int32 SAL_CALL rtl_string_getLength( const rtl_String * str ) SAL_THROW_EXTERN_C();
878 
879 /** Return a pointer to the underlying character array of a string.
880 
881     @param str
882     a valid string.
883 
884     @return
885     a pointer to the null-terminated character array.
886  */
887 sal_Char * SAL_CALL rtl_string_getStr( rtl_String * str ) SAL_THROW_EXTERN_C();
888 
889 /** Create a new string that is the concatenation of two other strings.
890 
891     The new string does not necessarily have a reference count of 1 (in cases
892     where one of the two other strings is empty), so it must not be modified
893     without checking the reference count.  This function does not handle
894     out-of-memory conditions.
895 
896     @param newStr
897     pointer to the new string.  The pointed-to data must be null or a valid
898     string.
899 
900     @param left
901     a valid string.
902 
903     @param right
904     a valid string.
905  */
906 void SAL_CALL rtl_string_newConcat( rtl_String ** newStr, rtl_String * left, rtl_String * right ) SAL_THROW_EXTERN_C();
907 
908 /** Create a new string by replacing a substring of another string.
909 
910     The new string results from replacing a number of characters (count),
911     starting at the specified position (index) in the original string (str),
912     with some new substring (subStr).  If subStr is null, than only a number
913     of characters is deleted.
914 
915     The new string does not necessarily have a reference count of 1, so it
916     must not be modified without checking the reference count.  This function
917     does not handle out-of-memory conditions.
918 
919     @param newStr
920     pointer to the new string.  The pointed-to data must be null or a valid
921     string.
922 
923     @param str
924     a valid string.
925 
926     @param index
927     the index into str at which to start replacement.  Must be between 0 and
928     the length of str, inclusive.
929 
930     @param count
931     the number of charcters to remove.  Must not be negative, and the sum of
932     index and count must not exceed the length of str.
933 
934     @param subStr
935     either null or a valid string to be inserted.
936  */
937 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();
938 
939 /** Create a new string by replacing all occurrences of a single character
940     within another string.
941 
942     The new string results from replacing all occurrences of oldChar in str
943     with newChar.
944 
945     The new string does not necessarily have a reference count of 1 (in cases
946     where oldChar does not occur in str), so it must not be modified without
947     checking the reference count.  This function does not handle out-of-memory
948     conditions.
949 
950     @param newStr
951     pointer to the new string.  The pointed-to data must be null or a valid
952     string.
953 
954     @param str
955     a valid string.
956 
957     @param oldChar
958     the old character.
959 
960     @param newChar
961     the new character.
962  */
963 void SAL_CALL rtl_string_newReplace( rtl_String ** newStr, rtl_String * str, sal_Char oldChar, sal_Char newChar ) SAL_THROW_EXTERN_C();
964 
965 /** Create a new string by converting all ASCII uppercase letters to lowercase
966     within another string.
967 
968     The new string results from replacing all characters with values between
969     65 and 90 (ASCII A--Z) by values between 97 and 122 (ASCII a--z).
970 
971     This function cannot be used for language-specific conversion.  The new
972     string does not necessarily have a reference count of 1 (in cases where
973     no characters need to be converted), so it must not be modified without
974     checking the reference count.  This function does not handle out-of-memory
975     conditions.
976 
977     @param newStr
978     pointer to the new string.  The pointed-to data must be null or a valid
979     string.
980 
981     @param str
982     a valid string.
983  */
984 void SAL_CALL rtl_string_newToAsciiLowerCase( rtl_String ** newStr, rtl_String * str ) SAL_THROW_EXTERN_C();
985 
986 /** Create a new string by converting all ASCII lowercase letters to uppercase
987     within another string.
988 
989     The new string results from replacing all characters with values between
990     97 and 122 (ASCII a--z) by values between 65 and 90 (ASCII A--Z).
991 
992     This function cannot be used for language-specific conversion.  The new
993     string does not necessarily have a reference count of 1 (in cases where
994     no characters need to be converted), so it must not be modified without
995     checking the reference count.  This function does not handle out-of-memory
996     conditions.
997 
998     @param newStr
999     pointer to the new string.  The pointed-to data must be null or a valid
1000     string.
1001 
1002     @param str
1003     a valid string.
1004  */
1005 void SAL_CALL rtl_string_newToAsciiUpperCase( rtl_String ** newStr, rtl_String * str ) SAL_THROW_EXTERN_C();
1006 
1007 /** Create a new string by removing white space from both ends of another
1008     string.
1009 
1010     The new string results from removing all characters with values less than
1011     or equal to 32 (the space character) form both ends of str.
1012 
1013     This function cannot be used for language-specific conversion.  The new
1014     string does not necessarily have a reference count of 1 (in cases where
1015     no characters need to be removed), so it must not be modified without
1016     checking the reference count.  This function does not handle out-of-memory
1017     conditions.
1018 
1019     @param newStr
1020     pointer to the new string.  The pointed-to data must be null or a valid
1021     string.
1022 
1023     @param str
1024     a valid string.
1025  */
1026 void SAL_CALL rtl_string_newTrim( rtl_String ** newStr, rtl_String * str ) SAL_THROW_EXTERN_C();
1027 
1028 /** Create a new string by extracting a single token from another string.
1029 
1030     Starting at index, the token's next token is searched for.  If there is no
1031     such token, the result is an empty string.  Otherwise, all characters from
1032     the start of that token and up to, but not including the next occurrence
1033     of cTok make up the resulting token.  The return value is the position of
1034     the next token, or -1 if no more tokens follow.
1035 
1036     Example code could look like
1037       rtl_String * pToken = NULL;
1038       sal_Int32 nIndex = 0;
1039       do
1040       {
1041           ...
1042           nIndex = rtl_string_getToken(&pToken, pStr, 0, ';', nIndex);
1043           ...
1044       }
1045       while (nIndex >= 0);
1046 
1047     The new string does not necessarily have a reference count of 1, so it
1048     must not be modified without checking the reference count.  This function
1049     does not handle out-of-memory conditions.
1050 
1051     @param newStr
1052     pointer to the new string.  The pointed-to data must be null or a valid
1053     string.  If either token or index is negative, an empty token is stored in
1054     newStr (and -1 is returned).
1055 
1056     @param str
1057     a valid string.
1058 
1059     @param token
1060     the number of the token to return, starting at index.
1061 
1062     @param cTok
1063     the character that seperates the tokens.
1064 
1065     @param index
1066     the position at which searching for the token starts.  Must not be greater
1067     than the length of str.
1068 
1069     @return
1070     the index of the next token, or -1 if no more tokens follow.
1071  */
1072 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();
1073 
1074 /* ======================================================================= */
1075 
1076 /** Supply an ASCII string literal together with its length.
1077 
1078     This macro can be used to compute (some of) the arguments in function calls
1079     like rtl::OString(RTL_CONSTASCII_STRINGPARAM("foo")) or
1080     rtl::OUString::equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("foo")).
1081 
1082     @param constAsciiStr
1083     must be an expression of type "(possibly cv-qualified reference to) array of
1084     (possibly cv-qualified) char."  Each element of the referenced array must
1085     represent an ASCII value in the range 0x00--0x7F.  The last element of the
1086     referenced array is not considered part of the represented ASCII string, and
1087     its value should be 0x00.  Depending on where this macro is used, the nature
1088     of the supplied expression might be further restricted.
1089 */
1090 #define RTL_CONSTASCII_STRINGPARAM( constAsciiStr ) constAsciiStr, ((sal_Int32)sizeof(constAsciiStr)-1)
1091 
1092 /** Supply the length of an ASCII string literal.
1093 
1094     This macro can be used to compute arguments in function calls like
1095     rtl::OUString::match(other, RTL_CONSTASCII_LENGTH("prefix")).
1096 
1097     @param constAsciiStr
1098     must be an expression of type "(possibly cv-qualified reference to) array of
1099     (possibly cv-qualified) char."  Each element of the referenced array must
1100     represent an ASCII value in the range 0x00--0x7F.  The last element of the
1101     referenced array is not considered part of the represented ASCII string, and
1102     its value should be 0x00.  Depending on where this macro is used, the nature
1103     of the supplied expression might be further restricted.
1104 */
1105 #define RTL_CONSTASCII_LENGTH( constAsciiStr ) ((sal_Int32)(sizeof(constAsciiStr)-1))
1106 
1107 /* ======================================================================= */
1108 
1109 /* predefined constants for String-Conversion */
1110 #define OUSTRING_TO_OSTRING_CVTFLAGS    (RTL_UNICODETOTEXT_FLAGS_UNDEFINED_DEFAULT |\
1111                                          RTL_UNICODETOTEXT_FLAGS_INVALID_DEFAULT |\
1112                                          RTL_UNICODETOTEXT_FLAGS_UNDEFINED_REPLACE |\
1113                                          RTL_UNICODETOTEXT_FLAGS_PRIVATE_MAPTO0 |\
1114                                          RTL_UNICODETOTEXT_FLAGS_NOCOMPOSITE)
1115 
1116 /* ----------------------------------------------------------------------- */
1117 
1118 /** Create a new byte string by converting a Unicode string, using a specific
1119     text encoding.
1120 
1121     The lengths of the byte string and the Unicode string may differ (e.g.,
1122     for double-byte encodings, UTF-7, UTF-8).
1123 
1124     If the length of the Unicode string is greater than zero, the reference
1125     count of the new string will be 1.
1126 
1127     If an out-of-memory condition occurs, newStr will point to a null pointer
1128     upon return.
1129 
1130     @param newStr
1131     pointer to the new string.  The pointed-to data must be null or a valid
1132     string.
1133 
1134     @param str
1135     a Unicode character array.  Need not be null-terminated, but must be at
1136     least as long as the specified len.
1137 
1138     @param len
1139     the length of the Unicode character array.
1140 
1141     @param encoding
1142     the text encoding to use for conversion.
1143 
1144     @param convertFlags
1145     flags which control the conversion.  Either use
1146     OUSTRING_TO_OSTRING_CVTFLAGS, or see
1147     <http://udk.openoffice.org/cpp/man/spec/textconversion.html> for more
1148     details.
1149  */
1150 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();
1151 
1152 /**
1153   Converts a Unicode string to a byte string, signalling failure.
1154 
1155   @param pTarget
1156   An out parameter receiving the converted string.  Must not be null itself, and
1157   must contain either null or a pointer to a valid rtl_String; the contents are
1158   not modified if conversion fails (rtl_convertUStringToString returns false).
1159 
1160   @param pSource
1161   The Unicode string.  May only be null if nLength is zero.
1162 
1163   @param nLength
1164   The length of the Unicode string.  Must be non-negative.
1165 
1166   @param nEncoding
1167   The text encoding to convert into.  Must be an octet encoding (i.e.,
1168   rtl_isOctetTextEncoding(nEncoding) must return true).
1169 
1170   @param nFlags
1171   A combination of RTL_UNICODETOTEXT_FLAGS that detail how to do the conversion
1172   (see rtl_convertUnicodeToText).  RTL_UNICODETOTEXT_FLAGS_FLUSH need not be
1173   included, it is implicitly assumed.  Typical uses are either
1174   RTL_UNICODETOTEXT_FLAGS_UNDEFINED_ERROR |
1175   RTL_UNICODETOTEXT_FLAGS_INVALID_ERROR (fail if a Unicode character cannot be
1176   converted to the target nEncoding) or OUSTRING_TO_OSTRING_CVTFLAGS (make a
1177   best efforts conversion).
1178 
1179   @return
1180   True if the conversion succeeded, false otherwise.
1181  */
1182 sal_Bool SAL_CALL rtl_convertUStringToString(rtl_String ** pTarget,
1183                                              sal_Unicode const * pSource,
1184                                              sal_Int32 nLength,
1185                                              rtl_TextEncoding nEncoding,
1186                                              sal_uInt32 nFlags)
1187     SAL_THROW_EXTERN_C();
1188 
1189 #ifdef __cplusplus
1190 }
1191 #endif
1192 
1193 #endif /* _RTL_STRING_H_ */
1194