1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: string.hxx,v $
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_HXX_
32 #define _RTL_STRING_HXX_
36 #ifndef _RTL_DIAGNOSE_H_
37 #include <osl/diagnose.h>
39 #include <rtl/memory.h>
40 #include <rtl/textenc.h>
41 #include <rtl/string.h>
43 #if !defined EXCEPTIONS_OFF
50 /* ======================================================================= */
53 This String class provide base functionality for C++ like 8-Bit
54 character array handling. The advantage of this class is, that it
55 handle all the memory managament for you - and it do it
56 more efficient. If you assign a string to another string, the
57 data of both strings are shared (without any copy operation or
58 memory allocation) as long as you do not change the string. This class
59 stores also the length of the string, so that many operations are
60 faster as the C-str-functions.
62 This class provide only readonly string handling. So you could create
63 a string and you could only query the content from this string.
64 It provide also functionality to change the string, but this results
65 in every case in a new string instance (in the most cases with an
66 memory allocation). You don't have functionality to change the
67 content of the string. If you want change the string content, than
68 you should us the OStringBuffer class, which provide these
69 functionality and avoid to much memory allocation.
71 The design of this class is similar to the string classes in Java
72 and so more people should have fewer understanding problems when they
87 OString( rtl_String
* value
, DO_NOT_ACQUIRE
* )
94 New string containing no characters.
96 OString() SAL_THROW(())
99 rtl_string_new( &pData
);
103 New string from OString.
105 @param str a OString.
107 OString( const OString
& str
) SAL_THROW(())
110 rtl_string_acquire( pData
);
114 New string from OString data.
116 @param str a OString data.
118 OString( rtl_String
* str
) SAL_THROW(())
121 rtl_string_acquire( pData
);
125 New string from a single character.
127 @param value a character.
129 explicit OString( sal_Char value
) SAL_THROW(())
132 rtl_string_newFromStr_WithLength( &pData
, &value
, 1 );
136 New string from a character buffer array.
138 @param value a NULL-terminated character array.
140 OString( const sal_Char
* value
) SAL_THROW(())
143 rtl_string_newFromStr( &pData
, value
);
147 New string from a character buffer array.
149 @param value a character array.
150 @param length the number of character which should be copied.
151 The character array length must be greater or
152 equal than this value.
154 OString( const sal_Char
* value
, sal_Int32 length
) SAL_THROW(())
157 rtl_string_newFromStr_WithLength( &pData
, value
, length
);
161 New string from a Unicode character buffer array.
163 @param value a Unicode character array.
164 @param length the number of character which should be converted.
165 The Unicode character array length must be
166 greater or equal than this value.
167 @param encoding the text encoding in which the Unicode character
168 sequence should be converted.
169 @param convertFlags flags which controls the conversion.
170 see RTL_UNICODETOTEXT_FLAGS_...
172 @exception std::bad_alloc is thrown if an out-of-memory condition occurs
174 OString( const sal_Unicode
* value
, sal_Int32 length
,
175 rtl_TextEncoding encoding
,
176 sal_uInt32 convertFlags
= OUSTRING_TO_OSTRING_CVTFLAGS
)
179 rtl_uString2String( &pData
, value
, length
, encoding
, convertFlags
);
180 #if defined EXCEPTIONS_OFF
181 OSL_ASSERT(pData
!= NULL
);
184 throw std::bad_alloc();
190 Release the string data.
192 ~OString() SAL_THROW(())
194 rtl_string_release( pData
);
200 @param str a OString.
202 OString
& operator=( const OString
& str
) SAL_THROW(())
204 rtl_string_assign( &pData
, str
.pData
);
209 Append a string to this string.
211 @param str a OString.
213 OString
& operator+=( const OString
& str
) SAL_THROW(())
215 rtl_string_newConcat( &pData
, pData
, str
.pData
);
220 Returns the length of this string.
222 The length is equal to the number of characters in this string.
224 @return the length of the sequence of characters represented by this
227 sal_Int32
getLength() const SAL_THROW(()) { return pData
->length
; }
230 Returns a pointer to the characters of this string.
232 <p>The returned pointer is not guaranteed to point to a null-terminated
233 byte string. Note that this string object may contain embedded null
234 characters, which will thus also be embedded in the returned byte
237 @return a pointer to a (not necessarily null-terminated) byte string
238 representing the characters of this string object.
240 operator const sal_Char
*() const SAL_THROW(()) { return pData
->buffer
; }
243 Returns a pointer to the characters of this string.
245 <p>The returned pointer is guaranteed to point to a null-terminated byte
246 string. But note that this string object may contain embedded null
247 characters, which will thus also be embedded in the returned
248 null-terminated byte string.</p>
250 @return a pointer to a null-terminated byte string representing the
251 characters of this string object.
253 const sal_Char
* getStr() const SAL_THROW(()) { return pData
->buffer
; }
256 Compares two strings.
258 The comparison is based on the numeric value of each character in
259 the strings and return a value indicating their relationship.
260 This function can't be used for language specific sorting.
262 @param str the object to be compared.
263 @return 0 - if both strings are equal
264 < 0 - if this string is less than the string argument
265 > 0 - if this string is greater than the string argument
267 sal_Int32
compareTo( const OString
& str
) const SAL_THROW(())
269 return rtl_str_compare_WithLength( pData
->buffer
, pData
->length
,
270 str
.pData
->buffer
, str
.pData
->length
);
274 Compares two strings with an maximum count of characters.
276 The comparison is based on the numeric value of each character in
277 the strings and return a value indicating their relationship.
278 This function can't be used for language specific sorting.
280 @param str the object to be compared.
281 @param maxLength the maximum count of characters to be compared.
282 @return 0 - if both strings are equal
283 < 0 - if this string is less than the string argument
284 > 0 - if this string is greater than the string argument
286 sal_Int32
compareTo( const OString
& rObj
, sal_Int32 maxLength
) const SAL_THROW(())
288 return rtl_str_shortenedCompare_WithLength( pData
->buffer
, pData
->length
,
289 rObj
.pData
->buffer
, rObj
.pData
->length
, maxLength
);
293 Compares two strings in reverse order.
295 The comparison is based on the numeric value of each character in
296 the strings and return a value indicating their relationship.
297 This function can't be used for language specific sorting.
299 @param str the object to be compared.
300 @return 0 - if both strings are equal
301 < 0 - if this string is less than the string argument
302 > 0 - if this string is greater than the string argument
304 sal_Int32
reverseCompareTo( const OString
& str
) const SAL_THROW(())
306 return rtl_str_reverseCompare_WithLength( pData
->buffer
, pData
->length
,
307 str
.pData
->buffer
, str
.pData
->length
);
311 Perform a comparison of two strings.
313 The result is true if and only if second string
314 represents the same sequence of characters as the first string.
315 This function can't be used for language specific comparison.
317 @param str the object to be compared.
318 @return sal_True if the strings are equal;
319 sal_False, otherwise.
321 sal_Bool
equals( const OString
& str
) const SAL_THROW(())
323 if ( pData
->length
!= str
.pData
->length
)
325 if ( pData
== str
.pData
)
327 return rtl_str_reverseCompare_WithLength( pData
->buffer
, pData
->length
,
328 str
.pData
->buffer
, str
.pData
->length
) == 0;
332 Perform a ASCII lowercase comparison of two strings.
334 The result is true if and only if second string
335 represents the same sequence of characters as the first string,
337 Character values between 65 and 90 (ASCII A-Z) are interpreted as
338 values between 97 and 122 (ASCII a-z).
339 This function can't be used for language specific comparison.
341 @param str the object to be compared.
342 @return sal_True if the strings are equal;
343 sal_False, otherwise.
345 sal_Bool
equalsIgnoreAsciiCase( const OString
& str
) const SAL_THROW(())
347 if ( pData
->length
!= str
.pData
->length
)
349 if ( pData
== str
.pData
)
351 return rtl_str_compareIgnoreAsciiCase_WithLength( pData
->buffer
, pData
->length
,
352 str
.pData
->buffer
, str
.pData
->length
) == 0;
356 Match against a substring appearing in this string.
358 The result is true if and only if the second string appears as a substring
359 of this string, at the given position.
360 This function can't be used for language specific comparison.
362 @param str the object (substring) to be compared.
363 @param fromIndex the index to start the comparion from.
364 The index must be greater or equal than 0
365 and less or equal as the string length.
366 @return sal_True if str match with the characters in the string
367 at the given position;
368 sal_False, otherwise.
370 sal_Bool
match( const OString
& str
, sal_Int32 fromIndex
= 0 ) const SAL_THROW(())
372 return rtl_str_shortenedCompare_WithLength( pData
->buffer
+fromIndex
, pData
->length
-fromIndex
,
373 str
.pData
->buffer
, str
.pData
->length
, str
.pData
->length
) == 0;
377 Match against a substring appearing in this string, ignoring the case of
380 The result is true if and only if the second string appears as a substring
381 of this string, at the given position.
382 Character values between 65 and 90 (ASCII A-Z) are interpreted as
383 values between 97 and 122 (ASCII a-z).
384 This function can't be used for language specific comparison.
386 @param str the object (substring) to be compared.
387 @param fromIndex the index to start the comparion from.
388 The index must be greater or equal than 0
389 and less or equal as the string length.
390 @return sal_True if str match with the characters in the string
391 at the given position;
392 sal_False, otherwise.
394 sal_Bool
matchIgnoreAsciiCase( const OString
& str
, sal_Int32 fromIndex
= 0 ) const SAL_THROW(())
396 return rtl_str_shortenedCompareIgnoreAsciiCase_WithLength( pData
->buffer
+fromIndex
, pData
->length
-fromIndex
,
397 str
.pData
->buffer
, str
.pData
->length
,
398 str
.pData
->length
) == 0;
401 friend sal_Bool
operator == ( const OString
& rStr1
, const OString
& rStr2
) SAL_THROW(())
402 { return rStr1
.getLength() == rStr2
.getLength() && rStr1
.compareTo( rStr2
) == 0; }
403 friend sal_Bool
operator == ( const OString
& rStr1
, const sal_Char
* pStr2
) SAL_THROW(())
404 { return rStr1
.compareTo( pStr2
) == 0; }
405 friend sal_Bool
operator == ( const sal_Char
* pStr1
, const OString
& rStr2
) SAL_THROW(())
406 { return OString( pStr1
).compareTo( rStr2
) == 0; }
408 friend sal_Bool
operator != ( const OString
& rStr1
, const OString
& rStr2
) SAL_THROW(())
409 { return !(operator == ( rStr1
, rStr2
)); }
410 friend sal_Bool
operator != ( const OString
& rStr1
, const sal_Char
* pStr2
) SAL_THROW(())
411 { return !(operator == ( rStr1
, pStr2
)); }
412 friend sal_Bool
operator != ( const sal_Char
* pStr1
, const OString
& rStr2
) SAL_THROW(())
413 { return !(operator == ( pStr1
, rStr2
)); }
415 friend sal_Bool
operator < ( const OString
& rStr1
, const OString
& rStr2
) SAL_THROW(())
416 { return rStr1
.compareTo( rStr2
) < 0; }
417 friend sal_Bool
operator > ( const OString
& rStr1
, const OString
& rStr2
) SAL_THROW(())
418 { return rStr1
.compareTo( rStr2
) > 0; }
419 friend sal_Bool
operator <= ( const OString
& rStr1
, const OString
& rStr2
) SAL_THROW(())
420 { return rStr1
.compareTo( rStr2
) <= 0; }
421 friend sal_Bool
operator >= ( const OString
& rStr1
, const OString
& rStr2
) SAL_THROW(())
422 { return rStr1
.compareTo( rStr2
) >= 0; }
425 Returns a hashcode for this string.
427 @return a hash code value for this object.
429 @see rtl::OStringHash for convenient use of STLPort's hash_map
431 sal_Int32
hashCode() const SAL_THROW(())
433 return rtl_str_hashCode_WithLength( pData
->buffer
, pData
->length
);
437 Returns the index within this string of the first occurrence of the
438 specified character, starting the search at the specified index.
440 @param ch character to be located.
441 @param fromIndex the index to start the search from.
442 The index must be greater or equal than 0
443 and less or equal as the string length.
444 @return the index of the first occurrence of the character in the
445 character sequence represented by this string that is
446 greater than or equal to fromIndex, or
447 -1 if the character does not occur.
449 sal_Int32
indexOf( sal_Char ch
, sal_Int32 fromIndex
= 0 ) const SAL_THROW(())
451 sal_Int32 ret
= rtl_str_indexOfChar_WithLength( pData
->buffer
+fromIndex
, pData
->length
-fromIndex
, ch
);
452 return (ret
< 0 ? ret
: ret
+fromIndex
);
456 Returns the index within this string of the last occurrence of the
457 specified character, searching backward starting at the end.
459 @param ch character to be located.
460 @return the index of the last occurrence of the character in the
461 character sequence represented by this string, or
462 -1 if the character does not occur.
464 sal_Int32
lastIndexOf( sal_Char ch
) const SAL_THROW(())
466 return rtl_str_lastIndexOfChar_WithLength( pData
->buffer
, pData
->length
, ch
);
470 Returns the index within this string of the last occurrence of the
471 specified character, searching backward starting before the specified
474 @param ch character to be located.
475 @param fromIndex the index before which to start the search.
476 @return the index of the last occurrence of the character in the
477 character sequence represented by this string that
478 is less than fromIndex, or -1
479 if the character does not occur before that point.
481 sal_Int32
lastIndexOf( sal_Char ch
, sal_Int32 fromIndex
) const SAL_THROW(())
483 return rtl_str_lastIndexOfChar_WithLength( pData
->buffer
, fromIndex
, ch
);
487 Returns the index within this string of the first occurrence of the
488 specified substring, starting at the specified index.
490 If str doesn't include any character, always -1 is
491 returned. This is also the case, if both strings are empty.
493 @param str the substring to search for.
494 @param fromIndex the index to start the search from.
495 @return If the string argument occurs one or more times as a substring
496 within this string at the starting index, then the index
497 of the first character of the first such substring is
498 returned. If it does not occur as a substring starting
499 at fromIndex or beyond, -1 is returned.
501 sal_Int32
indexOf( const OString
& str
, sal_Int32 fromIndex
= 0 ) const SAL_THROW(())
503 sal_Int32 ret
= rtl_str_indexOfStr_WithLength( pData
->buffer
+fromIndex
, pData
->length
-fromIndex
,
504 str
.pData
->buffer
, str
.pData
->length
);
505 return (ret
< 0 ? ret
: ret
+fromIndex
);
509 Returns the index within this string of the last occurrence of
510 the specified substring, searching backward starting at the end.
512 The returned index indicates the starting index of the substring
514 If str doesn't include any character, always -1 is
515 returned. This is also the case, if both strings are empty.
517 @param str the substring to search for.
518 @return If the string argument occurs one or more times as a substring
519 within this string, then the index of the first character of
520 the last such substring is returned. If it does not occur as
521 a substring, -1 is returned.
523 sal_Int32
lastIndexOf( const OString
& str
) const SAL_THROW(())
525 return rtl_str_lastIndexOfStr_WithLength( pData
->buffer
, pData
->length
,
526 str
.pData
->buffer
, str
.pData
->length
);
530 Returns the index within this string of the last occurrence of
531 the specified substring, searching backward starting before the specified
534 The returned index indicates the starting index of the substring
536 If str doesn't include any character, always -1 is
537 returned. This is also the case, if both strings are empty.
539 @param str the substring to search for.
540 @param fromIndex the index before which to start the search.
541 @return If the string argument occurs one or more times as a substring
542 within this string before the starting index, then the index
543 of the first character of the last such substring is
544 returned. Otherwise, -1 is returned.
546 sal_Int32
lastIndexOf( const OString
& str
, sal_Int32 fromIndex
) const SAL_THROW(())
548 return rtl_str_lastIndexOfStr_WithLength( pData
->buffer
, fromIndex
,
549 str
.pData
->buffer
, str
.pData
->length
);
553 Returns a new string that is a substring of this string.
555 The substring begins at the specified beginIndex. It is an error for
556 beginIndex to be negative or to be greater than the length of this string.
558 @param beginIndex the beginning index, inclusive.
559 @return the specified substring.
561 OString
copy( sal_Int32 beginIndex
) const SAL_THROW(())
563 OSL_ASSERT(beginIndex
>= 0 && beginIndex
<= getLength());
564 if ( beginIndex
== 0 )
568 rtl_String
* pNew
= 0;
569 rtl_string_newFromStr_WithLength( &pNew
, pData
->buffer
+beginIndex
, getLength()-beginIndex
);
570 return OString( pNew
, (DO_NOT_ACQUIRE
*)0 );
575 Returns a new string that is a substring of this string.
577 The substring begins at the specified beginIndex and contains count
578 characters. It is an error for either beginIndex or count to be negative,
579 or for beginIndex + count to be greater than the length of this string.
581 @param beginIndex the beginning index, inclusive.
582 @param count the number of characters.
583 @return the specified substring.
585 OString
copy( sal_Int32 beginIndex
, sal_Int32 count
) const SAL_THROW(())
587 OSL_ASSERT(beginIndex
>= 0 && beginIndex
<= getLength()
588 && count
>= 0 && count
<= getLength() - beginIndex
);
589 if ( (beginIndex
== 0) && (count
== getLength()) )
593 rtl_String
* pNew
= 0;
594 rtl_string_newFromStr_WithLength( &pNew
, pData
->buffer
+beginIndex
, count
);
595 return OString( pNew
, (DO_NOT_ACQUIRE
*)0 );
600 Concatenates the specified string to the end of this string.
602 @param str the string that is concatenated to the end
604 @return a string that represents the concatenation of this string
605 followed by the string argument.
607 OString
concat( const OString
& str
) const SAL_THROW(())
609 rtl_String
* pNew
= 0;
610 rtl_string_newConcat( &pNew
, pData
, str
.pData
);
611 return OString( pNew
, (DO_NOT_ACQUIRE
*)0 );
614 friend OString
operator+( const OString
& str1
, const OString
& str2
) SAL_THROW(())
616 return str1
.concat( str2
);
620 Returns a new string resulting from replacing n = count characters
621 from position index in this string with newStr.
623 @param index the replacing index in str.
624 The index must be greater or equal as 0 and
625 less or equal as the length of the string.
626 @param count the count of charcters that will replaced
627 The count must be greater or equal as 0 and
628 less or equal as the length of the string minus index.
629 @param newStr the new substring.
630 @return the new string.
632 OString
replaceAt( sal_Int32 index
, sal_Int32 count
, const OString
& newStr
) const SAL_THROW(())
634 rtl_String
* pNew
= 0;
635 rtl_string_newReplaceStrAt( &pNew
, pData
, index
, count
, newStr
.pData
);
636 return OString( pNew
, (DO_NOT_ACQUIRE
*)0 );
640 Returns a new string resulting from replacing all occurrences of
641 oldChar in this string with newChar.
643 If the character oldChar does not occur in the character sequence
644 represented by this object, then the string is assigned with
647 @param oldChar the old character.
648 @param newChar the new character.
649 @return a string derived from this string by replacing every
650 occurrence of oldChar with newChar.
652 OString
replace( sal_Char oldChar
, sal_Char newChar
) const SAL_THROW(())
654 rtl_String
* pNew
= 0;
655 rtl_string_newReplace( &pNew
, pData
, oldChar
, newChar
);
656 return OString( pNew
, (DO_NOT_ACQUIRE
*)0 );
660 Converts from this string all ASCII uppercase characters (65-90)
661 to ASCII lowercase characters (97-122).
663 This function can't be used for language specific conversion.
664 If the string doesn't contain characters which must be converted,
665 then the new string is assigned with str.
667 @return the string, converted to ASCII lowercase.
669 OString
toAsciiLowerCase() const SAL_THROW(())
671 rtl_String
* pNew
= 0;
672 rtl_string_newToAsciiLowerCase( &pNew
, pData
);
673 return OString( pNew
, (DO_NOT_ACQUIRE
*)0 );
677 Converts from this string all ASCII lowercase characters (97-122)
678 to ASCII uppercase characters (65-90).
680 This function can't be used for language specific conversion.
681 If the string doesn't contain characters which must be converted,
682 then the new string is assigned with str.
684 @return the string, converted to ASCII uppercase.
686 OString
toAsciiUpperCase() const SAL_THROW(())
688 rtl_String
* pNew
= 0;
689 rtl_string_newToAsciiUpperCase( &pNew
, pData
);
690 return OString( pNew
, (DO_NOT_ACQUIRE
*)0 );
694 Returns a new string resulting from removing white space from both ends
697 All characters that have codes less than or equal to
698 32 (the space character) are considered to be white space.
699 If the string doesn't contain white spaces at both ends,
700 then the new string is assigned with str.
702 @return the string, with white space removed from the front and end.
704 OString
trim() const SAL_THROW(())
706 rtl_String
* pNew
= 0;
707 rtl_string_newTrim( &pNew
, pData
);
708 return OString( pNew
, (DO_NOT_ACQUIRE
*)0 );
712 Returns a token in the string.
715 sal_Int32 nIndex = 0;
719 OString aToken = aStr.getToken( 0, ';', nIndex );
722 while ( nIndex >= 0 );
724 @param token the number of the token to return.
725 @param cTok the character which seperate the tokens.
726 @param index the position at which the token is searched in the
728 The index must not be greater thanthe length of the
730 This param is set to the position of the
731 next token or to -1, if it is the last token.
732 @return the token; if either token or index is negative, an empty token
733 is returned (and index is set to -1)
735 OString
getToken( sal_Int32 token
, sal_Char cTok
, sal_Int32
& index
) const SAL_THROW(())
737 rtl_String
* pNew
= 0;
738 index
= rtl_string_getToken( &pNew
, pData
, token
, cTok
, index
);
739 return OString( pNew
, (DO_NOT_ACQUIRE
*)0 );
743 Returns the Boolean value from this string.
745 This function can't be used for language specific conversion.
747 @return sal_True, if the string is 1 or "True" in any ASCII case.
748 sal_False in any other case.
750 sal_Bool
toBoolean() const SAL_THROW(())
752 return rtl_str_toBoolean( pData
->buffer
);
756 Returns the first character from this string.
758 @return the first character from this string or 0, if this string
761 sal_Char
toChar() const SAL_THROW(())
763 return pData
->buffer
[0];
767 Returns the int32 value from this string.
769 This function can't be used for language specific conversion.
771 @param radix the radix (between 2 and 36)
772 @return the int32 represented from this string.
773 0 if this string represents no number.
775 sal_Int32
toInt32( sal_Int16 radix
= 10 ) const SAL_THROW(())
777 return rtl_str_toInt32( pData
->buffer
, radix
);
781 Returns the int64 value from this string.
783 This function can't be used for language specific conversion.
785 @param radix the radix (between 2 and 36)
786 @return the int64 represented from this string.
787 0 if this string represents no number.
789 sal_Int64
toInt64( sal_Int16 radix
= 10 ) const SAL_THROW(())
791 return rtl_str_toInt64( pData
->buffer
, radix
);
795 Returns the float value from this string.
797 This function can't be used for language specific conversion.
799 @return the float represented from this string.
800 0.0 if this string represents no number.
802 float toFloat() const SAL_THROW(())
804 return rtl_str_toFloat( pData
->buffer
);
808 Returns the double value from this string.
810 This function can't be used for language specific conversion.
812 @return the double represented from this string.
813 0.0 if this string represents no number.
815 double toDouble() const SAL_THROW(())
817 return rtl_str_toDouble( pData
->buffer
);
821 Returns the string representation of the sal_Bool argument.
823 If the sal_Bool is true, the string "true" is returned.
824 If the sal_Bool is false, the string "false" is returned.
825 This function can't be used for language specific conversion.
828 @return a string with the string representation of the argument.
830 static OString
valueOf( sal_Bool b
) SAL_THROW(())
832 sal_Char aBuf
[RTL_STR_MAX_VALUEOFBOOLEAN
];
833 rtl_String
* pNewData
= 0;
834 rtl_string_newFromStr_WithLength( &pNewData
, aBuf
, rtl_str_valueOfBoolean( aBuf
, b
) );
835 return OString( pNewData
, (DO_NOT_ACQUIRE
*)0 );
839 Returns the string representation of the char argument.
841 @param c a character.
842 @return a string with the string representation of the argument.
844 static OString
valueOf( sal_Char c
) SAL_THROW(())
846 return OString( &c
, 1 );
850 Returns the string representation of the int argument.
852 This function can't be used for language specific conversion.
855 @param radix the radix (between 2 and 36)
856 @return a string with the string representation of the argument.
858 static OString
valueOf( sal_Int32 i
, sal_Int16 radix
= 10 ) SAL_THROW(())
860 sal_Char aBuf
[RTL_STR_MAX_VALUEOFINT32
];
861 rtl_String
* pNewData
= 0;
862 rtl_string_newFromStr_WithLength( &pNewData
, aBuf
, rtl_str_valueOfInt32( aBuf
, i
, radix
) );
863 return OString( pNewData
, (DO_NOT_ACQUIRE
*)0 );
867 Returns the string representation of the long argument.
869 This function can't be used for language specific conversion.
872 @param radix the radix (between 2 and 36)
873 @return a string with the string representation of the argument.
875 static OString
valueOf( sal_Int64 ll
, sal_Int16 radix
= 10 ) SAL_THROW(())
877 sal_Char aBuf
[RTL_STR_MAX_VALUEOFINT64
];
878 rtl_String
* pNewData
= 0;
879 rtl_string_newFromStr_WithLength( &pNewData
, aBuf
, rtl_str_valueOfInt64( aBuf
, ll
, radix
) );
880 return OString( pNewData
, (DO_NOT_ACQUIRE
*)0 );
884 Returns the string representation of the float argument.
886 This function can't be used for language specific conversion.
889 @return a string with the string representation of the argument.
891 static OString
valueOf( float f
) SAL_THROW(())
893 sal_Char aBuf
[RTL_STR_MAX_VALUEOFFLOAT
];
894 rtl_String
* pNewData
= 0;
895 rtl_string_newFromStr_WithLength( &pNewData
, aBuf
, rtl_str_valueOfFloat( aBuf
, f
) );
896 return OString( pNewData
, (DO_NOT_ACQUIRE
*)0 );
900 Returns the string representation of the double argument.
902 This function can't be used for language specific conversion.
905 @return a string with the string representation of the argument.
907 static OString
valueOf( double d
) SAL_THROW(())
909 sal_Char aBuf
[RTL_STR_MAX_VALUEOFDOUBLE
];
910 rtl_String
* pNewData
= 0;
911 rtl_string_newFromStr_WithLength( &pNewData
, aBuf
, rtl_str_valueOfDouble( aBuf
, d
) );
912 return OString( pNewData
, (DO_NOT_ACQUIRE
*)0 );
916 /* ======================================================================= */
918 /** A helper to use OStrings with hash maps.
920 Instances of this class are unary function objects that can be used as
921 hash function arguments to STLPort's hash_map and similar constructs.
925 /** Compute a hash code for a string.
931 a hash code for the string. This hash code should not be stored
932 persistently, as its computation may change in later revisions.
934 size_t operator()( const rtl::OString
& rString
) const
935 { return (size_t)rString
.hashCode(); }
938 /* ======================================================================= */
942 #endif /* __cplusplus */
944 #endif /* _RTL_STRING_HXX_ */