update credits
[LibreOffice.git] / include / rtl / string.hxx
blob7228fe7567a5950a081fd39483c882d6128da714
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 _RTL_STRING_HXX_
21 #define _RTL_STRING_HXX_
23 #include "sal/config.h"
25 #include <cassert>
26 #include <ostream>
27 #include <string.h>
29 #include <osl/diagnose.h>
30 #include <rtl/textenc.h>
31 #include <rtl/string.h>
32 #include <rtl/stringutils.hxx>
34 #ifdef RTL_FAST_STRING
35 #include <rtl/stringconcat.hxx>
36 #endif
38 #include "sal/log.hxx"
40 #if !defined EXCEPTIONS_OFF
41 #include <new>
42 #endif
44 // The unittest uses slightly different code to help check that the proper
45 // calls are made. The class is put into a different namespace to make
46 // sure the compiler generates a different (if generating also non-inline)
47 // copy of the function and does not merge them together. The class
48 // is "brought" into the proper rtl namespace by a typedef below.
49 #ifdef RTL_STRING_UNITTEST
50 #define rtl rtlunittest
51 #endif
53 namespace rtl
56 #ifdef RTL_STRING_UNITTEST
57 #undef rtl
58 // helper macro to make functions appear more readable
59 #define RTL_STRING_CONST_FUNCTION rtl_string_unittest_const_literal_function = true;
60 #else
61 #define RTL_STRING_CONST_FUNCTION
62 #endif
64 /* ======================================================================= */
66 /**
67 This String class provide base functionality for C++ like 8-Bit
68 character array handling. The advantage of this class is, that it
69 handle all the memory managament for you - and it do it
70 more efficient. If you assign a string to another string, the
71 data of both strings are shared (without any copy operation or
72 memory allocation) as long as you do not change the string. This class
73 stores also the length of the string, so that many operations are
74 faster as the C-str-functions.
76 This class provide only readonly string handling. So you could create
77 a string and you could only query the content from this string.
78 It provide also functionality to change the string, but this results
79 in every case in a new string instance (in the most cases with an
80 memory allocation). You don't have functionality to change the
81 content of the string. If you want change the string content, than
82 you should us the OStringBuffer class, which provide these
83 functionality and avoid to much memory allocation.
85 The design of this class is similar to the string classes in Java
86 and so more people should have fewer understanding problems when they
87 use this class.
90 class SAL_WARN_UNUSED OString
92 public:
93 /// @cond INTERNAL
94 rtl_String * pData;
95 /// @endcond
97 private:
98 class DO_NOT_ACQUIRE;
100 OString( rtl_String * value, SAL_UNUSED_PARAMETER DO_NOT_ACQUIRE * )
102 pData = value;
105 public:
107 New string containing no characters.
109 OString() SAL_THROW(())
111 pData = 0;
112 rtl_string_new( &pData );
116 New string from OString.
118 @param str a OString.
120 OString( const OString & str ) SAL_THROW(())
122 pData = str.pData;
123 rtl_string_acquire( pData );
127 New string from OString data.
129 @param str a OString data.
131 OString( rtl_String * str ) SAL_THROW(())
133 pData = str;
134 rtl_string_acquire( pData );
137 /** New string from OString data without acquiring it. Takeover of ownership.
139 The SAL_NO_ACQUIRE dummy parameter is only there to distinguish this
140 from other constructors.
142 @param str a OString data.
144 inline OString( rtl_String * str, __sal_NoAcquire ) SAL_THROW(())
146 pData = str;
150 New string from a single character.
152 @param value a character.
154 explicit OString( sal_Char value ) SAL_THROW(())
155 : pData (0)
157 rtl_string_newFromStr_WithLength( &pData, &value, 1 );
161 New string from a character buffer array.
163 Note: The argument type is always either char* or const char*. The template is
164 used only for technical reasons, as is the second argument.
166 @param value a NULL-terminated character array.
168 template< typename T >
169 OString( const T& value, typename internal::CharPtrDetector< T, internal::Dummy >::Type = internal::Dummy() ) SAL_THROW(())
171 pData = 0;
172 rtl_string_newFromStr( &pData, value );
175 template< typename T >
176 OString( T& value, typename internal::NonConstCharArrayDetector< T, internal::Dummy >::Type = internal::Dummy() ) SAL_THROW(())
178 pData = 0;
179 rtl_string_newFromStr( &pData, value );
183 New string from a string literal.
185 If there are any embedded \0's in the string literal, the result is undefined.
186 Use the overload that explicitly accepts length.
188 @since LibreOffice 3.6
190 @param literal a string literal
192 template< typename T >
193 OString( T& literal, typename internal::ConstCharArrayDetector< T, internal::Dummy >::Type = internal::Dummy() ) SAL_THROW(())
195 assert( strlen( literal ) == internal::ConstCharArrayDetector< T >::size - 1 );
196 pData = 0;
197 if( internal::ConstCharArrayDetector< T, void >::size - 1 == 0 ) // empty string
198 rtl_string_new( &pData );
199 else
200 rtl_string_newFromLiteral( &pData, literal, internal::ConstCharArrayDetector< T, void >::size - 1, 0 );
201 #ifdef RTL_STRING_UNITTEST
202 rtl_string_unittest_const_literal = true;
203 #endif
207 New string from a character buffer array.
209 @param value a character array.
210 @param length the number of character which should be copied.
211 The character array length must be greater or
212 equal than this value.
214 OString( const sal_Char * value, sal_Int32 length ) SAL_THROW(())
216 pData = 0;
217 rtl_string_newFromStr_WithLength( &pData, value, length );
221 New string from a Unicode character buffer array.
223 @param value a Unicode character array.
224 @param length the number of character which should be converted.
225 The Unicode character array length must be
226 greater or equal than this value.
227 @param encoding the text encoding in which the Unicode character
228 sequence should be converted.
229 @param convertFlags flags which controls the conversion.
230 see RTL_UNICODETOTEXT_FLAGS_...
232 @exception std::bad_alloc is thrown if an out-of-memory condition occurs
234 OString( const sal_Unicode * value, sal_Int32 length,
235 rtl_TextEncoding encoding,
236 sal_uInt32 convertFlags = OUSTRING_TO_OSTRING_CVTFLAGS )
238 pData = 0;
239 rtl_uString2String( &pData, value, length, encoding, convertFlags );
240 if (pData == 0) {
241 #if defined EXCEPTIONS_OFF
242 abort();
243 #else
244 throw std::bad_alloc();
245 #endif
249 #ifdef RTL_FAST_STRING
251 @overload
252 @internal
254 template< typename T1, typename T2 >
255 OString( const OStringConcat< T1, T2 >& c )
257 const sal_Int32 l = c.length();
258 pData = rtl_string_alloc( l );
259 if (l != 0)
261 char* end = c.addData( pData->buffer );
262 pData->length = end - pData->buffer;
263 *end = '\0';
266 #endif
269 Release the string data.
271 ~OString() SAL_THROW(())
273 rtl_string_release( pData );
277 Assign a new string.
279 @param str a OString.
281 OString & operator=( const OString & str ) SAL_THROW(())
283 rtl_string_assign( &pData, str.pData );
284 return *this;
288 @overload
289 This function accepts an ASCII string literal as its argument.
290 @since LibreOffice 3.6
292 template< typename T >
293 typename internal::ConstCharArrayDetector< T, OString& >::Type operator=( T& literal ) SAL_THROW(())
295 RTL_STRING_CONST_FUNCTION
296 assert( strlen( literal ) == internal::ConstCharArrayDetector< T >::size - 1 );
297 if( internal::ConstCharArrayDetector< T, void >::size - 1 == 0 ) // empty string
298 rtl_string_new( &pData );
299 else
300 rtl_string_newFromLiteral( &pData, literal, internal::ConstCharArrayDetector< T, void >::size - 1, 0 );
301 return *this;
305 Append a string to this string.
307 @param str a OString.
309 OString & operator+=( const OString & str ) SAL_THROW(())
311 rtl_string_newConcat( &pData, pData, str.pData );
312 return *this;
315 #ifdef RTL_FAST_STRING
317 @overload
318 @internal
320 template< typename T1, typename T2 >
321 OString& operator+=( const OStringConcat< T1, T2 >& c )
323 const int l = c.length();
324 if( l == 0 )
325 return *this;
326 rtl_string_ensureCapacity( &pData, pData->length + l );
327 char* end = c.addData( pData->buffer + pData->length );
328 *end = '\0';
329 pData->length = end - pData->buffer;
330 return *this;
332 #endif
334 Returns the length of this string.
336 The length is equal to the number of characters in this string.
338 @return the length of the sequence of characters represented by this
339 object.
341 sal_Int32 getLength() const SAL_THROW(()) { return pData->length; }
344 Checks if a string is empty.
346 @return true if the string is empty;
347 false, otherwise.
349 @since LibreOffice 3.4
351 bool isEmpty() const SAL_THROW(())
353 return pData->length == 0;
357 Returns a pointer to the characters of this string.
359 <p>The returned pointer is guaranteed to point to a null-terminated byte
360 string. But note that this string object may contain embedded null
361 characters, which will thus also be embedded in the returned
362 null-terminated byte string.</p>
364 @return a pointer to a null-terminated byte string representing the
365 characters of this string object.
367 const sal_Char * getStr() const SAL_THROW(()) { return pData->buffer; }
370 Access to individual characters.
372 @param index must be non-negative and less than length.
374 @return the character at the given index.
376 @since LibreOffice 3.5
378 sal_Char operator [](sal_Int32 index) const {
379 assert(index >= 0 && index <= getLength());
380 //TODO: should really check for < getLength(), but there is quite
381 // some clever code out there that violates this function's
382 // documented precondition and relies on s[s.getLength()] == 0 and
383 // that would need to be fixed first
384 return getStr()[index];
388 Compares two strings.
390 The comparison is based on the numeric value of each character in
391 the strings and return a value indicating their relationship.
392 This function can't be used for language specific sorting.
394 @param str the object to be compared.
395 @return 0 - if both strings are equal
396 < 0 - if this string is less than the string argument
397 > 0 - if this string is greater than the string argument
399 sal_Int32 compareTo( const OString & str ) const SAL_THROW(())
401 return rtl_str_compare_WithLength( pData->buffer, pData->length,
402 str.pData->buffer, str.pData->length );
406 Compares two strings with an maximum count of characters.
408 The comparison is based on the numeric value of each character in
409 the strings and return a value indicating their relationship.
410 This function can't be used for language specific sorting.
412 @param rObj the object to be compared.
413 @param maxLength the maximum count of characters to be compared.
414 @return 0 - if both strings are equal
415 < 0 - if this string is less than the string argument
416 > 0 - if this string is greater than the string argument
418 sal_Int32 compareTo( const OString & rObj, sal_Int32 maxLength ) const SAL_THROW(())
420 return rtl_str_shortenedCompare_WithLength( pData->buffer, pData->length,
421 rObj.pData->buffer, rObj.pData->length, maxLength );
425 Compares two strings in reverse order.
427 The comparison is based on the numeric value of each character in
428 the strings and return a value indicating their relationship.
429 This function can't be used for language specific sorting.
431 @param str the object to be compared.
432 @return 0 - if both strings are equal
433 < 0 - if this string is less than the string argument
434 > 0 - if this string is greater than the string argument
436 sal_Int32 reverseCompareTo( const OString & str ) const SAL_THROW(())
438 return rtl_str_reverseCompare_WithLength( pData->buffer, pData->length,
439 str.pData->buffer, str.pData->length );
443 Perform a comparison of two strings.
445 The result is true if and only if second string
446 represents the same sequence of characters as the first string.
447 This function can't be used for language specific comparison.
449 @param str the object to be compared.
450 @return sal_True if the strings are equal;
451 sal_False, otherwise.
453 sal_Bool equals( const OString & str ) const SAL_THROW(())
455 if ( pData->length != str.pData->length )
456 return sal_False;
457 if ( pData == str.pData )
458 return sal_True;
459 return rtl_str_reverseCompare_WithLength( pData->buffer, pData->length,
460 str.pData->buffer, str.pData->length ) == 0;
464 Perform a comparison of two strings.
466 The result is true if and only if second string
467 represents the same sequence of characters as the first string.
468 The ASCII string must be NULL-terminated and must be greater or
469 equal as length.
470 This function can't be used for language specific comparison.
473 @param value a character array.
474 @param length the length of the character array.
475 @return sal_True if the strings are equal;
476 sal_False, otherwise.
478 sal_Bool equalsL( const sal_Char* value, sal_Int32 length ) const SAL_THROW(())
480 if ( pData->length != length )
481 return sal_False;
483 return rtl_str_reverseCompare_WithLength( pData->buffer, pData->length,
484 value, length ) == 0;
488 Perform a ASCII lowercase comparison of two strings.
490 The result is true if and only if second string
491 represents the same sequence of characters as the first string,
492 ignoring the case.
493 Character values between 65 and 90 (ASCII A-Z) are interpreted as
494 values between 97 and 122 (ASCII a-z).
495 This function can't be used for language specific comparison.
497 @param str the object to be compared.
498 @return sal_True if the strings are equal;
499 sal_False, otherwise.
501 sal_Bool equalsIgnoreAsciiCase( const OString & str ) const SAL_THROW(())
503 if ( pData->length != str.pData->length )
504 return sal_False;
505 if ( pData == str.pData )
506 return sal_True;
507 return rtl_str_compareIgnoreAsciiCase_WithLength( pData->buffer, pData->length,
508 str.pData->buffer, str.pData->length ) == 0;
512 Perform a ASCII lowercase comparison of two strings.
514 The result is true if and only if second string
515 represents the same sequence of characters as the first string,
516 ignoring the case.
517 Character values between 65 and 90 (ASCII A-Z) are interpreted as
518 values between 97 and 122 (ASCII a-z).
519 Since this method is optimized for performance, the ASCII character
520 values are not converted in any way. The caller has to make sure that
521 all ASCII characters are in the allowed range between 0 and
522 127. The ASCII string must be NULL-terminated.
523 This function can't be used for language specific comparison.
525 Note: The argument type is always either char* or const char*, the return type is bool.
526 The template is used only for technical reasons.
528 @param asciiStr the 8-Bit ASCII character string to be compared.
529 @return sal_True if the strings are equal;
530 sal_False, otherwise.
532 template< typename T >
533 typename internal::CharPtrDetector< T, bool >::Type equalsIgnoreAsciiCase( const T& asciiStr ) const SAL_THROW(())
535 return rtl_str_compareIgnoreAsciiCase( pData->buffer, asciiStr ) == 0;
538 template< typename T >
539 typename internal::NonConstCharArrayDetector< T, bool >::Type equalsIgnoreAsciiCase( T& asciiStr ) const SAL_THROW(())
541 return rtl_str_compareIgnoreAsciiCase( pData->buffer, asciiStr ) == 0;
545 @overload
546 This function accepts an ASCII string literal as its argument.
547 @since LibreOffice 3.6
549 template< typename T >
550 typename internal::ConstCharArrayDetector< T, bool >::Type equalsIgnoreAsciiCase( T& literal ) const SAL_THROW(())
552 RTL_STRING_CONST_FUNCTION
553 assert( strlen( literal ) == internal::ConstCharArrayDetector< T >::size - 1 );
554 if ( pData->length != internal::ConstCharArrayDetector< T, void >::size - 1 )
555 return false;
556 return rtl_str_compareIgnoreAsciiCase_WithLength( pData->buffer, pData->length,
557 literal, internal::ConstCharArrayDetector< T, void >::size - 1 ) == 0;
561 Perform a ASCII lowercase comparison of two strings.
563 The result is true if and only if second string
564 represents the same sequence of characters as the first string,
565 ignoring the case.
566 Character values between 65 and 90 (ASCII A-Z) are interpreted as
567 values between 97 and 122 (ASCII a-z).
568 Since this method is optimized for performance, the ASCII character
569 values are not converted in any way. The caller has to make sure that
570 all ASCII characters are in the allowed range between 0 and
571 127. The ASCII string must be greater or equal in length as asciiStrLength.
572 This function can't be used for language specific comparison.
574 @param asciiStr the 8-Bit ASCII character string to be compared.
575 @param asciiStrLength the length of the ascii string
576 @return sal_True if the strings are equal;
577 sal_False, otherwise.
579 sal_Bool equalsIgnoreAsciiCaseL( const sal_Char * asciiStr, sal_Int32 asciiStrLength ) const SAL_THROW(())
581 if ( pData->length != asciiStrLength )
582 return sal_False;
584 return rtl_str_compareIgnoreAsciiCase_WithLength( pData->buffer, pData->length,
585 asciiStr, asciiStrLength ) == 0;
589 Match against a substring appearing in this string.
591 The result is true if and only if the second string appears as a substring
592 of this string, at the given position.
593 This function can't be used for language specific comparison.
595 @param str the object (substring) to be compared.
596 @param fromIndex the index to start the comparion from.
597 The index must be greater or equal than 0
598 and less or equal as the string length.
599 @return sal_True if str match with the characters in the string
600 at the given position;
601 sal_False, otherwise.
603 sal_Bool match( const OString & str, sal_Int32 fromIndex = 0 ) const SAL_THROW(())
605 return rtl_str_shortenedCompare_WithLength( pData->buffer+fromIndex, pData->length-fromIndex,
606 str.pData->buffer, str.pData->length, str.pData->length ) == 0;
610 @overload
611 This function accepts an ASCII string literal as its argument.
612 @since LibreOffice 3.6
614 template< typename T >
615 typename internal::ConstCharArrayDetector< T, bool >::Type match( T& literal, sal_Int32 fromIndex = 0 ) const SAL_THROW(())
617 RTL_STRING_CONST_FUNCTION
618 assert( strlen( literal ) == internal::ConstCharArrayDetector< T >::size - 1 );
619 return rtl_str_shortenedCompare_WithLength(
620 pData->buffer + fromIndex, pData->length - fromIndex,
621 literal, internal::ConstCharArrayDetector< T, void >::size - 1, internal::ConstCharArrayDetector< T, void >::size - 1) == 0;
625 Match against a substring appearing in this string.
627 @param str the substring to be compared; must not be null and must point
628 to memory of at least strLength bytes
630 @param strLength the length of the substring; must be non-negative
632 @param fromIndex the index into this string to start the comparison at;
633 must be non-negative and not greater than this string's length
635 @return true if and only if the given str is contained as a substring of
636 this string at the given fromIndex
638 @since LibreOffice 3.6
640 bool matchL(
641 char const * str, sal_Int32 strLength, sal_Int32 fromIndex = 0)
642 const
644 return rtl_str_shortenedCompare_WithLength(
645 pData->buffer + fromIndex, pData->length - fromIndex,
646 str, strLength, strLength) == 0;
649 // This overload is left undefined, to detect calls of matchL that
650 // erroneously use RTL_CONSTASCII_USTRINGPARAM instead of
651 // RTL_CONSTASCII_STRINGPARAM (but would lead to ambiguities on 32 bit
652 // platforms):
653 #if SAL_TYPES_SIZEOFLONG == 8
654 void matchL(char const *, sal_Int32, rtl_TextEncoding) const;
655 #endif
658 Match against a substring appearing in this string, ignoring the case of
659 ASCII letters.
661 The result is true if and only if the second string appears as a substring
662 of this string, at the given position.
663 Character values between 65 and 90 (ASCII A-Z) are interpreted as
664 values between 97 and 122 (ASCII a-z).
665 This function can't be used for language specific comparison.
667 @param str the object (substring) to be compared.
668 @param fromIndex the index to start the comparion from.
669 The index must be greater or equal than 0
670 and less or equal as the string length.
671 @return sal_True if str match with the characters in the string
672 at the given position;
673 sal_False, otherwise.
675 sal_Bool matchIgnoreAsciiCase( const OString & str, sal_Int32 fromIndex = 0 ) const SAL_THROW(())
677 return rtl_str_shortenedCompareIgnoreAsciiCase_WithLength( pData->buffer+fromIndex, pData->length-fromIndex,
678 str.pData->buffer, str.pData->length,
679 str.pData->length ) == 0;
683 @overload
684 This function accepts an ASCII string literal as its argument.
685 @since LibreOffice 3.6
687 template< typename T >
688 typename internal::ConstCharArrayDetector< T, bool >::Type matchIgnoreAsciiCase( T& literal, sal_Int32 fromIndex = 0 ) const
690 RTL_STRING_CONST_FUNCTION
691 assert( strlen( literal ) == internal::ConstCharArrayDetector< T >::size - 1 );
692 return rtl_str_shortenedCompareIgnoreAsciiCase_WithLength( pData->buffer+fromIndex, pData->length-fromIndex,
693 literal, internal::ConstCharArrayDetector< T, void >::size - 1, internal::ConstCharArrayDetector< T, void >::size - 1 ) == 0;
697 Check whether this string starts with a given substring.
699 @param str the substring to be compared
701 @return true if and only if the given str appears as a substring at the
702 start of this string
704 @since LibreOffice 4.0
706 bool startsWith(OString const & str) const {
707 return match(str, 0);
711 @overload
712 This function accepts an ASCII string literal as its argument.
713 @since LibreOffice 4.0
715 template< typename T >
716 typename internal::ConstCharArrayDetector< T, bool >::Type startsWith( T& literal ) const
718 RTL_STRING_CONST_FUNCTION
719 return match(literal, 0);
723 Check whether this string ends with a given substring.
725 @param str the substring to be compared
727 @return true if and only if the given str appears as a substring at the
728 end of this string
730 @since LibreOffice 3.6
732 bool endsWith(OString const & str) const {
733 return str.getLength() <= getLength()
734 && match(str, getLength() - str.getLength());
738 @overload
739 This function accepts an ASCII string literal as its argument.
740 @since LibreOffice 3.6
742 template< typename T >
743 typename internal::ConstCharArrayDetector< T, bool >::Type endsWith( T& literal ) const
745 RTL_STRING_CONST_FUNCTION
746 assert( strlen( literal ) == internal::ConstCharArrayDetector< T >::size - 1 );
747 return internal::ConstCharArrayDetector< T, void >::size - 1 <= getLength()
748 && match(literal, getLength() - ( internal::ConstCharArrayDetector< T, void >::size - 1 ));
752 Check whether this string ends with a given substring.
754 @param str the substring to be compared; must not be null and must point
755 to memory of at least strLength bytes
757 @param strLength the length of the substring; must be non-negative
759 @return true if and only if the given str appears as a substring at the
760 end of this string
762 @since LibreOffice 3.6
764 bool endsWithL(char const * str, sal_Int32 strLength) const {
765 return strLength <= getLength()
766 && matchL(str, strLength, getLength() - strLength);
769 friend sal_Bool operator == ( const OString& rStr1, const OString& rStr2 ) SAL_THROW(())
770 { return rStr1.equals(rStr2); }
771 friend sal_Bool operator != ( const OString& rStr1, const OString& rStr2 ) SAL_THROW(())
772 { return !(operator == ( rStr1, rStr2 )); }
773 friend sal_Bool operator < ( const OString& rStr1, const OString& rStr2 ) SAL_THROW(())
774 { return rStr1.compareTo( rStr2 ) < 0; }
775 friend sal_Bool operator > ( const OString& rStr1, const OString& rStr2 ) SAL_THROW(())
776 { return rStr1.compareTo( rStr2 ) > 0; }
777 friend sal_Bool operator <= ( const OString& rStr1, const OString& rStr2 ) SAL_THROW(())
778 { return rStr1.compareTo( rStr2 ) <= 0; }
779 friend sal_Bool operator >= ( const OString& rStr1, const OString& rStr2 ) SAL_THROW(())
780 { return rStr1.compareTo( rStr2 ) >= 0; }
782 template< typename T >
783 friend typename internal::CharPtrDetector< T, bool >::Type operator==( const OString& rStr1, const T& value ) SAL_THROW(())
785 return rStr1.compareTo( value ) == 0;
788 template< typename T >
789 friend typename internal::NonConstCharArrayDetector< T, bool >::Type operator==( const OString& rStr1, T& value ) SAL_THROW(())
791 return rStr1.compareTo( value ) == 0;
794 template< typename T >
795 friend typename internal::CharPtrDetector< T, bool >::Type operator==( const T& value, const OString& rStr2 ) SAL_THROW(())
797 return rStr2.compareTo( value ) == 0;
800 template< typename T >
801 friend typename internal::NonConstCharArrayDetector< T, bool >::Type operator==( T& value, const OString& rStr2 ) SAL_THROW(())
803 return rStr2.compareTo( value ) == 0;
807 @overload
808 This function accepts an ASCII string literal as its argument.
809 @since LibreOffice 3.6
811 template< typename T >
812 friend typename internal::ConstCharArrayDetector< T, bool >::Type operator==( const OString& rStr, T& literal ) SAL_THROW(())
814 RTL_STRING_CONST_FUNCTION
815 assert( strlen( literal ) == internal::ConstCharArrayDetector< T >::size - 1 );
816 return rStr.getLength() == internal::ConstCharArrayDetector< T, void >::size - 1
817 && rtl_str_compare_WithLength( rStr.pData->buffer, rStr.pData->length, literal,
818 internal::ConstCharArrayDetector< T, void >::size - 1 ) == 0;
822 @overload
823 This function accepts an ASCII string literal as its argument.
824 @since LibreOffice 3.6
826 template< typename T >
827 friend typename internal::ConstCharArrayDetector< T, bool >::Type operator==( T& literal, const OString& rStr ) SAL_THROW(())
829 RTL_STRING_CONST_FUNCTION
830 assert( strlen( literal ) == internal::ConstCharArrayDetector< T >::size - 1 );
831 return rStr.getLength() == internal::ConstCharArrayDetector< T, void >::size - 1
832 && rtl_str_compare_WithLength( rStr.pData->buffer, rStr.pData->length, literal,
833 internal::ConstCharArrayDetector< T, void >::size - 1 ) == 0;
836 template< typename T >
837 friend typename internal::CharPtrDetector< T, bool >::Type operator!=( const OString& rStr1, const T& value ) SAL_THROW(())
839 return !(operator == ( rStr1, value ));
842 template< typename T >
843 friend typename internal::NonConstCharArrayDetector< T, bool >::Type operator!=( const OString& rStr1, T& value ) SAL_THROW(())
845 return !(operator == ( rStr1, value ));
848 template< typename T >
849 friend typename internal::CharPtrDetector< T, bool >::Type operator!=( const T& value, const OString& rStr2 ) SAL_THROW(())
851 return !(operator == ( value, rStr2 ));
854 template< typename T >
855 friend typename internal::NonConstCharArrayDetector< T, bool >::Type operator!=( T& value, const OString& rStr2 ) SAL_THROW(())
857 return !(operator == ( value, rStr2 ));
861 @overload
862 This function accepts an ASCII string literal as its argument.
863 @since LibreOffice 3.6
865 template< typename T >
866 friend typename internal::ConstCharArrayDetector< T, bool >::Type operator!=( const OString& rStr, T& literal ) SAL_THROW(())
868 return !( rStr == literal );
872 @overload
873 This function accepts an ASCII string literal as its argument.
874 @since LibreOffice 3.6
876 template< typename T >
877 friend typename internal::ConstCharArrayDetector< T, bool >::Type operator!=( T& literal, const OString& rStr ) SAL_THROW(())
879 return !( literal == rStr );
883 Returns a hashcode for this string.
885 @return a hash code value for this object.
887 @see rtl::OStringHash for convenient use of boost::unordered_map
889 sal_Int32 hashCode() const SAL_THROW(())
891 return rtl_str_hashCode_WithLength( pData->buffer, pData->length );
895 Returns the index within this string of the first occurrence of the
896 specified character, starting the search at the specified index.
898 @param ch character to be located.
899 @param fromIndex the index to start the search from.
900 The index must be greater or equal than 0
901 and less or equal as the string length.
902 @return the index of the first occurrence of the character in the
903 character sequence represented by this string that is
904 greater than or equal to fromIndex, or
905 -1 if the character does not occur.
907 sal_Int32 indexOf( sal_Char ch, sal_Int32 fromIndex = 0 ) const SAL_THROW(())
909 sal_Int32 ret = rtl_str_indexOfChar_WithLength( pData->buffer+fromIndex, pData->length-fromIndex, ch );
910 return (ret < 0 ? ret : ret+fromIndex);
914 Returns the index within this string of the last occurrence of the
915 specified character, searching backward starting at the end.
917 @param ch character to be located.
918 @return the index of the last occurrence of the character in the
919 character sequence represented by this string, or
920 -1 if the character does not occur.
922 sal_Int32 lastIndexOf( sal_Char ch ) const SAL_THROW(())
924 return rtl_str_lastIndexOfChar_WithLength( pData->buffer, pData->length, ch );
928 Returns the index within this string of the last occurrence of the
929 specified character, searching backward starting before the specified
930 index.
932 @param ch character to be located.
933 @param fromIndex the index before which to start the search.
934 @return the index of the last occurrence of the character in the
935 character sequence represented by this string that
936 is less than fromIndex, or -1
937 if the character does not occur before that point.
939 sal_Int32 lastIndexOf( sal_Char ch, sal_Int32 fromIndex ) const SAL_THROW(())
941 return rtl_str_lastIndexOfChar_WithLength( pData->buffer, fromIndex, ch );
945 Returns the index within this string of the first occurrence of the
946 specified substring, starting at the specified index.
948 If str doesn't include any character, always -1 is
949 returned. This is also the case, if both strings are empty.
951 @param str the substring to search for.
952 @param fromIndex the index to start the search from.
953 @return If the string argument occurs one or more times as a substring
954 within this string at the starting index, then the index
955 of the first character of the first such substring is
956 returned. If it does not occur as a substring starting
957 at fromIndex or beyond, -1 is returned.
959 sal_Int32 indexOf( const OString & str, sal_Int32 fromIndex = 0 ) const SAL_THROW(())
961 sal_Int32 ret = rtl_str_indexOfStr_WithLength( pData->buffer+fromIndex, pData->length-fromIndex,
962 str.pData->buffer, str.pData->length );
963 return (ret < 0 ? ret : ret+fromIndex);
967 @overload
968 This function accepts an ASCII string literal as its argument.
969 @since LibreOffice 3.6
971 template< typename T >
972 typename internal::ConstCharArrayDetector< T, sal_Int32 >::Type indexOf( T& literal, sal_Int32 fromIndex = 0 ) const SAL_THROW(())
974 RTL_STRING_CONST_FUNCTION
975 assert( strlen( literal ) == internal::ConstCharArrayDetector< T >::size - 1 );
976 sal_Int32 n = rtl_str_indexOfStr_WithLength(
977 pData->buffer + fromIndex, pData->length - fromIndex, literal, internal::ConstCharArrayDetector< T, void >::size - 1);
978 return n < 0 ? n : n + fromIndex;
982 Returns the index within this string of the first occurrence of the
983 specified substring, starting at the specified index.
985 If str doesn't include any character, always -1 is
986 returned. This is also the case, if both strings are empty.
988 @param str the substring to search for.
989 @param len the length of the substring.
990 @param fromIndex the index to start the search from.
991 @return If the string argument occurs one or more times as a substring
992 within this string at the starting index, then the index
993 of the first character of the first such substring is
994 returned. If it does not occur as a substring starting
995 at fromIndex or beyond, -1 is returned.
997 @since LibreOffice 3.6
999 sal_Int32 indexOfL(char const * str, sal_Int32 len, sal_Int32 fromIndex = 0)
1000 const SAL_THROW(())
1002 sal_Int32 n = rtl_str_indexOfStr_WithLength(
1003 pData->buffer + fromIndex, pData->length - fromIndex, str, len);
1004 return n < 0 ? n : n + fromIndex;
1007 // This overload is left undefined, to detect calls of indexOfL that
1008 // erroneously use RTL_CONSTASCII_USTRINGPARAM instead of
1009 // RTL_CONSTASCII_STRINGPARAM (but would lead to ambiguities on 32 bit
1010 // platforms):
1011 #if SAL_TYPES_SIZEOFLONG == 8
1012 void indexOfL(char const *, sal_Int32, rtl_TextEncoding) const;
1013 #endif
1016 Returns the index within this string of the last occurrence of
1017 the specified substring, searching backward starting at the end.
1019 The returned index indicates the starting index of the substring
1020 in this string.
1021 If str doesn't include any character, always -1 is
1022 returned. This is also the case, if both strings are empty.
1024 @param str the substring to search for.
1025 @return If the string argument occurs one or more times as a substring
1026 within this string, then the index of the first character of
1027 the last such substring is returned. If it does not occur as
1028 a substring, -1 is returned.
1030 sal_Int32 lastIndexOf( const OString & str ) const SAL_THROW(())
1032 return rtl_str_lastIndexOfStr_WithLength( pData->buffer, pData->length,
1033 str.pData->buffer, str.pData->length );
1037 Returns the index within this string of the last occurrence of
1038 the specified substring, searching backward starting before the specified
1039 index.
1041 The returned index indicates the starting index of the substring
1042 in this string.
1043 If str doesn't include any character, always -1 is
1044 returned. This is also the case, if both strings are empty.
1046 @param str the substring to search for.
1047 @param fromIndex the index before which to start the search.
1048 @return If the string argument occurs one or more times as a substring
1049 within this string before the starting index, then the index
1050 of the first character of the last such substring is
1051 returned. Otherwise, -1 is returned.
1053 sal_Int32 lastIndexOf( const OString & str, sal_Int32 fromIndex ) const SAL_THROW(())
1055 return rtl_str_lastIndexOfStr_WithLength( pData->buffer, fromIndex,
1056 str.pData->buffer, str.pData->length );
1060 Returns a new string that is a substring of this string.
1062 The substring begins at the specified beginIndex. If
1063 beginIndex is negative or be greater than the length of
1064 this string, behaviour is undefined.
1066 @param beginIndex the beginning index, inclusive.
1067 @return the specified substring.
1069 SAL_WARN_UNUSED_RESULT OString copy( sal_Int32 beginIndex ) const SAL_THROW(())
1071 rtl_String *pNew = 0;
1072 rtl_string_newFromSubString( &pNew, pData, beginIndex, getLength() - beginIndex );
1073 return OString( pNew, (DO_NOT_ACQUIRE*)0 );
1077 Returns a new string that is a substring of this string.
1079 The substring begins at the specified beginIndex and contains count
1080 characters. If either beginIndex or count are negative,
1081 or beginIndex + count are greater than the length of this string
1082 then behaviour is undefined.
1084 @param beginIndex the beginning index, inclusive.
1085 @param count the number of characters.
1086 @return the specified substring.
1088 SAL_WARN_UNUSED_RESULT OString copy( sal_Int32 beginIndex, sal_Int32 count ) const SAL_THROW(())
1090 rtl_String *pNew = 0;
1091 rtl_string_newFromSubString( &pNew, pData, beginIndex, count );
1092 return OString( pNew, (DO_NOT_ACQUIRE*)0 );
1096 Concatenates the specified string to the end of this string.
1098 @param str the string that is concatenated to the end
1099 of this string.
1100 @return a string that represents the concatenation of this string
1101 followed by the string argument.
1103 SAL_WARN_UNUSED_RESULT OString concat( const OString & str ) const SAL_THROW(())
1105 rtl_String* pNew = 0;
1106 rtl_string_newConcat( &pNew, pData, str.pData );
1107 return OString( pNew, (DO_NOT_ACQUIRE*)0 );
1110 #ifndef RTL_FAST_STRING
1111 friend OString operator+( const OString & str1, const OString & str2 ) SAL_THROW(())
1113 return str1.concat( str2 );
1115 #endif
1118 Returns a new string resulting from replacing n = count characters
1119 from position index in this string with newStr.
1121 @param index the replacing index in str.
1122 The index must be greater or equal as 0 and
1123 less or equal as the length of the string.
1124 @param count the count of characters that will replaced
1125 The count must be greater or equal as 0 and
1126 less or equal as the length of the string minus index.
1127 @param newStr the new substring.
1128 @return the new string.
1130 SAL_WARN_UNUSED_RESULT OString replaceAt( sal_Int32 index, sal_Int32 count, const OString& newStr ) const SAL_THROW(())
1132 rtl_String* pNew = 0;
1133 rtl_string_newReplaceStrAt( &pNew, pData, index, count, newStr.pData );
1134 return OString( pNew, (DO_NOT_ACQUIRE*)0 );
1138 Returns a new string resulting from replacing all occurrences of
1139 oldChar in this string with newChar.
1141 If the character oldChar does not occur in the character sequence
1142 represented by this object, then the string is assigned with
1143 str.
1145 @param oldChar the old character.
1146 @param newChar the new character.
1147 @return a string derived from this string by replacing every
1148 occurrence of oldChar with newChar.
1150 SAL_WARN_UNUSED_RESULT OString replace( sal_Char oldChar, sal_Char newChar ) const SAL_THROW(())
1152 rtl_String* pNew = 0;
1153 rtl_string_newReplace( &pNew, pData, oldChar, newChar );
1154 return OString( pNew, (DO_NOT_ACQUIRE*)0 );
1158 Returns a new string resulting from replacing the first occurrence of a
1159 given substring with another substring.
1161 @param from the substring to be replaced
1163 @param to the replacing substring
1165 @param[in,out] index pointer to a start index; if the pointer is
1166 non-null: upon entry to the function, its value is the index into the this
1167 string at which to start searching for the \p from substring, the value
1168 must be non-negative and not greater than this string's length; upon exit
1169 from the function its value is the index into this string at which the
1170 replacement took place or -1 if no replacement took place; if the pointer
1171 is null, searching always starts at index 0
1173 @since LibreOffice 3.6
1175 SAL_WARN_UNUSED_RESULT OString replaceFirst(
1176 OString const & from, OString const & to, sal_Int32 * index = 0) const
1178 rtl_String * s = 0;
1179 sal_Int32 i = 0;
1180 rtl_string_newReplaceFirst(
1181 &s, pData, from.pData->buffer, from.pData->length,
1182 to.pData->buffer, to.pData->length, index == 0 ? &i : index);
1183 return OString(s, SAL_NO_ACQUIRE);
1187 Returns a new string resulting from replacing all occurrences of a given
1188 substring with another substring.
1190 Replacing subsequent occurrences picks up only after a given replacement.
1191 That is, replacing from "xa" to "xx" in "xaa" results in "xxa", not "xxx".
1193 @param from the substring to be replaced
1195 @param to the replacing substring
1197 @since LibreOffice 3.6
1199 SAL_WARN_UNUSED_RESULT OString replaceAll(OString const & from, OString const & to) const {
1200 rtl_String * s = 0;
1201 rtl_string_newReplaceAll(
1202 &s, pData, from.pData->buffer, from.pData->length,
1203 to.pData->buffer, to.pData->length);
1204 return OString(s, SAL_NO_ACQUIRE);
1208 Converts from this string all ASCII uppercase characters (65-90)
1209 to ASCII lowercase characters (97-122).
1211 This function can't be used for language specific conversion.
1212 If the string doesn't contain characters which must be converted,
1213 then the new string is assigned with str.
1215 @return the string, converted to ASCII lowercase.
1217 SAL_WARN_UNUSED_RESULT OString toAsciiLowerCase() const SAL_THROW(())
1219 rtl_String* pNew = 0;
1220 rtl_string_newToAsciiLowerCase( &pNew, pData );
1221 return OString( pNew, (DO_NOT_ACQUIRE*)0 );
1225 Converts from this string all ASCII lowercase characters (97-122)
1226 to ASCII uppercase characters (65-90).
1228 This function can't be used for language specific conversion.
1229 If the string doesn't contain characters which must be converted,
1230 then the new string is assigned with str.
1232 @return the string, converted to ASCII uppercase.
1234 SAL_WARN_UNUSED_RESULT OString toAsciiUpperCase() const SAL_THROW(())
1236 rtl_String* pNew = 0;
1237 rtl_string_newToAsciiUpperCase( &pNew, pData );
1238 return OString( pNew, (DO_NOT_ACQUIRE*)0 );
1242 Returns a new string resulting from removing white space from both ends
1243 of the string.
1245 All characters that have codes less than or equal to
1246 32 (the space character) are considered to be white space.
1247 If the string doesn't contain white spaces at both ends,
1248 then the new string is assigned with str.
1250 @return the string, with white space removed from the front and end.
1252 SAL_WARN_UNUSED_RESULT OString trim() const SAL_THROW(())
1254 rtl_String* pNew = 0;
1255 rtl_string_newTrim( &pNew, pData );
1256 return OString( pNew, (DO_NOT_ACQUIRE*)0 );
1260 Returns a token in the string.
1262 Example:
1263 sal_Int32 nIndex = 0;
1267 OString aToken = aStr.getToken( 0, ';', nIndex );
1270 while ( nIndex >= 0 );
1272 @param token the number of the token to return.
1273 @param cTok the character which separate the tokens.
1274 @param index the position at which the token is searched in the
1275 string.
1276 The index must not be greater thanthe length of the
1277 string.
1278 This param is set to the position of the
1279 next token or to -1, if it is the last token.
1280 @return the token; if either token or index is negative, an empty token
1281 is returned (and index is set to -1)
1283 OString getToken( sal_Int32 token, sal_Char cTok, sal_Int32& index ) const SAL_THROW(())
1285 rtl_String * pNew = 0;
1286 index = rtl_string_getToken( &pNew, pData, token, cTok, index );
1287 return OString( pNew, (DO_NOT_ACQUIRE *)0 );
1291 Returns a token from the string.
1293 The same as getToken(sal_Int32, sal_Char, sal_Int32 &), but always passing
1294 in 0 as the start index in the third argument.
1296 @param count the number of the token to return, starting with 0
1297 @param separator the character which separates the tokens
1299 @return the given token, or an empty string
1301 @since LibreOffice 3.6
1303 OString getToken(sal_Int32 count, char separator) const {
1304 sal_Int32 n = 0;
1305 return getToken(count, separator, n);
1309 Returns the Boolean value from this string.
1311 This function can't be used for language specific conversion.
1313 @return sal_True, if the string is 1 or "True" in any ASCII case.
1314 sal_False in any other case.
1316 sal_Bool toBoolean() const SAL_THROW(())
1318 return rtl_str_toBoolean( pData->buffer );
1322 Returns the first character from this string.
1324 @return the first character from this string or 0, if this string
1325 is emptry.
1327 sal_Char toChar() const SAL_THROW(())
1329 return pData->buffer[0];
1333 Returns the int32 value from this string.
1335 This function can't be used for language specific conversion.
1337 @param radix the radix (between 2 and 36)
1338 @return the int32 represented from this string.
1339 0 if this string represents no number.
1341 sal_Int32 toInt32( sal_Int16 radix = 10 ) const SAL_THROW(())
1343 return rtl_str_toInt32( pData->buffer, radix );
1347 Returns the int64 value from this string.
1349 This function can't be used for language specific conversion.
1351 @param radix the radix (between 2 and 36)
1352 @return the int64 represented from this string.
1353 0 if this string represents no number.
1355 sal_Int64 toInt64( sal_Int16 radix = 10 ) const SAL_THROW(())
1357 return rtl_str_toInt64( pData->buffer, radix );
1361 Returns the uint64 value from this string.
1363 This function can't be used for language specific conversion.
1365 @param radix the radix (between 2 and 36)
1366 @return the uint64 represented from this string.
1367 0 if this string represents no number or one of too large
1368 magnitude.
1370 @since LibreOffice 4.1
1372 sal_uInt64 toUInt64( sal_Int16 radix = 10 ) const SAL_THROW(())
1374 return rtl_str_toUInt64( pData->buffer, radix );
1378 Returns the float value from this string.
1380 This function can't be used for language specific conversion.
1382 @return the float represented from this string.
1383 0.0 if this string represents no number.
1385 float toFloat() const SAL_THROW(())
1387 return rtl_str_toFloat( pData->buffer );
1391 Returns the double value from this string.
1393 This function can't be used for language specific conversion.
1395 @return the double represented from this string.
1396 0.0 if this string represents no number.
1398 double toDouble() const SAL_THROW(())
1400 return rtl_str_toDouble( pData->buffer );
1404 Returns the string representation of the integer argument.
1406 This function can't be used for language specific conversion.
1408 @param i an integer value
1409 @param radix the radix (between 2 and 36)
1410 @return a string with the string representation of the argument.
1411 @since LibreOffice 4.1
1413 static OString number( int i, sal_Int16 radix = 10 )
1415 return number( static_cast< long long >( i ), radix );
1417 /// @overload
1418 /// @since LibreOffice 4.1
1419 static OString number( unsigned int i, sal_Int16 radix = 10 )
1421 return number( static_cast< unsigned long long >( i ), radix );
1423 /// @overload
1424 /// @since LibreOffice 4.1
1425 static OString number( long i, sal_Int16 radix = 10 )
1427 return number( static_cast< long long >( i ), radix );
1429 /// @overload
1430 /// @since LibreOffice 4.1
1431 static OString number( unsigned long i, sal_Int16 radix = 10 )
1433 return number( static_cast< unsigned long long >( i ), radix );
1435 /// @overload
1436 /// @since LibreOffice 4.1
1437 static OString number( long long ll, sal_Int16 radix = 10 )
1439 sal_Char aBuf[RTL_STR_MAX_VALUEOFINT64];
1440 rtl_String* pNewData = 0;
1441 rtl_string_newFromStr_WithLength( &pNewData, aBuf, rtl_str_valueOfInt64( aBuf, ll, radix ) );
1442 return OString( pNewData, (DO_NOT_ACQUIRE*)0 );
1444 /// @overload
1445 /// @since LibreOffice 4.1
1446 static OString number( unsigned long long ll, sal_Int16 radix = 10 )
1448 sal_Char aBuf[RTL_STR_MAX_VALUEOFUINT64];
1449 rtl_String* pNewData = 0;
1450 rtl_string_newFromStr_WithLength( &pNewData, aBuf, rtl_str_valueOfUInt64( aBuf, ll, radix ) );
1451 return OString( pNewData, (DO_NOT_ACQUIRE*)0 );
1455 Returns the string representation of the float argument.
1457 This function can't be used for language specific conversion.
1459 @param f a float.
1460 @return a string with the string representation of the argument.
1461 @since LibreOffice 4.1
1463 static OString number( float f )
1465 sal_Char aBuf[RTL_STR_MAX_VALUEOFFLOAT];
1466 rtl_String* pNewData = 0;
1467 rtl_string_newFromStr_WithLength( &pNewData, aBuf, rtl_str_valueOfFloat( aBuf, f ) );
1468 return OString( pNewData, (DO_NOT_ACQUIRE*)0 );
1472 Returns the string representation of the double argument.
1474 This function can't be used for language specific conversion.
1476 @param d a double.
1477 @return a string with the string representation of the argument.
1478 @since LibreOffice 4.1
1480 static OString number( double d )
1482 sal_Char aBuf[RTL_STR_MAX_VALUEOFDOUBLE];
1483 rtl_String* pNewData = 0;
1484 rtl_string_newFromStr_WithLength( &pNewData, aBuf, rtl_str_valueOfDouble( aBuf, d ) );
1485 return OString( pNewData, (DO_NOT_ACQUIRE*)0 );
1489 Returns the string representation of the sal_Bool argument.
1491 If the sal_Bool is true, the string "true" is returned.
1492 If the sal_Bool is false, the string "false" is returned.
1493 This function can't be used for language specific conversion.
1495 @param b a sal_Bool.
1496 @return a string with the string representation of the argument.
1497 @deprecated use boolean()
1499 SAL_DEPRECATED_INTERNAL("use boolean()") static OString valueOf( sal_Bool b ) SAL_THROW(())
1501 return boolean(b);
1505 Returns the string representation of the boolean argument.
1507 If the argument is true, the string "true" is returned.
1508 If the argument is false, the string "false" is returned.
1509 This function can't be used for language specific conversion.
1511 @param b a bool.
1512 @return a string with the string representation of the argument.
1513 @since LibreOffice 4.1
1515 static OString boolean( bool b ) SAL_THROW(())
1517 sal_Char aBuf[RTL_STR_MAX_VALUEOFBOOLEAN];
1518 rtl_String* pNewData = 0;
1519 rtl_string_newFromStr_WithLength( &pNewData, aBuf, rtl_str_valueOfBoolean( aBuf, b ) );
1520 return OString( pNewData, (DO_NOT_ACQUIRE*)0 );
1524 Returns the string representation of the char argument.
1526 @param c a character.
1527 @return a string with the string representation of the argument.
1528 @deprecated use operator, function or constructor taking char or sal_Unicode argument
1530 SAL_DEPRECATED_INTERNAL("convert to OString or use directly") static OString valueOf( sal_Char c ) SAL_THROW(())
1532 return OString( &c, 1 );
1536 Returns the string representation of the int argument.
1538 This function can't be used for language specific conversion.
1540 @param i a int32.
1541 @param radix the radix (between 2 and 36)
1542 @return a string with the string representation of the argument.
1543 @deprecated use number()
1545 SAL_DEPRECATED_INTERNAL("use number()") static OString valueOf( sal_Int32 i, sal_Int16 radix = 10 ) SAL_THROW(())
1547 return number( i, radix );
1551 Returns the string representation of the long argument.
1553 This function can't be used for language specific conversion.
1555 @param ll a int64.
1556 @param radix the radix (between 2 and 36)
1557 @return a string with the string representation of the argument.
1558 @deprecated use number()
1560 SAL_DEPRECATED_INTERNAL("use number()") static OString valueOf( sal_Int64 ll, sal_Int16 radix = 10 ) SAL_THROW(())
1562 return number( ll, radix );
1566 Returns the string representation of the float argument.
1568 This function can't be used for language specific conversion.
1570 @param f a float.
1571 @return a string with the string representation of the argument.
1572 @deprecated use number()
1574 SAL_DEPRECATED_INTERNAL("use number()") static OString valueOf( float f ) SAL_THROW(())
1576 return number(f);
1580 Returns the string representation of the double argument.
1582 This function can't be used for language specific conversion.
1584 @param d a double.
1585 @return a string with the string representation of the argument.
1586 @deprecated use number()
1588 SAL_DEPRECATED_INTERNAL("use number()") static OString valueOf( double d ) SAL_THROW(())
1590 return number(d);
1595 /* ======================================================================= */
1597 #ifdef RTL_FAST_STRING
1599 A simple wrapper around string literal. It is usually not necessary to use, can
1600 be mostly used to force OString operator+ working with operands that otherwise would
1601 not trigger it.
1603 This class is not part of public API and is meant to be used only in LibreOffice code.
1604 @since LibreOffice 4.0
1606 struct SAL_WARN_UNUSED OStringLiteral
1608 template< int N >
1609 OStringLiteral( const char (&str)[ N ] ) : size( N - 1 ), data( str ) { assert( strlen( str ) == N - 1 ); }
1610 int size;
1611 const char* data;
1615 @internal
1617 template<>
1618 struct ToStringHelper< OString >
1620 static int length( const OString& s ) { return s.getLength(); }
1621 static char* addData( char* buffer, const OString& s ) { return addDataHelper( buffer, s.getStr(), s.getLength()); }
1622 static const bool allowOStringConcat = true;
1623 static const bool allowOUStringConcat = false;
1627 @internal
1629 template<>
1630 struct ToStringHelper< OStringLiteral >
1632 static int length( const OStringLiteral& str ) { return str.size; }
1633 static char* addData( char* buffer, const OStringLiteral& str ) { return addDataHelper( buffer, str.data, str.size ); }
1634 static const bool allowOStringConcat = true;
1635 static const bool allowOUStringConcat = false;
1639 @internal
1641 template< typename charT, typename traits, typename T1, typename T2 >
1642 inline std::basic_ostream<charT, traits> & operator <<(
1643 std::basic_ostream<charT, traits> & stream, const OStringConcat< T1, T2 >& concat)
1645 return stream << OString( concat );
1647 #else
1648 // non-RTL_FAST_CODE needs this to compile
1649 typedef OString OStringLiteral;
1650 #endif
1653 /** A helper to use OStrings with hash maps.
1655 Instances of this class are unary function objects that can be used as
1656 hash function arguments to boost::unordered_map and similar constructs.
1658 struct OStringHash
1660 /** Compute a hash code for a string.
1662 @param rString
1663 a string.
1665 @return
1666 a hash code for the string. This hash code should not be stored
1667 persistently, as its computation may change in later revisions.
1669 size_t operator()( const OString& rString ) const
1670 { return (size_t)rString.hashCode(); }
1673 /** Equality functor for classic c-strings (i.e. null-terminated char* strings) */
1674 struct CStringEqual
1676 bool operator()( const char* p1, const char* p2) const
1677 { return rtl_str_compare(p1, p2) == 0; }
1680 /** Hashing functor for classic c-strings (i.e. null-terminated char* strings) */
1681 struct CStringHash
1683 size_t operator()(const char* p) const
1684 { return rtl_str_hashCode(p); }
1687 /* ======================================================================= */
1690 Support for rtl::OString in std::ostream (and thus in
1691 CPPUNIT_ASSERT or SAL_INFO macros, for example).
1693 @since LibreOffice 4.0
1695 template< typename charT, typename traits > std::basic_ostream<charT, traits> &
1696 operator <<(
1697 std::basic_ostream<charT, traits> & stream, OString const & string)
1699 return stream << string.getStr();
1700 // best effort; potentially loses data due to embedded null characters
1703 } /* Namespace */
1705 #ifdef RTL_STRING_UNITTEST
1706 namespace rtl
1708 typedef rtlunittest::OString OString;
1710 #undef RTL_STRING_CONST_FUNCTION
1711 #endif
1713 #ifdef RTL_USING
1714 using ::rtl::OString;
1715 using ::rtl::OStringHash;
1716 using ::rtl::OStringLiteral;
1717 #endif
1719 #endif /* _RTL_STRING_HXX_ */
1721 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */