1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #ifndef INCLUDED_RTL_STRING_HXX
21 #define INCLUDED_RTL_STRING_HXX
23 #include <sal/config.h>
30 #include <rtl/textenc.h>
31 #include <rtl/string.h>
32 #include <rtl/stringutils.hxx>
34 #ifdef LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
35 #include <rtl/stringconcat.hxx>
38 #include <sal/log.hxx>
40 // The unittest uses slightly different code to help check that the proper
41 // calls are made. The class is put into a different namespace to make
42 // sure the compiler generates a different (if generating also non-inline)
43 // copy of the function and does not merge them together. The class
44 // is "brought" into the proper rtl namespace by a typedef below.
45 #ifdef RTL_STRING_UNITTEST
46 #define rtl rtlunittest
53 #ifdef RTL_STRING_UNITTEST
55 // helper macro to make functions appear more readable
56 #define RTL_STRING_CONST_FUNCTION rtl_string_unittest_const_literal_function = true;
58 #define RTL_STRING_CONST_FUNCTION
62 /* ======================================================================= */
65 This String class provide base functionality for C++ like 8-Bit
66 character array handling. The advantage of this class is, that it
67 handle all the memory managament for you - and it do it
68 more efficient. If you assign a string to another string, the
69 data of both strings are shared (without any copy operation or
70 memory allocation) as long as you do not change the string. This class
71 stores also the length of the string, so that many operations are
72 faster as the C-str-functions.
74 This class provide only readonly string handling. So you could create
75 a string and you could only query the content from this string.
76 It provide also functionality to change the string, but this results
77 in every case in a new string instance (in the most cases with an
78 memory allocation). You don't have functionality to change the
79 content of the string. If you want change the string content, than
80 you should us the OStringBuffer class, which provide these
81 functionality and avoid to much memory allocation.
83 The design of this class is similar to the string classes in Java
84 and so more people should have fewer understanding problems when they
88 class SAL_WARN_UNUSED SAL_DLLPUBLIC_RTTI OString
96 New string containing no characters.
101 rtl_string_new( &pData
);
105 New string from OString.
107 @param str a OString.
109 OString( const OString
& str
)
112 rtl_string_acquire( pData
);
116 New string from OString data.
118 @param str a OString data.
120 OString( rtl_String
* str
)
123 rtl_string_acquire( pData
);
126 /** New string from OString data without acquiring it. Takeover of ownership.
128 The SAL_NO_ACQUIRE dummy parameter is only there to distinguish this
129 from other constructors.
131 @param str a OString data.
133 inline OString( rtl_String
* str
, __sal_NoAcquire
)
139 New string from a single character.
141 @param value a character.
143 explicit OString( sal_Char value
)
146 rtl_string_newFromStr_WithLength( &pData
, &value
, 1 );
150 New string from a character buffer array.
152 Note: The argument type is always either char* or const char*. The template is
153 used only for technical reasons, as is the second argument.
155 @param value a NULL-terminated character array.
157 template< typename T
>
158 OString( const T
& value
, typename
libreoffice_internal::CharPtrDetector
< T
, libreoffice_internal::Dummy
>::Type
= libreoffice_internal::Dummy() )
161 rtl_string_newFromStr( &pData
, value
);
164 template< typename T
>
165 OString( T
& value
, typename
libreoffice_internal::NonConstCharArrayDetector
< T
, libreoffice_internal::Dummy
>::Type
= libreoffice_internal::Dummy() )
168 rtl_string_newFromStr( &pData
, value
);
172 New string from a string literal.
174 If there are any embedded \0's in the string literal, the result is undefined.
175 Use the overload that explicitly accepts length.
177 @since LibreOffice 3.6
179 @param literal a string literal
181 template< typename T
>
182 OString( T
& literal
, typename
libreoffice_internal::ConstCharArrayDetector
< T
, libreoffice_internal::Dummy
>::Type
= libreoffice_internal::Dummy() )
184 assert( strlen( literal
) == libreoffice_internal::ConstCharArrayDetector
< T
>::size
- 1 );
186 if( libreoffice_internal::ConstCharArrayDetector
< T
, void >::size
- 1 == 0 ) // empty string
187 rtl_string_new( &pData
);
189 rtl_string_newFromLiteral( &pData
, literal
, libreoffice_internal::ConstCharArrayDetector
< T
, void >::size
- 1, 0 );
190 #ifdef RTL_STRING_UNITTEST
191 rtl_string_unittest_const_literal
= true;
196 New string from a character buffer array.
198 @param value a character array.
199 @param length the number of character which should be copied.
200 The character array length must be greater or
201 equal than this value.
203 OString( const sal_Char
* value
, sal_Int32 length
)
206 rtl_string_newFromStr_WithLength( &pData
, value
, length
);
210 New string from a Unicode character buffer array.
212 @param value a Unicode character array.
213 @param length the number of character which should be converted.
214 The Unicode character array length must be
215 greater or equal than this value.
216 @param encoding the text encoding in which the Unicode character
217 sequence should be converted.
218 @param convertFlags flags which controls the conversion.
219 see RTL_UNICODETOTEXT_FLAGS_...
221 @exception std::bad_alloc is thrown if an out-of-memory condition occurs
223 OString( const sal_Unicode
* value
, sal_Int32 length
,
224 rtl_TextEncoding encoding
,
225 sal_uInt32 convertFlags
= OUSTRING_TO_OSTRING_CVTFLAGS
)
228 rtl_uString2String( &pData
, value
, length
, encoding
, convertFlags
);
230 throw std::bad_alloc();
234 #ifdef LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
239 template< typename T1
, typename T2
>
240 OString( const OStringConcat
< T1
, T2
>& c
)
242 const sal_Int32 l
= c
.length();
243 pData
= rtl_string_alloc( l
);
246 char* end
= c
.addData( pData
->buffer
);
247 pData
->length
= end
- pData
->buffer
;
254 Release the string data.
258 rtl_string_release( pData
);
264 @param str a OString.
266 OString
& operator=( const OString
& str
)
268 rtl_string_assign( &pData
, str
.pData
);
274 This function accepts an ASCII string literal as its argument.
275 @since LibreOffice 3.6
277 template< typename T
>
278 typename
libreoffice_internal::ConstCharArrayDetector
< T
, OString
& >::Type
operator=( T
& literal
)
280 RTL_STRING_CONST_FUNCTION
281 assert( strlen( literal
) == libreoffice_internal::ConstCharArrayDetector
< T
>::size
- 1 );
282 if( libreoffice_internal::ConstCharArrayDetector
< T
, void >::size
- 1 == 0 ) // empty string
283 rtl_string_new( &pData
);
285 rtl_string_newFromLiteral( &pData
, literal
, libreoffice_internal::ConstCharArrayDetector
< T
, void >::size
- 1, 0 );
290 Append a string to this string.
292 @param str a OString.
294 OString
& operator+=( const OString
& str
)
296 rtl_string_newConcat( &pData
, pData
, str
.pData
);
300 #ifdef LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
305 template< typename T1
, typename T2
>
306 OString
& operator+=( const OStringConcat
< T1
, T2
>& c
)
308 const int l
= c
.length();
311 rtl_string_ensureCapacity( &pData
, pData
->length
+ l
);
312 char* end
= c
.addData( pData
->buffer
+ pData
->length
);
314 pData
->length
= end
- pData
->buffer
;
320 Clears the string, i.e, makes a zero-character string
321 @since LibreOffice 4.4
325 rtl_string_new( &pData
);
329 Returns the length of this string.
331 The length is equal to the number of characters in this string.
333 @return the length of the sequence of characters represented by this
336 sal_Int32
getLength() const { return pData
->length
; }
339 Checks if a string is empty.
341 @return true if the string is empty;
344 @since LibreOffice 3.4
348 return pData
->length
== 0;
352 Returns a pointer to the characters of this string.
354 <p>The returned pointer is guaranteed to point to a null-terminated byte
355 string. But note that this string object may contain embedded null
356 characters, which will thus also be embedded in the returned
357 null-terminated byte string.</p>
359 @return a pointer to a null-terminated byte string representing the
360 characters of this string object.
362 const sal_Char
* getStr() const { return pData
->buffer
; }
365 Access to individual characters.
367 @param index must be non-negative and less than length.
369 @return the character at the given index.
371 @since LibreOffice 3.5
373 sal_Char
operator [](sal_Int32 index
) const {
374 // silence spurious -Werror=strict-overflow warnings from GCC 4.8.2
375 assert(index
>= 0 && static_cast<sal_uInt32
>(index
) < static_cast<sal_uInt32
>(getLength()));
376 return getStr()[index
];
380 Compares two strings.
382 The comparison is based on the numeric value of each character in
383 the strings and return a value indicating their relationship.
384 This function can't be used for language specific sorting.
386 @param str the object to be compared.
387 @return 0 - if both strings are equal
388 < 0 - if this string is less than the string argument
389 > 0 - if this string is greater than the string argument
391 sal_Int32
compareTo( const OString
& str
) const
393 return rtl_str_compare_WithLength( pData
->buffer
, pData
->length
,
394 str
.pData
->buffer
, str
.pData
->length
);
398 Compares two strings with an maximum count of characters.
400 The comparison is based on the numeric value of each character in
401 the strings and return a value indicating their relationship.
402 This function can't be used for language specific sorting.
404 @param rObj the object to be compared.
405 @param maxLength the maximum count of characters to be compared.
406 @return 0 - if both strings are equal
407 < 0 - if this string is less than the string argument
408 > 0 - if this string is greater than the string argument
410 sal_Int32
compareTo( const OString
& rObj
, sal_Int32 maxLength
) const
412 return rtl_str_shortenedCompare_WithLength( pData
->buffer
, pData
->length
,
413 rObj
.pData
->buffer
, rObj
.pData
->length
, maxLength
);
417 Compares two strings in reverse order.
419 The comparison is based on the numeric value of each character in
420 the strings and return a value indicating their relationship.
421 This function can't be used for language specific sorting.
423 @param str the object to be compared.
424 @return 0 - if both strings are equal
425 < 0 - if this string is less than the string argument
426 > 0 - if this string is greater than the string argument
428 sal_Int32
reverseCompareTo( const OString
& str
) const
430 return rtl_str_reverseCompare_WithLength( pData
->buffer
, pData
->length
,
431 str
.pData
->buffer
, str
.pData
->length
);
435 Perform a comparison of two strings.
437 The result is true if and only if second string
438 represents the same sequence of characters as the first string.
439 This function can't be used for language specific comparison.
441 @param str the object to be compared.
442 @return true if the strings are equal;
445 bool equals( const OString
& str
) const
447 if ( pData
->length
!= str
.pData
->length
)
449 if ( pData
== str
.pData
)
451 return rtl_str_reverseCompare_WithLength( pData
->buffer
, pData
->length
,
452 str
.pData
->buffer
, str
.pData
->length
) == 0;
456 Perform a comparison of two strings.
458 The result is true if and only if second string
459 represents the same sequence of characters as the first string.
460 The ASCII string must be NULL-terminated and must be greater or
462 This function can't be used for language specific comparison.
465 @param value a character array.
466 @param length the length of the character array.
467 @return true if the strings are equal;
470 bool equalsL( const sal_Char
* value
, sal_Int32 length
) const
472 if ( pData
->length
!= length
)
475 return rtl_str_reverseCompare_WithLength( pData
->buffer
, pData
->length
,
476 value
, length
) == 0;
480 Perform a ASCII lowercase comparison of two strings.
482 The result is true if and only if second string
483 represents the same sequence of characters as the first string,
485 Character values between 65 and 90 (ASCII A-Z) are interpreted as
486 values between 97 and 122 (ASCII a-z).
487 This function can't be used for language specific comparison.
489 @param str the object to be compared.
490 @return true if the strings are equal;
493 bool equalsIgnoreAsciiCase( const OString
& str
) const
495 if ( pData
->length
!= str
.pData
->length
)
497 if ( pData
== str
.pData
)
499 return rtl_str_compareIgnoreAsciiCase_WithLength( pData
->buffer
, pData
->length
,
500 str
.pData
->buffer
, str
.pData
->length
) == 0;
504 Perform a ASCII lowercase comparison of two strings.
506 The result is true if and only if second string
507 represents the same sequence of characters as the first string,
509 Character values between 65 and 90 (ASCII A-Z) are interpreted as
510 values between 97 and 122 (ASCII a-z).
511 Since this method is optimized for performance, the ASCII character
512 values are not converted in any way. The caller has to make sure that
513 all ASCII characters are in the allowed range between 0 and
514 127. The ASCII string must be NULL-terminated.
515 This function can't be used for language specific comparison.
517 Note: The argument type is always either char* or const char*, the return type is bool.
518 The template is used only for technical reasons.
520 @param asciiStr the 8-Bit ASCII character string to be compared.
521 @return true if the strings are equal;
524 template< typename T
>
525 typename
libreoffice_internal::CharPtrDetector
< T
, bool >::Type
equalsIgnoreAsciiCase( const T
& asciiStr
) const
527 return rtl_str_compareIgnoreAsciiCase( pData
->buffer
, asciiStr
) == 0;
530 template< typename T
>
531 typename
libreoffice_internal::NonConstCharArrayDetector
< T
, bool >::Type
equalsIgnoreAsciiCase( T
& asciiStr
) const
533 return rtl_str_compareIgnoreAsciiCase( pData
->buffer
, asciiStr
) == 0;
538 This function accepts an ASCII string literal as its argument.
539 @since LibreOffice 3.6
541 template< typename T
>
542 typename
libreoffice_internal::ConstCharArrayDetector
< T
, bool >::Type
equalsIgnoreAsciiCase( T
& literal
) const
544 RTL_STRING_CONST_FUNCTION
545 assert( strlen( literal
) == libreoffice_internal::ConstCharArrayDetector
< T
>::size
- 1 );
546 if ( pData
->length
!= libreoffice_internal::ConstCharArrayDetector
< T
, void >::size
- 1 )
548 return rtl_str_compareIgnoreAsciiCase_WithLength( pData
->buffer
, pData
->length
,
549 literal
, libreoffice_internal::ConstCharArrayDetector
< T
, void >::size
- 1 ) == 0;
553 Perform a ASCII lowercase comparison of two strings.
555 The result is true if and only if second string
556 represents the same sequence of characters as the first string,
558 Character values between 65 and 90 (ASCII A-Z) are interpreted as
559 values between 97 and 122 (ASCII a-z).
560 Since this method is optimized for performance, the ASCII character
561 values are not converted in any way. The caller has to make sure that
562 all ASCII characters are in the allowed range between 0 and
563 127. The ASCII string must be greater or equal in length as asciiStrLength.
564 This function can't be used for language specific comparison.
566 @param asciiStr the 8-Bit ASCII character string to be compared.
567 @param asciiStrLength the length of the ascii string
568 @return true if the strings are equal;
571 bool equalsIgnoreAsciiCaseL( const sal_Char
* asciiStr
, sal_Int32 asciiStrLength
) const
573 if ( pData
->length
!= asciiStrLength
)
576 return rtl_str_compareIgnoreAsciiCase_WithLength( pData
->buffer
, pData
->length
,
577 asciiStr
, asciiStrLength
) == 0;
581 Match against a substring appearing in this string.
583 The result is true if and only if the second string appears as a substring
584 of this string, at the given position.
585 This function can't be used for language specific comparison.
587 @param str the object (substring) to be compared.
588 @param fromIndex the index to start the comparion from.
589 The index must be greater or equal than 0
590 and less or equal as the string length.
591 @return true if str match with the characters in the string
592 at the given position;
595 bool match( const OString
& str
, sal_Int32 fromIndex
= 0 ) const
597 return rtl_str_shortenedCompare_WithLength( pData
->buffer
+fromIndex
, pData
->length
-fromIndex
,
598 str
.pData
->buffer
, str
.pData
->length
, str
.pData
->length
) == 0;
603 This function accepts an ASCII string literal as its argument.
604 @since LibreOffice 3.6
606 template< typename T
>
607 typename
libreoffice_internal::ConstCharArrayDetector
< T
, bool >::Type
match( T
& literal
, sal_Int32 fromIndex
= 0 ) const
609 RTL_STRING_CONST_FUNCTION
610 assert( strlen( literal
) == libreoffice_internal::ConstCharArrayDetector
< T
>::size
- 1 );
611 return rtl_str_shortenedCompare_WithLength(
612 pData
->buffer
+ fromIndex
, pData
->length
- fromIndex
,
613 literal
, libreoffice_internal::ConstCharArrayDetector
< T
, void >::size
- 1, libreoffice_internal::ConstCharArrayDetector
< T
, void >::size
- 1) == 0;
617 Match against a substring appearing in this string.
619 @param str the substring to be compared; must not be null and must point
620 to memory of at least strLength bytes
622 @param strLength the length of the substring; must be non-negative
624 @param fromIndex the index into this string to start the comparison at;
625 must be non-negative and not greater than this string's length
627 @return true if and only if the given str is contained as a substring of
628 this string at the given fromIndex
630 @since LibreOffice 3.6
633 char const * str
, sal_Int32 strLength
, sal_Int32 fromIndex
= 0)
636 return rtl_str_shortenedCompare_WithLength(
637 pData
->buffer
+ fromIndex
, pData
->length
- fromIndex
,
638 str
, strLength
, strLength
) == 0;
641 // This overload is left undefined, to detect calls of matchL that
642 // erroneously use RTL_CONSTASCII_USTRINGPARAM instead of
643 // RTL_CONSTASCII_STRINGPARAM (but would lead to ambiguities on 32 bit
645 #if SAL_TYPES_SIZEOFLONG == 8
646 void matchL(char const *, sal_Int32
, rtl_TextEncoding
) const;
650 Match against a substring appearing in this string, ignoring the case of
653 The result is true if and only if the second string appears as a substring
654 of this string, at the given position.
655 Character values between 65 and 90 (ASCII A-Z) are interpreted as
656 values between 97 and 122 (ASCII a-z).
657 This function can't be used for language specific comparison.
659 @param str the object (substring) to be compared.
660 @param fromIndex the index to start the comparion from.
661 The index must be greater or equal than 0
662 and less or equal as the string length.
663 @return true if str match with the characters in the string
664 at the given position;
667 bool matchIgnoreAsciiCase( const OString
& str
, sal_Int32 fromIndex
= 0 ) const
669 return rtl_str_shortenedCompareIgnoreAsciiCase_WithLength( pData
->buffer
+fromIndex
, pData
->length
-fromIndex
,
670 str
.pData
->buffer
, str
.pData
->length
,
671 str
.pData
->length
) == 0;
676 This function accepts an ASCII string literal as its argument.
677 @since LibreOffice 3.6
679 template< typename T
>
680 typename
libreoffice_internal::ConstCharArrayDetector
< T
, bool >::Type
matchIgnoreAsciiCase( T
& literal
, sal_Int32 fromIndex
= 0 ) const
682 RTL_STRING_CONST_FUNCTION
683 assert( strlen( literal
) == libreoffice_internal::ConstCharArrayDetector
< T
>::size
- 1 );
684 return rtl_str_shortenedCompareIgnoreAsciiCase_WithLength( pData
->buffer
+fromIndex
, pData
->length
-fromIndex
,
685 literal
, libreoffice_internal::ConstCharArrayDetector
< T
, void >::size
- 1, libreoffice_internal::ConstCharArrayDetector
< T
, void >::size
- 1 ) == 0;
689 Check whether this string starts with a given substring.
691 @param str the substring to be compared
693 @param rest if non-null, and this function returns true, then assign a
694 copy of the remainder of this string to *rest. Available since
697 @return true if and only if the given str appears as a substring at the
700 @since LibreOffice 4.0
702 bool startsWith(OString
const & str
, OString
* rest
= 0) const {
703 bool b
= match(str
, 0);
704 if (b
&& rest
!= 0) {
705 *rest
= copy(str
.getLength());
712 This function accepts an ASCII string literal as its argument.
713 @since LibreOffice 4.0
715 template< typename T
>
716 typename
libreoffice_internal::ConstCharArrayDetector
< T
, bool >::Type
startsWith(
717 T
& literal
, OString
* rest
= 0) const
719 RTL_STRING_CONST_FUNCTION
720 bool b
= match(literal
, 0);
721 if (b
&& rest
!= 0) {
722 *rest
= copy(libreoffice_internal::ConstCharArrayDetector
< T
, void >::size
- 1);
728 Check whether this string ends with a given substring.
730 @param str the substring to be compared
732 @param rest if non-null, and this function returns true, then assign a
733 copy of the remainder of this string to *rest. Available since
736 @return true if and only if the given str appears as a substring at the
739 @since LibreOffice 3.6
741 bool endsWith(OString
const & str
, OString
* rest
= 0) const {
742 bool b
= str
.getLength() <= getLength()
743 && match(str
, getLength() - str
.getLength());
744 if (b
&& rest
!= 0) {
745 *rest
= copy(0, getLength() - str
.getLength());
752 This function accepts an ASCII string literal as its argument.
753 @since LibreOffice 3.6
755 template< typename T
>
756 typename
libreoffice_internal::ConstCharArrayDetector
< T
, bool >::Type
endsWith(
757 T
& literal
, OString
* rest
= 0) const
759 RTL_STRING_CONST_FUNCTION
760 assert( strlen( literal
) == libreoffice_internal::ConstCharArrayDetector
< T
>::size
- 1 );
761 bool b
= libreoffice_internal::ConstCharArrayDetector
< T
, void >::size
- 1 <= getLength()
762 && match(literal
, getLength() - ( libreoffice_internal::ConstCharArrayDetector
< T
, void >::size
- 1 ));
763 if (b
&& rest
!= 0) {
767 - (libreoffice_internal::ConstCharArrayDetector
< T
, void >::size
- 1)));
773 Check whether this string ends with a given substring.
775 @param str the substring to be compared; must not be null and must point
776 to memory of at least strLength bytes
778 @param strLength the length of the substring; must be non-negative
780 @return true if and only if the given str appears as a substring at the
783 @since LibreOffice 3.6
785 bool endsWithL(char const * str
, sal_Int32 strLength
) const {
786 return strLength
<= getLength()
787 && matchL(str
, strLength
, getLength() - strLength
);
790 friend bool operator == ( const OString
& rStr1
, const OString
& rStr2
)
791 { return rStr1
.equals(rStr2
); }
792 friend bool operator != ( const OString
& rStr1
, const OString
& rStr2
)
793 { return !(operator == ( rStr1
, rStr2
)); }
794 friend bool operator < ( const OString
& rStr1
, const OString
& rStr2
)
795 { return rStr1
.compareTo( rStr2
) < 0; }
796 friend bool operator > ( const OString
& rStr1
, const OString
& rStr2
)
797 { return rStr1
.compareTo( rStr2
) > 0; }
798 friend bool operator <= ( const OString
& rStr1
, const OString
& rStr2
)
799 { return rStr1
.compareTo( rStr2
) <= 0; }
800 friend bool operator >= ( const OString
& rStr1
, const OString
& rStr2
)
801 { return rStr1
.compareTo( rStr2
) >= 0; }
803 template< typename T
>
804 friend typename
libreoffice_internal::CharPtrDetector
< T
, bool >::Type
operator==( const OString
& rStr1
, const T
& value
)
806 return rStr1
.compareTo( value
) == 0;
809 template< typename T
>
810 friend typename
libreoffice_internal::NonConstCharArrayDetector
< T
, bool >::Type
operator==( const OString
& rStr1
, T
& value
)
812 return rStr1
.compareTo( value
) == 0;
815 template< typename T
>
816 friend typename
libreoffice_internal::CharPtrDetector
< T
, bool >::Type
operator==( const T
& value
, const OString
& rStr2
)
818 return rStr2
.compareTo( value
) == 0;
821 template< typename T
>
822 friend typename
libreoffice_internal::NonConstCharArrayDetector
< T
, bool >::Type
operator==( T
& value
, const OString
& rStr2
)
824 return rStr2
.compareTo( value
) == 0;
829 This function accepts an ASCII string literal as its argument.
830 @since LibreOffice 3.6
832 template< typename T
>
833 friend typename
libreoffice_internal::ConstCharArrayDetector
< T
, bool >::Type
operator==( const OString
& rStr
, T
& literal
)
835 RTL_STRING_CONST_FUNCTION
836 assert( strlen( literal
) == libreoffice_internal::ConstCharArrayDetector
< T
>::size
- 1 );
837 return rStr
.getLength() == libreoffice_internal::ConstCharArrayDetector
< T
, void >::size
- 1
838 && rtl_str_compare_WithLength( rStr
.pData
->buffer
, rStr
.pData
->length
, literal
,
839 libreoffice_internal::ConstCharArrayDetector
< T
, void >::size
- 1 ) == 0;
844 This function accepts an ASCII string literal as its argument.
845 @since LibreOffice 3.6
847 template< typename T
>
848 friend typename
libreoffice_internal::ConstCharArrayDetector
< T
, bool >::Type
operator==( T
& literal
, const OString
& rStr
)
850 RTL_STRING_CONST_FUNCTION
851 assert( strlen( literal
) == libreoffice_internal::ConstCharArrayDetector
< T
>::size
- 1 );
852 return rStr
.getLength() == libreoffice_internal::ConstCharArrayDetector
< T
, void >::size
- 1
853 && rtl_str_compare_WithLength( rStr
.pData
->buffer
, rStr
.pData
->length
, literal
,
854 libreoffice_internal::ConstCharArrayDetector
< T
, void >::size
- 1 ) == 0;
857 template< typename T
>
858 friend typename
libreoffice_internal::CharPtrDetector
< T
, bool >::Type
operator!=( const OString
& rStr1
, const T
& value
)
860 return !(operator == ( rStr1
, value
));
863 template< typename T
>
864 friend typename
libreoffice_internal::NonConstCharArrayDetector
< T
, bool >::Type
operator!=( const OString
& rStr1
, T
& value
)
866 return !(operator == ( rStr1
, value
));
869 template< typename T
>
870 friend typename
libreoffice_internal::CharPtrDetector
< T
, bool >::Type
operator!=( const T
& value
, const OString
& rStr2
)
872 return !(operator == ( value
, rStr2
));
875 template< typename T
>
876 friend typename
libreoffice_internal::NonConstCharArrayDetector
< T
, bool >::Type
operator!=( T
& value
, const OString
& rStr2
)
878 return !(operator == ( value
, rStr2
));
883 This function accepts an ASCII string literal as its argument.
884 @since LibreOffice 3.6
886 template< typename T
>
887 friend typename
libreoffice_internal::ConstCharArrayDetector
< T
, bool >::Type
operator!=( const OString
& rStr
, T
& literal
)
889 return !( rStr
== literal
);
894 This function accepts an ASCII string literal as its argument.
895 @since LibreOffice 3.6
897 template< typename T
>
898 friend typename
libreoffice_internal::ConstCharArrayDetector
< T
, bool >::Type
operator!=( T
& literal
, const OString
& rStr
)
900 return !( literal
== rStr
);
904 Returns a hashcode for this string.
906 @return a hash code value for this object.
908 @see rtl::OStringHash for convenient use of std::unordered_map
910 sal_Int32
hashCode() const
912 return rtl_str_hashCode_WithLength( pData
->buffer
, pData
->length
);
916 Returns the index within this string of the first occurrence of the
917 specified character, starting the search at the specified index.
919 @param ch character to be located.
920 @param fromIndex the index to start the search from.
921 The index must be greater or equal than 0
922 and less or equal as the string length.
923 @return the index of the first occurrence of the character in the
924 character sequence represented by this string that is
925 greater than or equal to fromIndex, or
926 -1 if the character does not occur.
928 sal_Int32
indexOf( sal_Char ch
, sal_Int32 fromIndex
= 0 ) const
930 sal_Int32 ret
= rtl_str_indexOfChar_WithLength( pData
->buffer
+fromIndex
, pData
->length
-fromIndex
, ch
);
931 return (ret
< 0 ? ret
: ret
+fromIndex
);
935 Returns the index within this string of the last occurrence of the
936 specified character, searching backward starting at the end.
938 @param ch character to be located.
939 @return the index of the last occurrence of the character in the
940 character sequence represented by this string, or
941 -1 if the character does not occur.
943 sal_Int32
lastIndexOf( sal_Char ch
) const
945 return rtl_str_lastIndexOfChar_WithLength( pData
->buffer
, pData
->length
, ch
);
949 Returns the index within this string of the last occurrence of the
950 specified character, searching backward starting before the specified
953 @param ch character to be located.
954 @param fromIndex the index before which to start the search.
955 @return the index of the last occurrence of the character in the
956 character sequence represented by this string that
957 is less than fromIndex, or -1
958 if the character does not occur before that point.
960 sal_Int32
lastIndexOf( sal_Char ch
, sal_Int32 fromIndex
) const
962 return rtl_str_lastIndexOfChar_WithLength( pData
->buffer
, fromIndex
, ch
);
966 Returns the index within this string of the first occurrence of the
967 specified substring, starting at the specified index.
969 If str doesn't include any character, always -1 is
970 returned. This is also the case, if both strings are empty.
972 @param str the substring to search for.
973 @param fromIndex the index to start the search from.
974 @return If the string argument occurs one or more times as a substring
975 within this string at the starting index, then the index
976 of the first character of the first such substring is
977 returned. If it does not occur as a substring starting
978 at fromIndex or beyond, -1 is returned.
980 sal_Int32
indexOf( const OString
& str
, sal_Int32 fromIndex
= 0 ) const
982 sal_Int32 ret
= rtl_str_indexOfStr_WithLength( pData
->buffer
+fromIndex
, pData
->length
-fromIndex
,
983 str
.pData
->buffer
, str
.pData
->length
);
984 return (ret
< 0 ? ret
: ret
+fromIndex
);
989 This function accepts an ASCII string literal as its argument.
990 @since LibreOffice 3.6
992 template< typename T
>
993 typename
libreoffice_internal::ConstCharArrayDetector
< T
, sal_Int32
>::Type
indexOf( T
& literal
, sal_Int32 fromIndex
= 0 ) const
995 RTL_STRING_CONST_FUNCTION
996 assert( strlen( literal
) == libreoffice_internal::ConstCharArrayDetector
< T
>::size
- 1 );
997 sal_Int32 n
= rtl_str_indexOfStr_WithLength(
998 pData
->buffer
+ fromIndex
, pData
->length
- fromIndex
, literal
, libreoffice_internal::ConstCharArrayDetector
< T
, void >::size
- 1);
999 return n
< 0 ? n
: n
+ fromIndex
;
1003 Returns the index within this string of the first occurrence of the
1004 specified substring, starting at the specified index.
1006 If str doesn't include any character, always -1 is
1007 returned. This is also the case, if both strings are empty.
1009 @param str the substring to search for.
1010 @param len the length of the substring.
1011 @param fromIndex the index to start the search from.
1012 @return If the string argument occurs one or more times as a substring
1013 within this string at the starting index, then the index
1014 of the first character of the first such substring is
1015 returned. If it does not occur as a substring starting
1016 at fromIndex or beyond, -1 is returned.
1018 @since LibreOffice 3.6
1020 sal_Int32
indexOfL(char const * str
, sal_Int32 len
, sal_Int32 fromIndex
= 0)
1023 sal_Int32 n
= rtl_str_indexOfStr_WithLength(
1024 pData
->buffer
+ fromIndex
, pData
->length
- fromIndex
, str
, len
);
1025 return n
< 0 ? n
: n
+ fromIndex
;
1028 // This overload is left undefined, to detect calls of indexOfL that
1029 // erroneously use RTL_CONSTASCII_USTRINGPARAM instead of
1030 // RTL_CONSTASCII_STRINGPARAM (but would lead to ambiguities on 32 bit
1032 #if SAL_TYPES_SIZEOFLONG == 8
1033 void indexOfL(char const *, sal_Int32
, rtl_TextEncoding
) const;
1037 Returns the index within this string of the last occurrence of
1038 the specified substring, searching backward starting at the end.
1040 The returned index indicates the starting index of the substring
1042 If str doesn't include any character, always -1 is
1043 returned. This is also the case, if both strings are empty.
1045 @param str the substring to search for.
1046 @return If the string argument occurs one or more times as a substring
1047 within this string, then the index of the first character of
1048 the last such substring is returned. If it does not occur as
1049 a substring, -1 is returned.
1051 sal_Int32
lastIndexOf( const OString
& str
) const
1053 return rtl_str_lastIndexOfStr_WithLength( pData
->buffer
, pData
->length
,
1054 str
.pData
->buffer
, str
.pData
->length
);
1058 Returns the index within this string of the last occurrence of
1059 the specified substring, searching backward starting before the specified
1062 The returned index indicates the starting index of the substring
1064 If str doesn't include any character, always -1 is
1065 returned. This is also the case, if both strings are empty.
1067 @param str the substring to search for.
1068 @param fromIndex the index before which to start the search.
1069 @return If the string argument occurs one or more times as a substring
1070 within this string before the starting index, then the index
1071 of the first character of the last such substring is
1072 returned. Otherwise, -1 is returned.
1074 sal_Int32
lastIndexOf( const OString
& str
, sal_Int32 fromIndex
) const
1076 return rtl_str_lastIndexOfStr_WithLength( pData
->buffer
, fromIndex
,
1077 str
.pData
->buffer
, str
.pData
->length
);
1081 Returns a new string that is a substring of this string.
1083 The substring begins at the specified beginIndex. If
1084 beginIndex is negative or be greater than the length of
1085 this string, behaviour is undefined.
1087 @param beginIndex the beginning index, inclusive.
1088 @return the specified substring.
1090 SAL_WARN_UNUSED_RESULT OString
copy( sal_Int32 beginIndex
) const
1092 rtl_String
*pNew
= 0;
1093 rtl_string_newFromSubString( &pNew
, pData
, beginIndex
, getLength() - beginIndex
);
1094 return OString( pNew
, SAL_NO_ACQUIRE
);
1098 Returns a new string that is a substring of this string.
1100 The substring begins at the specified beginIndex and contains count
1101 characters. If either beginIndex or count are negative,
1102 or beginIndex + count are greater than the length of this string
1103 then behaviour is undefined.
1105 @param beginIndex the beginning index, inclusive.
1106 @param count the number of characters.
1107 @return the specified substring.
1109 SAL_WARN_UNUSED_RESULT OString
copy( sal_Int32 beginIndex
, sal_Int32 count
) const
1111 rtl_String
*pNew
= 0;
1112 rtl_string_newFromSubString( &pNew
, pData
, beginIndex
, count
);
1113 return OString( pNew
, SAL_NO_ACQUIRE
);
1117 Concatenates the specified string to the end of this string.
1119 @param str the string that is concatenated to the end
1121 @return a string that represents the concatenation of this string
1122 followed by the string argument.
1124 SAL_WARN_UNUSED_RESULT OString
concat( const OString
& str
) const
1126 rtl_String
* pNew
= 0;
1127 rtl_string_newConcat( &pNew
, pData
, str
.pData
);
1128 return OString( pNew
, SAL_NO_ACQUIRE
);
1131 #ifndef LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
1132 friend OString
operator+( const OString
& str1
, const OString
& str2
)
1134 return str1
.concat( str2
);
1139 Returns a new string resulting from replacing n = count characters
1140 from position index in this string with newStr.
1142 @param index the replacing index in str.
1143 The index must be greater or equal as 0 and
1144 less or equal as the length of the string.
1145 @param count the count of characters that will replaced
1146 The count must be greater or equal as 0 and
1147 less or equal as the length of the string minus index.
1148 @param newStr the new substring.
1149 @return the new string.
1151 SAL_WARN_UNUSED_RESULT OString
replaceAt( sal_Int32 index
, sal_Int32 count
, const OString
& newStr
) const
1153 rtl_String
* pNew
= 0;
1154 rtl_string_newReplaceStrAt( &pNew
, pData
, index
, count
, newStr
.pData
);
1155 return OString( pNew
, SAL_NO_ACQUIRE
);
1159 Returns a new string resulting from replacing all occurrences of
1160 oldChar in this string with newChar.
1162 If the character oldChar does not occur in the character sequence
1163 represented by this object, then the string is assigned with
1166 @param oldChar the old character.
1167 @param newChar the new character.
1168 @return a string derived from this string by replacing every
1169 occurrence of oldChar with newChar.
1171 SAL_WARN_UNUSED_RESULT OString
replace( sal_Char oldChar
, sal_Char newChar
) const
1173 rtl_String
* pNew
= 0;
1174 rtl_string_newReplace( &pNew
, pData
, oldChar
, newChar
);
1175 return OString( pNew
, SAL_NO_ACQUIRE
);
1179 Returns a new string resulting from replacing the first occurrence of a
1180 given substring with another substring.
1182 @param from the substring to be replaced
1184 @param to the replacing substring
1186 @param[in,out] index pointer to a start index; if the pointer is
1187 non-null: upon entry to the function, its value is the index into the this
1188 string at which to start searching for the \p from substring, the value
1189 must be non-negative and not greater than this string's length; upon exit
1190 from the function its value is the index into this string at which the
1191 replacement took place or -1 if no replacement took place; if the pointer
1192 is null, searching always starts at index 0
1194 @since LibreOffice 3.6
1196 SAL_WARN_UNUSED_RESULT OString
replaceFirst(
1197 OString
const & from
, OString
const & to
, sal_Int32
* index
= 0) const
1201 rtl_string_newReplaceFirst(
1202 &s
, pData
, from
.pData
->buffer
, from
.pData
->length
,
1203 to
.pData
->buffer
, to
.pData
->length
, index
== 0 ? &i
: index
);
1204 return OString(s
, SAL_NO_ACQUIRE
);
1208 Returns a new string resulting from replacing all occurrences of a given
1209 substring with another substring.
1211 Replacing subsequent occurrences picks up only after a given replacement.
1212 That is, replacing from "xa" to "xx" in "xaa" results in "xxa", not "xxx".
1214 @param from the substring to be replaced
1216 @param to the replacing substring
1218 @since LibreOffice 3.6
1220 SAL_WARN_UNUSED_RESULT OString
replaceAll(OString
const & from
, OString
const & to
) const {
1222 rtl_string_newReplaceAll(
1223 &s
, pData
, from
.pData
->buffer
, from
.pData
->length
,
1224 to
.pData
->buffer
, to
.pData
->length
);
1225 return OString(s
, SAL_NO_ACQUIRE
);
1229 Converts from this string all ASCII uppercase characters (65-90)
1230 to ASCII lowercase characters (97-122).
1232 This function can't be used for language specific conversion.
1233 If the string doesn't contain characters which must be converted,
1234 then the new string is assigned with str.
1236 @return the string, converted to ASCII lowercase.
1238 SAL_WARN_UNUSED_RESULT OString
toAsciiLowerCase() const
1240 rtl_String
* pNew
= 0;
1241 rtl_string_newToAsciiLowerCase( &pNew
, pData
);
1242 return OString( pNew
, SAL_NO_ACQUIRE
);
1246 Converts from this string all ASCII lowercase characters (97-122)
1247 to ASCII uppercase characters (65-90).
1249 This function can't be used for language specific conversion.
1250 If the string doesn't contain characters which must be converted,
1251 then the new string is assigned with str.
1253 @return the string, converted to ASCII uppercase.
1255 SAL_WARN_UNUSED_RESULT OString
toAsciiUpperCase() const
1257 rtl_String
* pNew
= 0;
1258 rtl_string_newToAsciiUpperCase( &pNew
, pData
);
1259 return OString( pNew
, SAL_NO_ACQUIRE
);
1263 Returns a new string resulting from removing white space from both ends
1266 All characters that have codes less than or equal to
1267 32 (the space character) are considered to be white space.
1268 If the string doesn't contain white spaces at both ends,
1269 then the new string is assigned with str.
1271 @return the string, with white space removed from the front and end.
1273 SAL_WARN_UNUSED_RESULT OString
trim() const
1275 rtl_String
* pNew
= 0;
1276 rtl_string_newTrim( &pNew
, pData
);
1277 return OString( pNew
, SAL_NO_ACQUIRE
);
1281 Returns a token in the string.
1284 sal_Int32 nIndex = 0;
1288 OString aToken = aStr.getToken( 0, ';', nIndex );
1291 while ( nIndex >= 0 );
1293 @param token the number of the token to return.
1294 @param cTok the character which separate the tokens.
1295 @param index the position at which the token is searched in the
1297 The index must not be greater thanthe length of the
1299 This param is set to the position of the
1300 next token or to -1, if it is the last token.
1301 @return the token; if either token or index is negative, an empty token
1302 is returned (and index is set to -1)
1304 OString
getToken( sal_Int32 token
, sal_Char cTok
, sal_Int32
& index
) const
1306 rtl_String
* pNew
= 0;
1307 index
= rtl_string_getToken( &pNew
, pData
, token
, cTok
, index
);
1308 return OString( pNew
, SAL_NO_ACQUIRE
);
1312 Returns a token from the string.
1314 The same as getToken(sal_Int32, sal_Char, sal_Int32 &), but always passing
1315 in 0 as the start index in the third argument.
1317 @param count the number of the token to return, starting with 0
1318 @param separator the character which separates the tokens
1320 @return the given token, or an empty string
1322 @since LibreOffice 3.6
1324 OString
getToken(sal_Int32 count
, char separator
) const {
1326 return getToken(count
, separator
, n
);
1330 Returns the Boolean value from this string.
1332 This function can't be used for language specific conversion.
1334 @return true, if the string is 1 or "True" in any ASCII case.
1335 false in any other case.
1337 bool toBoolean() const
1339 return rtl_str_toBoolean( pData
->buffer
);
1343 Returns the first character from this string.
1345 @return the first character from this string or 0, if this string
1348 sal_Char
toChar() const
1350 return pData
->buffer
[0];
1354 Returns the int32 value from this string.
1356 This function can't be used for language specific conversion.
1358 @param radix the radix (between 2 and 36)
1359 @return the int32 represented from this string.
1360 0 if this string represents no number or one of too large
1363 sal_Int32
toInt32( sal_Int16 radix
= 10 ) const
1365 return rtl_str_toInt32( pData
->buffer
, radix
);
1369 Returns the uint32 value from this string.
1371 This function can't be used for language specific conversion.
1373 @param radix the radix (between 2 and 36)
1374 @return the uint32 represented from this string.
1375 0 if this string represents no number or one of too large
1378 @since LibreOffice 4.2
1380 sal_uInt32
toUInt32( sal_Int16 radix
= 10 ) const
1382 return rtl_str_toUInt32( pData
->buffer
, radix
);
1386 Returns the int64 value from this string.
1388 This function can't be used for language specific conversion.
1390 @param radix the radix (between 2 and 36)
1391 @return the int64 represented from this string.
1392 0 if this string represents no number or one of too large
1395 sal_Int64
toInt64( sal_Int16 radix
= 10 ) const
1397 return rtl_str_toInt64( pData
->buffer
, radix
);
1401 Returns the uint64 value from this string.
1403 This function can't be used for language specific conversion.
1405 @param radix the radix (between 2 and 36)
1406 @return the uint64 represented from this string.
1407 0 if this string represents no number or one of too large
1410 @since LibreOffice 4.1
1412 sal_uInt64
toUInt64( sal_Int16 radix
= 10 ) const
1414 return rtl_str_toUInt64( pData
->buffer
, radix
);
1418 Returns the float value from this string.
1420 This function can't be used for language specific conversion.
1422 @return the float represented from this string.
1423 0.0 if this string represents no number.
1425 float toFloat() const
1427 return rtl_str_toFloat( pData
->buffer
);
1431 Returns the double value from this string.
1433 This function can't be used for language specific conversion.
1435 @return the double represented from this string.
1436 0.0 if this string represents no number.
1438 double toDouble() const
1440 return rtl_str_toDouble( pData
->buffer
);
1444 Returns the string representation of the integer argument.
1446 This function can't be used for language specific conversion.
1448 @param i an integer value
1449 @param radix the radix (between 2 and 36)
1450 @return a string with the string representation of the argument.
1451 @since LibreOffice 4.1
1453 static OString
number( int i
, sal_Int16 radix
= 10 )
1455 return number( static_cast< long long >( i
), radix
);
1458 /// @since LibreOffice 4.1
1459 static OString
number( unsigned int i
, sal_Int16 radix
= 10 )
1461 return number( static_cast< unsigned long long >( i
), radix
);
1464 /// @since LibreOffice 4.1
1465 static OString
number( long i
, sal_Int16 radix
= 10 )
1467 return number( static_cast< long long >( i
), radix
);
1470 /// @since LibreOffice 4.1
1471 static OString
number( unsigned long i
, sal_Int16 radix
= 10 )
1473 return number( static_cast< unsigned long long >( i
), radix
);
1476 /// @since LibreOffice 4.1
1477 static OString
number( long long ll
, sal_Int16 radix
= 10 )
1479 sal_Char aBuf
[RTL_STR_MAX_VALUEOFINT64
];
1480 rtl_String
* pNewData
= 0;
1481 rtl_string_newFromStr_WithLength( &pNewData
, aBuf
, rtl_str_valueOfInt64( aBuf
, ll
, radix
) );
1482 return OString( pNewData
, SAL_NO_ACQUIRE
);
1485 /// @since LibreOffice 4.1
1486 static OString
number( unsigned long long ll
, sal_Int16 radix
= 10 )
1488 sal_Char aBuf
[RTL_STR_MAX_VALUEOFUINT64
];
1489 rtl_String
* pNewData
= 0;
1490 rtl_string_newFromStr_WithLength( &pNewData
, aBuf
, rtl_str_valueOfUInt64( aBuf
, ll
, radix
) );
1491 return OString( pNewData
, SAL_NO_ACQUIRE
);
1495 Returns the string representation of the float argument.
1497 This function can't be used for language specific conversion.
1500 @return a string with the string representation of the argument.
1501 @since LibreOffice 4.1
1503 static OString
number( float f
)
1505 sal_Char aBuf
[RTL_STR_MAX_VALUEOFFLOAT
];
1506 rtl_String
* pNewData
= 0;
1507 rtl_string_newFromStr_WithLength( &pNewData
, aBuf
, rtl_str_valueOfFloat( aBuf
, f
) );
1508 return OString( pNewData
, SAL_NO_ACQUIRE
);
1512 Returns the string representation of the double argument.
1514 This function can't be used for language specific conversion.
1517 @return a string with the string representation of the argument.
1518 @since LibreOffice 4.1
1520 static OString
number( double d
)
1522 sal_Char aBuf
[RTL_STR_MAX_VALUEOFDOUBLE
];
1523 rtl_String
* pNewData
= 0;
1524 rtl_string_newFromStr_WithLength( &pNewData
, aBuf
, rtl_str_valueOfDouble( aBuf
, d
) );
1525 return OString( pNewData
, SAL_NO_ACQUIRE
);
1529 Returns the string representation of the sal_Bool argument.
1531 If the sal_Bool is true, the string "true" is returned.
1532 If the sal_Bool is false, the string "false" is returned.
1533 This function can't be used for language specific conversion.
1535 @param b a sal_Bool.
1536 @return a string with the string representation of the argument.
1537 @deprecated use boolean()
1539 SAL_DEPRECATED("use boolean()") static OString
valueOf( sal_Bool b
)
1545 Returns the string representation of the boolean argument.
1547 If the argument is true, the string "true" is returned.
1548 If the argument is false, the string "false" is returned.
1549 This function can't be used for language specific conversion.
1552 @return a string with the string representation of the argument.
1553 @since LibreOffice 4.1
1555 static OString
boolean( bool b
)
1557 sal_Char aBuf
[RTL_STR_MAX_VALUEOFBOOLEAN
];
1558 rtl_String
* pNewData
= 0;
1559 rtl_string_newFromStr_WithLength( &pNewData
, aBuf
, rtl_str_valueOfBoolean( aBuf
, b
) );
1560 return OString( pNewData
, SAL_NO_ACQUIRE
);
1564 Returns the string representation of the char argument.
1566 @param c a character.
1567 @return a string with the string representation of the argument.
1568 @deprecated use operator, function or constructor taking char or sal_Unicode argument
1570 SAL_DEPRECATED("convert to OString or use directly") static OString
valueOf( sal_Char c
)
1572 return OString( &c
, 1 );
1576 Returns the string representation of the int argument.
1578 This function can't be used for language specific conversion.
1581 @param radix the radix (between 2 and 36)
1582 @return a string with the string representation of the argument.
1583 @deprecated use number()
1585 SAL_DEPRECATED("use number()") static OString
valueOf( sal_Int32 i
, sal_Int16 radix
= 10 )
1587 return number( i
, radix
);
1591 Returns the string representation of the long argument.
1593 This function can't be used for language specific conversion.
1596 @param radix the radix (between 2 and 36)
1597 @return a string with the string representation of the argument.
1598 @deprecated use number()
1600 SAL_DEPRECATED("use number()") static OString
valueOf( sal_Int64 ll
, sal_Int16 radix
= 10 )
1602 return number( ll
, radix
);
1606 Returns the string representation of the float argument.
1608 This function can't be used for language specific conversion.
1611 @return a string with the string representation of the argument.
1612 @deprecated use number()
1614 SAL_DEPRECATED("use number()") static OString
valueOf( float f
)
1620 Returns the string representation of the double argument.
1622 This function can't be used for language specific conversion.
1625 @return a string with the string representation of the argument.
1626 @deprecated use number()
1628 SAL_DEPRECATED("use number()") static OString
valueOf( double d
)
1635 /* ======================================================================= */
1637 #ifdef LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
1639 A simple wrapper around string literal. It is usually not necessary to use, can
1640 be mostly used to force OString operator+ working with operands that otherwise would
1643 This class is not part of public API and is meant to be used only in LibreOffice code.
1644 @since LibreOffice 4.0
1646 struct SAL_WARN_UNUSED OStringLiteral
1649 explicit OStringLiteral( const char (&str
)[ N
] ) : size( N
- 1 ), data( str
) { assert( strlen( str
) == N
- 1 ); }
1658 struct ToStringHelper
< OString
>
1660 static int length( const OString
& s
) { return s
.getLength(); }
1661 static char* addData( char* buffer
, const OString
& s
) { return addDataHelper( buffer
, s
.getStr(), s
.getLength()); }
1662 static const bool allowOStringConcat
= true;
1663 static const bool allowOUStringConcat
= false;
1670 struct ToStringHelper
< OStringLiteral
>
1672 static int length( const OStringLiteral
& str
) { return str
.size
; }
1673 static char* addData( char* buffer
, const OStringLiteral
& str
) { return addDataHelper( buffer
, str
.data
, str
.size
); }
1674 static const bool allowOStringConcat
= true;
1675 static const bool allowOUStringConcat
= false;
1681 template< typename charT
, typename traits
, typename T1
, typename T2
>
1682 inline std::basic_ostream
<charT
, traits
> & operator <<(
1683 std::basic_ostream
<charT
, traits
> & stream
, const OStringConcat
< T1
, T2
>& concat
)
1685 return stream
<< OString( concat
);
1690 /** A helper to use OStrings with hash maps.
1692 Instances of this class are unary function objects that can be used as
1693 hash function arguments to std::unordered_map and similar constructs.
1697 /** Compute a hash code for a string.
1703 a hash code for the string. This hash code should not be stored
1704 persistently, as its computation may change in later revisions.
1706 size_t operator()( const OString
& rString
) const
1707 { return (size_t)rString
.hashCode(); }
1710 /** Equality functor for classic c-strings (i.e., null-terminated char* strings). */
1713 bool operator()( const char* p1
, const char* p2
) const
1714 { return rtl_str_compare(p1
, p2
) == 0; }
1717 /** Hashing functor for classic c-strings (i.e., null-terminated char* strings). */
1720 size_t operator()(const char* p
) const
1721 { return rtl_str_hashCode(p
); }
1724 /* ======================================================================= */
1727 Support for rtl::OString in std::ostream (and thus in
1728 CPPUNIT_ASSERT or SAL_INFO macros, for example).
1730 @since LibreOffice 4.0
1732 template< typename charT
, typename traits
> std::basic_ostream
<charT
, traits
> &
1734 std::basic_ostream
<charT
, traits
> & stream
, OString
const & string
)
1736 return stream
<< string
.getStr();
1737 // best effort; potentially loses data due to embedded null characters
1742 #ifdef RTL_STRING_UNITTEST
1745 typedef rtlunittest::OString OString
;
1747 #undef RTL_STRING_CONST_FUNCTION
1750 #if defined LIBO_INTERNAL_ONLY && !defined RTL_STRING_UNITTEST
1751 using ::rtl::OString
;
1752 using ::rtl::OStringHash
;
1753 using ::rtl::OStringLiteral
;
1756 #endif // INCLUDED_RTL_STRING_HXX
1758 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */