LibreOffice
LibreOffice 5.0 SDK C/C++ API Reference
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
string.hxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
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/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
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 .
18  */
19 
20 #ifndef INCLUDED_RTL_STRING_HXX
21 #define INCLUDED_RTL_STRING_HXX
22 
23 #include <sal/config.h>
24 
25 #include <cassert>
26 #include <new>
27 #include <ostream>
28 #include <string.h>
29 
30 #include <rtl/textenc.h>
31 #include <rtl/string.h>
32 #include <rtl/stringutils.hxx>
33 
34 #ifdef LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
35 #include <rtl/stringconcat.hxx>
36 #endif
37 
38 #include <sal/log.hxx>
39 
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
47 #endif
48 
49 namespace rtl
50 {
51 
53 #ifdef RTL_STRING_UNITTEST
54 #undef rtl
55 // helper macro to make functions appear more readable
56 #define RTL_STRING_CONST_FUNCTION rtl_string_unittest_const_literal_function = true;
57 #else
58 #define RTL_STRING_CONST_FUNCTION
59 #endif
60 
62 /* ======================================================================= */
63 
88 class SAL_WARN_UNUSED SAL_DLLPUBLIC_RTTI OString
89 {
90 public:
92  rtl_String * pData;
94 
99  {
100  pData = 0;
101  rtl_string_new( &pData );
102  }
103 
109  OString( const OString & str )
110  {
111  pData = str.pData;
112  rtl_string_acquire( pData );
113  }
114 
120  OString( rtl_String * str )
121  {
122  pData = str;
123  rtl_string_acquire( pData );
124  }
125 
133  inline OString( rtl_String * str, __sal_NoAcquire )
134  {
135  pData = str;
136  }
137 
143  explicit OString( sal_Char value )
144  : pData (0)
145  {
146  rtl_string_newFromStr_WithLength( &pData, &value, 1 );
147  }
148 
157  template< typename T >
159  {
160  pData = 0;
161  rtl_string_newFromStr( &pData, value );
162  }
163 
164  template< typename T >
166  {
167  pData = 0;
168  rtl_string_newFromStr( &pData, value );
169  }
170 
181  template< typename T >
183  {
184  assert( strlen( literal ) == libreoffice_internal::ConstCharArrayDetector< T >::size - 1 );
185  pData = 0;
187  rtl_string_new( &pData );
188  else
190 #ifdef RTL_STRING_UNITTEST
191  rtl_string_unittest_const_literal = true;
192 #endif
193  }
194 
203  OString( const sal_Char * value, sal_Int32 length )
204  {
205  pData = 0;
206  rtl_string_newFromStr_WithLength( &pData, value, length );
207  }
208 
223  OString( const sal_Unicode * value, sal_Int32 length,
224  rtl_TextEncoding encoding,
225  sal_uInt32 convertFlags = OUSTRING_TO_OSTRING_CVTFLAGS )
226  {
227  pData = 0;
228  rtl_uString2String( &pData, value, length, encoding, convertFlags );
229  if (pData == 0) {
230  throw std::bad_alloc();
231  }
232  }
233 
234 #ifdef LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
235 
239  template< typename T1, typename T2 >
240  OString( const OStringConcat< T1, T2 >& c )
241  {
242  const sal_Int32 l = c.length();
243  pData = rtl_string_alloc( l );
244  if (l != 0)
245  {
246  char* end = c.addData( pData->buffer );
247  pData->length = end - pData->buffer;
248  *end = '\0';
249  }
250  }
251 #endif
252 
257  {
258  rtl_string_release( pData );
259  }
260 
266  OString & operator=( const OString & str )
267  {
268  rtl_string_assign( &pData, str.pData );
269  return *this;
270  }
271 
277  template< typename T >
279  {
280  RTL_STRING_CONST_FUNCTION
281  assert( strlen( literal ) == libreoffice_internal::ConstCharArrayDetector< T >::size - 1 );
283  rtl_string_new( &pData );
284  else
286  return *this;
287  }
288 
294  OString & operator+=( const OString & str )
295  {
296  rtl_string_newConcat( &pData, pData, str.pData );
297  return *this;
298  }
299 
300 #ifdef LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
301 
305  template< typename T1, typename T2 >
306  OString& operator+=( const OStringConcat< T1, T2 >& c )
307  {
308  const int l = c.length();
309  if( l == 0 )
310  return *this;
311  rtl_string_ensureCapacity( &pData, pData->length + l );
312  char* end = c.addData( pData->buffer + pData->length );
313  *end = '\0';
314  pData->length = end - pData->buffer;
315  return *this;
316  }
317 #endif
318 
323  void clear()
324  {
325  rtl_string_new( &pData );
326  }
327 
336  sal_Int32 getLength() const { return pData->length; }
337 
346  bool isEmpty() const
347  {
348  return pData->length == 0;
349  }
350 
362  const sal_Char * getStr() const { return pData->buffer; }
363 
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];
377  }
378 
391  sal_Int32 compareTo( const OString & str ) const
392  {
393  return rtl_str_compare_WithLength( pData->buffer, pData->length,
394  str.pData->buffer, str.pData->length );
395  }
396 
410  sal_Int32 compareTo( const OString & rObj, sal_Int32 maxLength ) const
411  {
412  return rtl_str_shortenedCompare_WithLength( pData->buffer, pData->length,
413  rObj.pData->buffer, rObj.pData->length, maxLength );
414  }
415 
428  sal_Int32 reverseCompareTo( const OString & str ) const
429  {
430  return rtl_str_reverseCompare_WithLength( pData->buffer, pData->length,
431  str.pData->buffer, str.pData->length );
432  }
433 
445  bool equals( const OString & str ) const
446  {
447  if ( pData->length != str.pData->length )
448  return false;
449  if ( pData == str.pData )
450  return true;
451  return rtl_str_reverseCompare_WithLength( pData->buffer, pData->length,
452  str.pData->buffer, str.pData->length ) == 0;
453  }
454 
470  bool equalsL( const sal_Char* value, sal_Int32 length ) const
471  {
472  if ( pData->length != length )
473  return false;
474 
475  return rtl_str_reverseCompare_WithLength( pData->buffer, pData->length,
476  value, length ) == 0;
477  }
478 
493  bool equalsIgnoreAsciiCase( const OString & str ) const
494  {
495  if ( pData->length != str.pData->length )
496  return false;
497  if ( pData == str.pData )
498  return true;
499  return rtl_str_compareIgnoreAsciiCase_WithLength( pData->buffer, pData->length,
500  str.pData->buffer, str.pData->length ) == 0;
501  }
502 
524  template< typename T >
526  {
527  return rtl_str_compareIgnoreAsciiCase( pData->buffer, asciiStr ) == 0;
528  }
529 
530  template< typename T >
532  {
533  return rtl_str_compareIgnoreAsciiCase( pData->buffer, asciiStr ) == 0;
534  }
535 
541  template< typename T >
543  {
544  RTL_STRING_CONST_FUNCTION
545  assert( strlen( literal ) == libreoffice_internal::ConstCharArrayDetector< T >::size - 1 );
547  return false;
548  return rtl_str_compareIgnoreAsciiCase_WithLength( pData->buffer, pData->length,
550  }
551 
571  bool equalsIgnoreAsciiCaseL( const sal_Char * asciiStr, sal_Int32 asciiStrLength ) const
572  {
573  if ( pData->length != asciiStrLength )
574  return false;
575 
576  return rtl_str_compareIgnoreAsciiCase_WithLength( pData->buffer, pData->length,
577  asciiStr, asciiStrLength ) == 0;
578  }
579 
595  bool match( const OString & str, sal_Int32 fromIndex = 0 ) const
596  {
597  return rtl_str_shortenedCompare_WithLength( pData->buffer+fromIndex, pData->length-fromIndex,
598  str.pData->buffer, str.pData->length, str.pData->length ) == 0;
599  }
600 
606  template< typename T >
607  typename libreoffice_internal::ConstCharArrayDetector< T, bool >::Type match( T& literal, sal_Int32 fromIndex = 0 ) const
608  {
609  RTL_STRING_CONST_FUNCTION
610  assert( strlen( literal ) == libreoffice_internal::ConstCharArrayDetector< T >::size - 1 );
612  pData->buffer + fromIndex, pData->length - fromIndex,
614  }
615 
632  bool matchL(
633  char const * str, sal_Int32 strLength, sal_Int32 fromIndex = 0)
634  const
635  {
637  pData->buffer + fromIndex, pData->length - fromIndex,
638  str, strLength, strLength) == 0;
639  }
640 
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
644  // platforms):
645 #if SAL_TYPES_SIZEOFLONG == 8
646  void matchL(char const *, sal_Int32, rtl_TextEncoding) const;
647 #endif
648 
667  bool matchIgnoreAsciiCase( const OString & str, sal_Int32 fromIndex = 0 ) const
668  {
669  return rtl_str_shortenedCompareIgnoreAsciiCase_WithLength( pData->buffer+fromIndex, pData->length-fromIndex,
670  str.pData->buffer, str.pData->length,
671  str.pData->length ) == 0;
672  }
673 
679  template< typename T >
680  typename libreoffice_internal::ConstCharArrayDetector< T, bool >::Type matchIgnoreAsciiCase( T& literal, sal_Int32 fromIndex = 0 ) const
681  {
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,
686  }
687 
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());
706  }
707  return b;
708  }
709 
715  template< typename T >
717  T & literal, OString * rest = 0) const
718  {
719  RTL_STRING_CONST_FUNCTION
720  bool b = match(literal, 0);
721  if (b && rest != 0) {
723  }
724  return b;
725  }
726 
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());
746  }
747  return b;
748  }
749 
755  template< typename T >
757  T & literal, OString * rest = 0) const
758  {
759  RTL_STRING_CONST_FUNCTION
760  assert( strlen( literal ) == libreoffice_internal::ConstCharArrayDetector< T >::size - 1 );
762  && match(literal, getLength() - ( libreoffice_internal::ConstCharArrayDetector< T, void >::size - 1 ));
763  if (b && rest != 0) {
764  *rest = copy(
765  0,
766  (getLength()
768  }
769  return b;
770  }
771 
785  bool endsWithL(char const * str, sal_Int32 strLength) const {
786  return strLength <= getLength()
787  && matchL(str, strLength, getLength() - strLength);
788  }
789 
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; }
802 
803  template< typename T >
804  friend typename libreoffice_internal::CharPtrDetector< T, bool >::Type operator==( const OString& rStr1, const T& value )
805  {
806  return rStr1.compareTo( value ) == 0;
807  }
808 
809  template< typename T >
811  {
812  return rStr1.compareTo( value ) == 0;
813  }
814 
815  template< typename T >
816  friend typename libreoffice_internal::CharPtrDetector< T, bool >::Type operator==( const T& value, const OString& rStr2 )
817  {
818  return rStr2.compareTo( value ) == 0;
819  }
820 
821  template< typename T >
823  {
824  return rStr2.compareTo( value ) == 0;
825  }
826 
832  template< typename T >
834  {
835  RTL_STRING_CONST_FUNCTION
836  assert( strlen( literal ) == libreoffice_internal::ConstCharArrayDetector< T >::size - 1 );
838  && rtl_str_compare_WithLength( rStr.pData->buffer, rStr.pData->length, literal,
840  }
841 
847  template< typename T >
849  {
850  RTL_STRING_CONST_FUNCTION
851  assert( strlen( literal ) == libreoffice_internal::ConstCharArrayDetector< T >::size - 1 );
853  && rtl_str_compare_WithLength( rStr.pData->buffer, rStr.pData->length, literal,
855  }
856 
857  template< typename T >
858  friend typename libreoffice_internal::CharPtrDetector< T, bool >::Type operator!=( const OString& rStr1, const T& value )
859  {
860  return !(operator == ( rStr1, value ));
861  }
862 
863  template< typename T >
865  {
866  return !(operator == ( rStr1, value ));
867  }
868 
869  template< typename T >
870  friend typename libreoffice_internal::CharPtrDetector< T, bool >::Type operator!=( const T& value, const OString& rStr2 )
871  {
872  return !(operator == ( value, rStr2 ));
873  }
874 
875  template< typename T >
877  {
878  return !(operator == ( value, rStr2 ));
879  }
880 
886  template< typename T >
888  {
889  return !( rStr == literal );
890  }
891 
897  template< typename T >
899  {
900  return !( literal == rStr );
901  }
902 
910  sal_Int32 hashCode() const
911  {
912  return rtl_str_hashCode_WithLength( pData->buffer, pData->length );
913  }
914 
928  sal_Int32 indexOf( sal_Char ch, sal_Int32 fromIndex = 0 ) const
929  {
930  sal_Int32 ret = rtl_str_indexOfChar_WithLength( pData->buffer+fromIndex, pData->length-fromIndex, ch );
931  return (ret < 0 ? ret : ret+fromIndex);
932  }
933 
943  sal_Int32 lastIndexOf( sal_Char ch ) const
944  {
945  return rtl_str_lastIndexOfChar_WithLength( pData->buffer, pData->length, ch );
946  }
947 
960  sal_Int32 lastIndexOf( sal_Char ch, sal_Int32 fromIndex ) const
961  {
962  return rtl_str_lastIndexOfChar_WithLength( pData->buffer, fromIndex, ch );
963  }
964 
980  sal_Int32 indexOf( const OString & str, sal_Int32 fromIndex = 0 ) const
981  {
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);
985  }
986 
992  template< typename T >
993  typename libreoffice_internal::ConstCharArrayDetector< T, sal_Int32 >::Type indexOf( T& literal, sal_Int32 fromIndex = 0 ) const
994  {
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;
1000  }
1001 
1020  sal_Int32 indexOfL(char const * str, sal_Int32 len, sal_Int32 fromIndex = 0)
1021  const
1022  {
1023  sal_Int32 n = rtl_str_indexOfStr_WithLength(
1024  pData->buffer + fromIndex, pData->length - fromIndex, str, len);
1025  return n < 0 ? n : n + fromIndex;
1026  }
1027 
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
1031  // platforms):
1032 #if SAL_TYPES_SIZEOFLONG == 8
1033  void indexOfL(char const *, sal_Int32, rtl_TextEncoding) const;
1034 #endif
1035 
1051  sal_Int32 lastIndexOf( const OString & str ) const
1052  {
1053  return rtl_str_lastIndexOfStr_WithLength( pData->buffer, pData->length,
1054  str.pData->buffer, str.pData->length );
1055  }
1056 
1074  sal_Int32 lastIndexOf( const OString & str, sal_Int32 fromIndex ) const
1075  {
1076  return rtl_str_lastIndexOfStr_WithLength( pData->buffer, fromIndex,
1077  str.pData->buffer, str.pData->length );
1078  }
1079 
1090  SAL_WARN_UNUSED_RESULT OString copy( sal_Int32 beginIndex ) const
1091  {
1092  rtl_String *pNew = 0;
1093  rtl_string_newFromSubString( &pNew, pData, beginIndex, getLength() - beginIndex );
1094  return OString( pNew, SAL_NO_ACQUIRE );
1095  }
1096 
1109  SAL_WARN_UNUSED_RESULT OString copy( sal_Int32 beginIndex, sal_Int32 count ) const
1110  {
1111  rtl_String *pNew = 0;
1112  rtl_string_newFromSubString( &pNew, pData, beginIndex, count );
1113  return OString( pNew, SAL_NO_ACQUIRE );
1114  }
1115 
1125  {
1126  rtl_String* pNew = 0;
1127  rtl_string_newConcat( &pNew, pData, str.pData );
1128  return OString( pNew, SAL_NO_ACQUIRE );
1129  }
1130 
1131 #ifndef LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
1132  friend OString operator+( const OString & str1, const OString & str2 )
1133  {
1134  return str1.concat( str2 );
1135  }
1136 #endif
1137 
1151  SAL_WARN_UNUSED_RESULT OString replaceAt( sal_Int32 index, sal_Int32 count, const OString& newStr ) const
1152  {
1153  rtl_String* pNew = 0;
1154  rtl_string_newReplaceStrAt( &pNew, pData, index, count, newStr.pData );
1155  return OString( pNew, SAL_NO_ACQUIRE );
1156  }
1157 
1172  {
1173  rtl_String* pNew = 0;
1174  rtl_string_newReplace( &pNew, pData, oldChar, newChar );
1175  return OString( pNew, SAL_NO_ACQUIRE );
1176  }
1177 
1197  OString const & from, OString const & to, sal_Int32 * index = 0) const
1198  {
1199  rtl_String * s = 0;
1200  sal_Int32 i = 0;
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);
1205  }
1206 
1220  SAL_WARN_UNUSED_RESULT OString replaceAll(OString const & from, OString const & to) const {
1221  rtl_String * s = 0;
1223  &s, pData, from.pData->buffer, from.pData->length,
1224  to.pData->buffer, to.pData->length);
1225  return OString(s, SAL_NO_ACQUIRE);
1226  }
1227 
1239  {
1240  rtl_String* pNew = 0;
1241  rtl_string_newToAsciiLowerCase( &pNew, pData );
1242  return OString( pNew, SAL_NO_ACQUIRE );
1243  }
1244 
1256  {
1257  rtl_String* pNew = 0;
1258  rtl_string_newToAsciiUpperCase( &pNew, pData );
1259  return OString( pNew, SAL_NO_ACQUIRE );
1260  }
1261 
1274  {
1275  rtl_String* pNew = 0;
1276  rtl_string_newTrim( &pNew, pData );
1277  return OString( pNew, SAL_NO_ACQUIRE );
1278  }
1279 
1304  OString getToken( sal_Int32 token, sal_Char cTok, sal_Int32& index ) const
1305  {
1306  rtl_String * pNew = 0;
1307  index = rtl_string_getToken( &pNew, pData, token, cTok, index );
1308  return OString( pNew, SAL_NO_ACQUIRE );
1309  }
1310 
1324  OString getToken(sal_Int32 count, char separator) const {
1325  sal_Int32 n = 0;
1326  return getToken(count, separator, n);
1327  }
1328 
1337  bool toBoolean() const
1338  {
1339  return rtl_str_toBoolean( pData->buffer );
1340  }
1341 
1349  {
1350  return pData->buffer[0];
1351  }
1352 
1363  sal_Int32 toInt32( sal_Int16 radix = 10 ) const
1364  {
1365  return rtl_str_toInt32( pData->buffer, radix );
1366  }
1367 
1380  sal_uInt32 toUInt32( sal_Int16 radix = 10 ) const
1381  {
1382  return rtl_str_toUInt32( pData->buffer, radix );
1383  }
1384 
1395  sal_Int64 toInt64( sal_Int16 radix = 10 ) const
1396  {
1397  return rtl_str_toInt64( pData->buffer, radix );
1398  }
1399 
1412  sal_uInt64 toUInt64( sal_Int16 radix = 10 ) const
1413  {
1414  return rtl_str_toUInt64( pData->buffer, radix );
1415  }
1416 
1425  float toFloat() const
1426  {
1427  return rtl_str_toFloat( pData->buffer );
1428  }
1429 
1438  double toDouble() const
1439  {
1440  return rtl_str_toDouble( pData->buffer );
1441  }
1442 
1453  static OString number( int i, sal_Int16 radix = 10 )
1454  {
1455  return number( static_cast< long long >( i ), radix );
1456  }
1459  static OString number( unsigned int i, sal_Int16 radix = 10 )
1460  {
1461  return number( static_cast< unsigned long long >( i ), radix );
1462  }
1465  static OString number( long i, sal_Int16 radix = 10 )
1466  {
1467  return number( static_cast< long long >( i ), radix );
1468  }
1471  static OString number( unsigned long i, sal_Int16 radix = 10 )
1472  {
1473  return number( static_cast< unsigned long long >( i ), radix );
1474  }
1477  static OString number( long long ll, sal_Int16 radix = 10 )
1478  {
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 );
1483  }
1486  static OString number( unsigned long long ll, sal_Int16 radix = 10 )
1487  {
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 );
1492  }
1493 
1503  static OString number( float f )
1504  {
1506  rtl_String* pNewData = 0;
1507  rtl_string_newFromStr_WithLength( &pNewData, aBuf, rtl_str_valueOfFloat( aBuf, f ) );
1508  return OString( pNewData, SAL_NO_ACQUIRE );
1509  }
1510 
1520  static OString number( double d )
1521  {
1523  rtl_String* pNewData = 0;
1524  rtl_string_newFromStr_WithLength( &pNewData, aBuf, rtl_str_valueOfDouble( aBuf, d ) );
1525  return OString( pNewData, SAL_NO_ACQUIRE );
1526  }
1527 
1539  SAL_DEPRECATED("use boolean()") static OString valueOf( sal_Bool b )
1540  {
1541  return boolean(b);
1542  }
1543 
1555  static OString boolean( bool b )
1556  {
1558  rtl_String* pNewData = 0;
1559  rtl_string_newFromStr_WithLength( &pNewData, aBuf, rtl_str_valueOfBoolean( aBuf, b ) );
1560  return OString( pNewData, SAL_NO_ACQUIRE );
1561  }
1562 
1570  SAL_DEPRECATED("convert to OString or use directly") static OString valueOf( sal_Char c )
1571  {
1572  return OString( &c, 1 );
1573  }
1574 
1585  SAL_DEPRECATED("use number()") static OString valueOf( sal_Int32 i, sal_Int16 radix = 10 )
1586  {
1587  return number( i, radix );
1588  }
1589 
1600  SAL_DEPRECATED("use number()") static OString valueOf( sal_Int64 ll, sal_Int16 radix = 10 )
1601  {
1602  return number( ll, radix );
1603  }
1604 
1614  SAL_DEPRECATED("use number()") static OString valueOf( float f )
1615  {
1616  return number(f);
1617  }
1618 
1628  SAL_DEPRECATED("use number()") static OString valueOf( double d )
1629  {
1630  return number(d);
1631  }
1632 
1633 };
1634 
1635 /* ======================================================================= */
1636 
1637 #ifdef LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
1638 
1646 struct SAL_WARN_UNUSED OStringLiteral
1647 {
1648  template< int N >
1649  explicit OStringLiteral( const char (&str)[ N ] ) : size( N - 1 ), data( str ) { assert( strlen( str ) == N - 1 ); }
1650  int size;
1651  const char* data;
1652 };
1653 
1657 template<>
1658 struct ToStringHelper< OString >
1659  {
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;
1664  };
1665 
1669 template<>
1670 struct ToStringHelper< OStringLiteral >
1671  {
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;
1676  };
1677 
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)
1684 {
1685  return stream << OString( concat );
1686 }
1687 #endif
1688 
1689 
1696 {
1706  size_t operator()( const OString& rString ) const
1707  { return (size_t)rString.hashCode(); }
1708 };
1709 
1712 {
1713  bool operator()( const char* p1, const char* p2) const
1714  { return rtl_str_compare(p1, p2) == 0; }
1715 };
1716 
1719 {
1720  size_t operator()(const char* p) const
1721  { return rtl_str_hashCode(p); }
1722 };
1723 
1724 /* ======================================================================= */
1725 
1732 template< typename charT, typename traits > std::basic_ostream<charT, traits> &
1734  std::basic_ostream<charT, traits> & stream, OString const & string)
1735 {
1736  return stream << string.getStr();
1737  // best effort; potentially loses data due to embedded null characters
1738 }
1739 
1740 } /* Namespace */
1741 
1742 #ifdef RTL_STRING_UNITTEST
1743 namespace rtl
1744 {
1745 typedef rtlunittest::OString OString;
1746 }
1747 #undef RTL_STRING_CONST_FUNCTION
1748 #endif
1749 
1750 #if defined LIBO_INTERNAL_ONLY && !defined RTL_STRING_UNITTEST
1751 using ::rtl::OString;
1752 using ::rtl::OStringHash;
1753 using ::rtl::OStringLiteral;
1754 #endif
1755 
1756 #endif // INCLUDED_RTL_STRING_HXX
1757 
1758 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */