Line data Source code
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 _RTL_USTRING_HXX_
21 : #define _RTL_USTRING_HXX_
22 :
23 : #include "sal/config.h"
24 :
25 : #include <cassert>
26 : #include <ostream>
27 : #include <string.h>
28 :
29 : #include "osl/diagnose.h"
30 : #include <rtl/ustring.h>
31 : #include <rtl/string.hxx>
32 : #include <rtl/stringutils.hxx>
33 : #include <rtl/textenc.h>
34 : #include "sal/log.hxx"
35 :
36 : #ifdef RTL_FAST_STRING
37 : #include <rtl/stringconcat.hxx>
38 : #endif
39 :
40 : #if defined EXCEPTIONS_OFF
41 : #include <stdlib.h>
42 : #else
43 : #include <new>
44 : #endif
45 :
46 : // The unittest uses slightly different code to help check that the proper
47 : // calls are made. The class is put into a different namespace to make
48 : // sure the compiler generates a different (if generating also non-inline)
49 : // copy of the function and does not merge them together. The class
50 : // is "brought" into the proper rtl namespace by a typedef below.
51 : #ifdef RTL_STRING_UNITTEST
52 : #define rtl rtlunittest
53 : #endif
54 :
55 : namespace rtl
56 : {
57 :
58 : #ifdef RTL_STRING_UNITTEST
59 : #undef rtl
60 : #endif
61 :
62 : /* ======================================================================= */
63 :
64 : /**
65 : This String class provides base functionality for C++ like Unicode
66 : character array handling. The advantage of this class is that it
67 : handles all the memory management for you - and it does it
68 : more efficiently. 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 : also stores the length of the string, so that many operations are
72 : faster than the C-str-functions.
73 :
74 : This class provides only readonly string handling. So you could create
75 : a string and you could only query the content from this string.
76 : It provides also functionality to change the string, but this results
77 : in every case in a new string instance (in the most cases with a
78 : memory allocation). You don't have functionality to change the
79 : content of the string. If you want to change the string content, then
80 : you should use the OStringBuffer class, which provides these
81 : functionalities and avoids too much memory allocation.
82 :
83 : The design of this class is similar to the string classes in Java so
84 : less people should have understanding problems when they use this class.
85 : */
86 :
87 : class SAL_WARN_UNUSED OUString
88 : {
89 : public:
90 : /// @cond INTERNAL
91 : rtl_uString * pData;
92 : /// @endcond
93 :
94 : /**
95 : New string containing no characters.
96 : */
97 103892906 : OUString() SAL_THROW(())
98 : {
99 103892906 : pData = 0;
100 103892906 : rtl_uString_new( &pData );
101 103892909 : }
102 :
103 : /**
104 : New string from OUString.
105 :
106 : @param str a OUString.
107 : */
108 153190674 : OUString( const OUString & str ) SAL_THROW(())
109 : {
110 153190674 : pData = str.pData;
111 153190674 : rtl_uString_acquire( pData );
112 153190675 : }
113 :
114 : /**
115 : New string from OUString data.
116 :
117 : @param str a OUString data.
118 : */
119 4469798 : OUString( rtl_uString * str ) SAL_THROW(())
120 : {
121 4469798 : pData = str;
122 4469798 : rtl_uString_acquire( pData );
123 4469798 : }
124 :
125 : /** New OUString from OUString data without acquiring it. Takeover of ownership.
126 :
127 : The SAL_NO_ACQUIRE dummy parameter is only there to distinguish this
128 : from other constructors.
129 :
130 : @param str
131 : OUString data
132 : */
133 53385760 : inline OUString( rtl_uString * str, __sal_NoAcquire ) SAL_THROW(())
134 53385760 : { pData = str; }
135 :
136 : /**
137 : New string from a single Unicode character.
138 :
139 : @param value a Unicode character.
140 : */
141 1489190 : explicit OUString( sal_Unicode value ) SAL_THROW(())
142 1489190 : : pData (0)
143 : {
144 1489190 : rtl_uString_newFromStr_WithLength( &pData, &value, 1 );
145 1489190 : }
146 :
147 : /**
148 : New string from a Unicode character buffer array.
149 :
150 : @param value a NULL-terminated Unicode character array.
151 : */
152 10876416 : OUString( const sal_Unicode * value ) SAL_THROW(())
153 : {
154 10876416 : pData = 0;
155 10876416 : rtl_uString_newFromStr( &pData, value );
156 10876416 : }
157 :
158 : /**
159 : New string from a Unicode character buffer array.
160 :
161 : @param value a Unicode character array.
162 : @param length the number of character which should be copied.
163 : The character array length must be greater than
164 : or equal to this value.
165 : */
166 2284231 : OUString( const sal_Unicode * value, sal_Int32 length ) SAL_THROW(())
167 : {
168 2284231 : pData = 0;
169 2284231 : rtl_uString_newFromStr_WithLength( &pData, value, length );
170 2284231 : }
171 :
172 : /**
173 : New string from an 8-Bit string literal that is expected to contain only
174 : characters in the ASCII set (i.e. first 128 characters). This constructor
175 : allows an efficient and convenient way to create OUString
176 : instances from ASCII literals. When creating strings from data that
177 : is not pure ASCII, it needs to be converted to OUString by explicitly
178 : providing the encoding to use for the conversion.
179 :
180 : If there are any embedded \0's in the string literal, the result is undefined.
181 : Use the overload that explicitly accepts length.
182 :
183 : @param literal the 8-bit ASCII string literal
184 :
185 : @since LibreOffice 3.6
186 : */
187 : template< typename T >
188 11526397 : OUString( T& literal, typename internal::ConstCharArrayDetector< T, internal::Dummy >::Type = internal::Dummy() )
189 : {
190 : assert( strlen( literal ) == internal::ConstCharArrayDetector< T >::size - 1 );
191 11526397 : pData = 0;
192 : if( internal::ConstCharArrayDetector< T, void >::size - 1 == 0 ) // empty string
193 21372 : rtl_uString_new( &pData );
194 : else
195 11505025 : rtl_uString_newFromLiteral( &pData, literal, internal::ConstCharArrayDetector< T, void >::size - 1, 0 );
196 : #ifdef RTL_STRING_UNITTEST
197 32 : rtl_string_unittest_const_literal = true;
198 : #endif
199 11526397 : }
200 :
201 : #ifdef RTL_STRING_UNITTEST
202 : /**
203 : * Only used by unittests to detect incorrect conversions.
204 : * @internal
205 : */
206 : template< typename T >
207 21 : OUString( T&, typename internal::ExceptConstCharArrayDetector< T >::Type = internal::Dummy() )
208 : {
209 21 : pData = 0;
210 21 : rtl_uString_newFromLiteral( &pData, "!!br0ken!!", 10, 0 ); // set to garbage
211 21 : rtl_string_unittest_invalid_conversion = true;
212 21 : }
213 : /**
214 : * Only used by unittests to detect incorrect conversions.
215 : * @internal
216 : */
217 : template< typename T >
218 2 : OUString( const T&, typename internal::ExceptCharArrayDetector< T >::Type = internal::Dummy() )
219 : {
220 2 : pData = 0;
221 2 : rtl_uString_newFromLiteral( &pData, "!!br0ken!!", 10, 0 ); // set to garbage
222 2 : rtl_string_unittest_invalid_conversion = true;
223 2 : }
224 : #endif
225 :
226 : /**
227 : New string from an 8-Bit character buffer array.
228 :
229 : @param value An 8-Bit character array.
230 : @param length The number of character which should be converted.
231 : The 8-Bit character array length must be
232 : greater than or equal to this value.
233 : @param encoding The text encoding from which the 8-Bit character
234 : sequence should be converted.
235 : @param convertFlags Flags which control the conversion.
236 : see RTL_TEXTTOUNICODE_FLAGS_...
237 :
238 : @exception std::bad_alloc is thrown if an out-of-memory condition occurs
239 : */
240 5968694 : OUString( const sal_Char * value, sal_Int32 length,
241 : rtl_TextEncoding encoding,
242 : sal_uInt32 convertFlags = OSTRING_TO_OUSTRING_CVTFLAGS )
243 : {
244 5968694 : pData = 0;
245 5968694 : rtl_string2UString( &pData, value, length, encoding, convertFlags );
246 5968694 : if (pData == 0) {
247 : #if defined EXCEPTIONS_OFF
248 : abort();
249 : #else
250 0 : throw std::bad_alloc();
251 : #endif
252 : }
253 5968694 : }
254 :
255 : /** Create a new string from an array of Unicode code points.
256 :
257 : @param codePoints
258 : an array of at least codePointCount code points, which each must be in
259 : the range from 0 to 0x10FFFF, inclusive. May be null if codePointCount
260 : is zero.
261 :
262 : @param codePointCount
263 : the non-negative number of code points.
264 :
265 : @exception std::bad_alloc
266 : is thrown if either an out-of-memory condition occurs or the resulting
267 : number of UTF-16 code units would have been larger than SAL_MAX_INT32.
268 :
269 : @since UDK 3.2.7
270 : */
271 21388 : inline explicit OUString(
272 : sal_uInt32 const * codePoints, sal_Int32 codePointCount):
273 21388 : pData(NULL)
274 : {
275 21388 : rtl_uString_newFromCodePoints(&pData, codePoints, codePointCount);
276 21388 : if (pData == NULL) {
277 : #if defined EXCEPTIONS_OFF
278 : abort();
279 : #else
280 0 : throw std::bad_alloc();
281 : #endif
282 : }
283 21388 : }
284 :
285 : #ifdef RTL_FAST_STRING
286 : /**
287 : @overload
288 : @internal
289 : */
290 : template< typename T1, typename T2 >
291 2641150 : OUString( const OUStringConcat< T1, T2 >& c )
292 : {
293 2641150 : const sal_Int32 l = c.length();
294 2641150 : pData = rtl_uString_alloc( l );
295 2641150 : if (l != 0)
296 : {
297 2641147 : sal_Unicode* end = c.addData( pData->buffer );
298 2641147 : pData->length = end - pData->buffer;
299 2641147 : *end = '\0';
300 : // TODO realloc in case pData->length is noticeably smaller than l?
301 : }
302 2641150 : }
303 : #endif
304 :
305 : /**
306 : Release the string data.
307 : */
308 348377478 : ~OUString() SAL_THROW(())
309 : {
310 348377478 : rtl_uString_release( pData );
311 348377493 : }
312 :
313 : /** Provides an OUString const & passing a storage pointer of an
314 : rtl_uString * handle.
315 : It is more convenient to use C++ OUString member functions when dealing
316 : with rtl_uString * handles. Using this function avoids unnecessary
317 : acquire()/release() calls for a temporary OUString object.
318 :
319 : @param ppHandle
320 : pointer to storage
321 : @return
322 : OUString const & based on given storage
323 : */
324 3103575 : static inline OUString const & unacquired( rtl_uString * const * ppHandle )
325 3103575 : { return * reinterpret_cast< OUString const * >( ppHandle ); }
326 :
327 : /**
328 : Assign a new string.
329 :
330 : @param str a OUString.
331 : */
332 93238358 : OUString & operator=( const OUString & str ) SAL_THROW(())
333 : {
334 93238358 : rtl_uString_assign( &pData, str.pData );
335 93238358 : return *this;
336 : }
337 :
338 : /**
339 : Assign a new string from an 8-Bit string literal that is expected to contain only
340 : characters in the ASCII set (i.e. first 128 characters). This operator
341 : allows an efficient and convenient way to assign OUString
342 : instances from ASCII literals. When assigning strings from data that
343 : is not pure ASCII, it needs to be converted to OUString by explicitly
344 : providing the encoding to use for the conversion.
345 :
346 : @param literal the 8-bit ASCII string literal
347 :
348 : @since LibreOffice 3.6
349 : */
350 : template< typename T >
351 2168652 : typename internal::ConstCharArrayDetector< T, OUString& >::Type operator=( T& literal )
352 : {
353 : assert( strlen( literal ) == internal::ConstCharArrayDetector< T >::size - 1 );
354 : if( internal::ConstCharArrayDetector< T, void >::size - 1 == 0 ) // empty string
355 1605223 : rtl_uString_new( &pData );
356 : else
357 563429 : rtl_uString_newFromLiteral( &pData, literal, internal::ConstCharArrayDetector< T, void >::size - 1, 0 );
358 2168652 : return *this;
359 : }
360 :
361 : /**
362 : Append a string to this string.
363 :
364 : @param str a OUString.
365 : */
366 3528007 : OUString & operator+=( const OUString & str ) SAL_THROW(())
367 : {
368 3528007 : rtl_uString_newConcat( &pData, pData, str.pData );
369 3528007 : return *this;
370 : }
371 :
372 : #ifdef RTL_FAST_STRING
373 : /**
374 : @overload
375 : @internal
376 : */
377 : template< typename T1, typename T2 >
378 3211 : OUString& operator+=( const OUStringConcat< T1, T2 >& c )
379 : {
380 3211 : const int l = c.length();
381 3211 : if( l == 0 )
382 0 : return *this;
383 3211 : rtl_uString_ensureCapacity( &pData, pData->length + l );
384 3211 : sal_Unicode* end = c.addData( pData->buffer + pData->length );
385 3211 : *end = '\0';
386 3211 : pData->length = end - pData->buffer;
387 3211 : return *this;
388 : }
389 : #endif
390 :
391 : /**
392 : Returns the length of this string.
393 :
394 : The length is equal to the number of Unicode characters in this string.
395 :
396 : @return the length of the sequence of characters represented by this
397 : object.
398 : */
399 157130182 : sal_Int32 getLength() const SAL_THROW(()) { return pData->length; }
400 :
401 : /**
402 : Checks if a string is empty.
403 :
404 : @return true if the string is empty;
405 : false, otherwise.
406 :
407 : @since LibreOffice 3.4
408 : */
409 27891641 : bool isEmpty() const SAL_THROW(())
410 : {
411 27891641 : return pData->length == 0;
412 : }
413 :
414 : /**
415 : Returns a pointer to the Unicode character buffer for this string.
416 :
417 : It isn't necessarily NULL terminated.
418 :
419 : @return a pointer to the Unicode characters buffer for this object.
420 : */
421 264830532 : const sal_Unicode * getStr() const SAL_THROW(()) { return pData->buffer; }
422 :
423 : /**
424 : Access to individual characters.
425 :
426 : @param index must be non-negative and less than length.
427 :
428 : @return the character at the given index.
429 :
430 : @since LibreOffice 3.5
431 : */
432 223640951 : sal_Unicode operator [](sal_Int32 index) const {
433 : assert(index >= 0 && index <= getLength());
434 : //TODO: should really check for < getLength(), but there is quite
435 : // some clever code out there that violates this function's
436 : // documented precondition and relies on s[s.getLength()] == 0 and
437 : // that would need to be fixed first
438 223640951 : return getStr()[index];
439 : }
440 :
441 : /**
442 : Compares two strings.
443 :
444 : The comparison is based on the numeric value of each character in
445 : the strings and return a value indicating their relationship.
446 : This function can't be used for language specific sorting.
447 :
448 : @param str the object to be compared.
449 : @return 0 - if both strings are equal
450 : < 0 - if this string is less than the string argument
451 : > 0 - if this string is greater than the string argument
452 : */
453 128177607 : sal_Int32 compareTo( const OUString & str ) const SAL_THROW(())
454 : {
455 : return rtl_ustr_compare_WithLength( pData->buffer, pData->length,
456 128177607 : str.pData->buffer, str.pData->length );
457 : }
458 :
459 : /**
460 : Compares two strings with a maximum count of characters.
461 :
462 : The comparison is based on the numeric value of each character in
463 : the strings and return a value indicating their relationship.
464 : This function can't be used for language specific sorting.
465 :
466 : @param str the object to be compared.
467 : @param maxLength the maximum count of characters to be compared.
468 : @return 0 - if both strings are equal
469 : < 0 - if this string is less than the string argument
470 : > 0 - if this string is greater than the string argument
471 :
472 : @since UDK 3.2.7
473 : */
474 5243 : sal_Int32 compareTo( const OUString & str, sal_Int32 maxLength ) const SAL_THROW(())
475 : {
476 : return rtl_ustr_shortenedCompare_WithLength( pData->buffer, pData->length,
477 5243 : str.pData->buffer, str.pData->length, maxLength );
478 : }
479 :
480 : /**
481 : Compares two strings in reverse order.
482 :
483 : The comparison is based on the numeric value of each character in
484 : the strings and return a value indicating their relationship.
485 : This function can't be used for language specific sorting.
486 :
487 : @param str the object to be compared.
488 : @return 0 - if both strings are equal
489 : < 0 - if this string is less than the string argument
490 : > 0 - if this string is greater than the string argument
491 : */
492 0 : sal_Int32 reverseCompareTo( const OUString & str ) const SAL_THROW(())
493 : {
494 : return rtl_ustr_reverseCompare_WithLength( pData->buffer, pData->length,
495 0 : str.pData->buffer, str.pData->length );
496 : }
497 :
498 : /**
499 : @overload
500 : This function accepts an ASCII string literal as its argument.
501 : @since LibreOffice 4.1
502 : */
503 : template< typename T >
504 12226 : typename internal::ConstCharArrayDetector< T, sal_Int32 >::Type reverseCompareTo( T& literal ) const SAL_THROW(())
505 : {
506 : assert( strlen( literal ) == internal::ConstCharArrayDetector< T >::size - 1 );
507 : return rtl_ustr_asciil_reverseCompare_WithLength( pData->buffer, pData->length,
508 12226 : literal, internal::ConstCharArrayDetector< T, void >::size - 1 );
509 : }
510 :
511 : /**
512 : Perform a comparison of two strings.
513 :
514 : The result is true if and only if second string
515 : represents the same sequence of characters as the first string.
516 : This function can't be used for language specific comparison.
517 :
518 : @param str the object to be compared.
519 : @return sal_True if the strings are equal;
520 : sal_False, otherwise.
521 : */
522 114269345 : sal_Bool equals( const OUString & str ) const SAL_THROW(())
523 : {
524 114269345 : if ( pData->length != str.pData->length )
525 81419822 : return sal_False;
526 32849523 : if ( pData == str.pData )
527 15649772 : return sal_True;
528 : return rtl_ustr_reverseCompare_WithLength( pData->buffer, pData->length,
529 17199751 : str.pData->buffer, str.pData->length ) == 0;
530 : }
531 :
532 : /**
533 : Perform a ASCII lowercase comparison of two strings.
534 :
535 : The result is true if and only if second string
536 : represents the same sequence of characters as the first string,
537 : ignoring the case.
538 : Character values between 65 and 90 (ASCII A-Z) are interpreted as
539 : values between 97 and 122 (ASCII a-z).
540 : This function can't be used for language specific comparison.
541 :
542 : @param str the object to be compared.
543 : @return sal_True if the strings are equal;
544 : sal_False, otherwise.
545 : */
546 846336 : sal_Bool equalsIgnoreAsciiCase( const OUString & str ) const SAL_THROW(())
547 : {
548 846336 : if ( pData->length != str.pData->length )
549 623232 : return sal_False;
550 223104 : if ( pData == str.pData )
551 42979 : return sal_True;
552 : return rtl_ustr_compareIgnoreAsciiCase_WithLength( pData->buffer, pData->length,
553 180125 : str.pData->buffer, str.pData->length ) == 0;
554 : }
555 :
556 : /**
557 : Perform a ASCII lowercase comparison of two strings.
558 :
559 : Compare the two strings with uppercase ASCII
560 : character values between 65 and 90 (ASCII A-Z) interpreted as
561 : values between 97 and 122 (ASCII a-z).
562 : This function can't be used for language specific comparison.
563 :
564 : @param str the object to be compared.
565 : @return 0 - if both strings are equal
566 : < 0 - if this string is less than the string argument
567 : > 0 - if this string is greater than the string argument
568 :
569 : @since LibreOffice 4.0
570 : */
571 3 : sal_Int32 compareToIgnoreAsciiCase( const OUString & str ) const SAL_THROW(())
572 : {
573 : return rtl_ustr_compareIgnoreAsciiCase_WithLength( pData->buffer, pData->length,
574 3 : str.pData->buffer, str.pData->length );
575 : }
576 :
577 :
578 : /**
579 : @overload
580 : This function accepts an ASCII string literal as its argument.
581 : @since LibreOffice 3.6
582 : */
583 : template< typename T >
584 1451372 : typename internal::ConstCharArrayDetector< T, bool >::Type equalsIgnoreAsciiCase( T& literal ) const SAL_THROW(())
585 : {
586 : assert( strlen( literal ) == internal::ConstCharArrayDetector< T >::size - 1 );
587 1451372 : if ( pData->length != internal::ConstCharArrayDetector< T, void >::size - 1 )
588 1129013 : return sal_False;
589 :
590 322359 : return rtl_ustr_ascii_compareIgnoreAsciiCase_WithLength( pData->buffer, pData->length, literal ) == 0;
591 : }
592 :
593 : /**
594 : Match against a substring appearing in this string.
595 :
596 : The result is true if and only if the second string appears as a substring
597 : of this string, at the given position.
598 : This function can't be used for language specific comparison.
599 :
600 : @param str the object (substring) to be compared.
601 : @param fromIndex the index to start the comparion from.
602 : The index must be greater than or equal to 0
603 : and less or equal as the string length.
604 : @return sal_True if str match with the characters in the string
605 : at the given position;
606 : sal_False, otherwise.
607 : */
608 4370780 : sal_Bool match( const OUString & str, sal_Int32 fromIndex = 0 ) const SAL_THROW(())
609 : {
610 4370780 : return rtl_ustr_shortenedCompare_WithLength( pData->buffer+fromIndex, pData->length-fromIndex,
611 8741560 : str.pData->buffer, str.pData->length, str.pData->length ) == 0;
612 : }
613 :
614 : /**
615 : @overload
616 : This function accepts an ASCII string literal as its argument.
617 : @since LibreOffice 3.6
618 : */
619 : template< typename T >
620 1103107 : typename internal::ConstCharArrayDetector< T, bool >::Type match( T& literal, sal_Int32 fromIndex = 0 ) const SAL_THROW(())
621 : {
622 : assert( strlen( literal ) == internal::ConstCharArrayDetector< T >::size - 1 );
623 1103107 : return rtl_ustr_ascii_shortenedCompare_WithLength( pData->buffer+fromIndex, pData->length-fromIndex,
624 2206214 : literal, internal::ConstCharArrayDetector< T, void >::size - 1 ) == 0;
625 : }
626 :
627 : /**
628 : Match against a substring appearing in this string, ignoring the case of
629 : ASCII letters.
630 :
631 : The result is true if and only if the second string appears as a substring
632 : of this string, at the given position.
633 : Character values between 65 and 90 (ASCII A-Z) are interpreted as
634 : values between 97 and 122 (ASCII a-z).
635 : This function can't be used for language specific comparison.
636 :
637 : @param str the object (substring) to be compared.
638 : @param fromIndex the index to start the comparion from.
639 : The index must be greater than or equal to 0
640 : and less than or equal to the string length.
641 : @return sal_True if str match with the characters in the string
642 : at the given position;
643 : sal_False, otherwise.
644 : */
645 30742 : sal_Bool matchIgnoreAsciiCase( const OUString & str, sal_Int32 fromIndex = 0 ) const SAL_THROW(())
646 : {
647 30742 : return rtl_ustr_shortenedCompareIgnoreAsciiCase_WithLength( pData->buffer+fromIndex, pData->length-fromIndex,
648 : str.pData->buffer, str.pData->length,
649 61484 : str.pData->length ) == 0;
650 : }
651 :
652 : /**
653 : @overload
654 : This function accepts an ASCII string literal as its argument.
655 : @since LibreOffice 3.6
656 : */
657 : template< typename T >
658 2115 : typename internal::ConstCharArrayDetector< T, bool >::Type matchIgnoreAsciiCase( T& literal, sal_Int32 fromIndex = 0 ) const SAL_THROW(())
659 : {
660 : assert( strlen( literal ) == internal::ConstCharArrayDetector< T >::size - 1 );
661 2115 : return rtl_ustr_ascii_shortenedCompareIgnoreAsciiCase_WithLength( pData->buffer+fromIndex, pData->length-fromIndex,
662 4230 : literal, internal::ConstCharArrayDetector< T, void >::size - 1 ) == 0;
663 : }
664 :
665 : /**
666 : Compares two strings.
667 :
668 : The comparison is based on the numeric value of each character in
669 : the strings and return a value indicating their relationship.
670 : Since this method is optimized for performance, the ASCII character
671 : values are not converted in any way. The caller has to make sure that
672 : all ASCII characters are in the allowed range between 0 and
673 : 127. The ASCII string must be NULL-terminated.
674 : This function can't be used for language specific sorting.
675 :
676 : @param asciiStr the 8-Bit ASCII character string to be compared.
677 : @return 0 - if both strings are equal
678 : < 0 - if this string is less than the string argument
679 : > 0 - if this string is greater than the string argument
680 : */
681 1677788 : sal_Int32 compareToAscii( const sal_Char* asciiStr ) const SAL_THROW(())
682 : {
683 1677788 : return rtl_ustr_ascii_compare_WithLength( pData->buffer, pData->length, asciiStr );
684 : }
685 :
686 : /**
687 : Compares two strings with a maximum count of characters.
688 :
689 : The comparison is based on the numeric value of each character in
690 : the strings and return a value indicating their relationship.
691 : Since this method is optimized for performance, the ASCII character
692 : values are not converted in any way. The caller has to make sure that
693 : all ASCII characters are in the allowed range between 0 and
694 : 127. The ASCII string must be NULL-terminated.
695 : This function can't be used for language specific sorting.
696 :
697 : @deprecated This is a confusing overload with unexpectedly different
698 : semantics from the one-parameter form, so it is marked as deprecated.
699 : Practically all uses compare the return value against zero and can thus
700 : be replaced with uses of startsWith.
701 :
702 : @param asciiStr the 8-Bit ASCII character string to be compared.
703 : @param maxLength the maximum count of characters to be compared.
704 : @return 0 - if both strings are equal
705 : < 0 - if this string is less than the string argument
706 : > 0 - if this string is greater than the string argument
707 : */
708 : SAL_DEPRECATED(
709 : "replace s1.compareToAscii(s2, strlen(s2)) == 0 with s1.startsWith(s2)")
710 : sal_Int32 compareToAscii( const sal_Char * asciiStr, sal_Int32 maxLength ) const SAL_THROW(())
711 : {
712 : return rtl_ustr_ascii_shortenedCompare_WithLength( pData->buffer, pData->length,
713 : asciiStr, maxLength );
714 : }
715 :
716 : /**
717 : Compares two strings in reverse order.
718 :
719 : This could be useful, if normally both strings start with the same
720 : content. The comparison is based on the numeric value of each character
721 : in the strings and return a value indicating their relationship.
722 : Since this method is optimized for performance, the ASCII character
723 : values are not converted in any way. The caller has to make sure that
724 : all ASCII characters are in the allowed range between 0 and 127.
725 : The ASCII string must be NULL-terminated and must be greater than
726 : or equal to asciiStrLength.
727 : This function can't be used for language specific sorting.
728 :
729 : @param asciiStr the 8-Bit ASCII character string to be compared.
730 : @param asciiStrLength the length of the ascii string
731 : @return 0 - if both strings are equal
732 : < 0 - if this string is less than the string argument
733 : > 0 - if this string is greater than the string argument
734 : */
735 386919 : sal_Int32 reverseCompareToAsciiL( const sal_Char * asciiStr, sal_Int32 asciiStrLength ) const SAL_THROW(())
736 : {
737 : return rtl_ustr_asciil_reverseCompare_WithLength( pData->buffer, pData->length,
738 386919 : asciiStr, asciiStrLength );
739 : }
740 :
741 : /**
742 : Perform a comparison of two strings.
743 :
744 : The result is true if and only if second string
745 : represents the same sequence of characters as the first string.
746 : Since this method is optimized for performance, the ASCII character
747 : values are not converted in any way. The caller has to make sure that
748 : all ASCII characters are in the allowed range between 0 and
749 : 127. The ASCII string must be NULL-terminated.
750 : This function can't be used for language specific comparison.
751 :
752 : @param asciiStr the 8-Bit ASCII character string to be compared.
753 : @return sal_True if the strings are equal;
754 : sal_False, otherwise.
755 : */
756 189316193 : sal_Bool equalsAscii( const sal_Char* asciiStr ) const SAL_THROW(())
757 : {
758 : return rtl_ustr_ascii_compare_WithLength( pData->buffer, pData->length,
759 189316193 : asciiStr ) == 0;
760 : }
761 :
762 : /**
763 : Perform a comparison of two strings.
764 :
765 : The result is true if and only if second string
766 : represents the same sequence of characters as the first string.
767 : Since this method is optimized for performance, the ASCII character
768 : values are not converted in any way. The caller has to make sure that
769 : all ASCII characters are in the allowed range between 0 and
770 : 127. The ASCII string must be NULL-terminated and must be greater than
771 : or equal to asciiStrLength.
772 : This function can't be used for language specific comparison.
773 :
774 : @param asciiStr the 8-Bit ASCII character string to be compared.
775 : @param asciiStrLength the length of the ascii string
776 : @return sal_True if the strings are equal;
777 : sal_False, otherwise.
778 : */
779 49646950 : sal_Bool equalsAsciiL( const sal_Char* asciiStr, sal_Int32 asciiStrLength ) const SAL_THROW(())
780 : {
781 49646950 : if ( pData->length != asciiStrLength )
782 39004825 : return sal_False;
783 :
784 : return rtl_ustr_asciil_reverseEquals_WithLength(
785 10642125 : pData->buffer, asciiStr, asciiStrLength );
786 : }
787 :
788 : /**
789 : Perform a ASCII lowercase comparison of two strings.
790 :
791 : The result is true if and only if second string
792 : represents the same sequence of characters as the first string,
793 : ignoring the case.
794 : Character values between 65 and 90 (ASCII A-Z) are interpreted as
795 : values between 97 and 122 (ASCII a-z).
796 : Since this method is optimized for performance, the ASCII character
797 : values are not converted in any way. The caller has to make sure that
798 : all ASCII characters are in the allowed range between 0 and
799 : 127. The ASCII string must be NULL-terminated.
800 : This function can't be used for language specific comparison.
801 :
802 : @param asciiStr the 8-Bit ASCII character string to be compared.
803 : @return sal_True if the strings are equal;
804 : sal_False, otherwise.
805 : */
806 814745 : sal_Bool equalsIgnoreAsciiCaseAscii( const sal_Char * asciiStr ) const SAL_THROW(())
807 : {
808 814745 : return rtl_ustr_ascii_compareIgnoreAsciiCase_WithLength( pData->buffer, pData->length, asciiStr ) == 0;
809 : }
810 :
811 : /**
812 : Compares two ASCII strings ignoring case
813 :
814 : The comparison is based on the numeric value of each character in
815 : the strings and return a value indicating their relationship.
816 : Since this method is optimized for performance, the ASCII character
817 : values are not converted in any way. The caller has to make sure that
818 : all ASCII characters are in the allowed range between 0 and
819 : 127. The ASCII string must be NULL-terminated.
820 : This function can't be used for language specific sorting.
821 :
822 : @param asciiStr the 8-Bit ASCII character string to be compared.
823 : @return 0 - if both strings are equal
824 : < 0 - if this string is less than the string argument
825 : > 0 - if this string is greater than the string argument
826 :
827 : @since LibreOffice 3.5
828 : */
829 652364 : sal_Int32 compareToIgnoreAsciiCaseAscii( const sal_Char * asciiStr ) const SAL_THROW(())
830 : {
831 652364 : return rtl_ustr_ascii_compareIgnoreAsciiCase_WithLength( pData->buffer, pData->length, asciiStr );
832 : }
833 :
834 : /**
835 : Perform an ASCII lowercase comparison of two strings.
836 :
837 : The result is true if and only if second string
838 : represents the same sequence of characters as the first string,
839 : ignoring the case.
840 : Character values between 65 and 90 (ASCII A-Z) are interpreted as
841 : values between 97 and 122 (ASCII a-z).
842 : Since this method is optimized for performance, the ASCII character
843 : values are not converted in any way. The caller has to make sure that
844 : all ASCII characters are in the allowed range between 0 and 127.
845 : The ASCII string must be NULL-terminated and must be greater than
846 : or equal to asciiStrLength.
847 : This function can't be used for language specific comparison.
848 :
849 : @param asciiStr the 8-Bit ASCII character string to be compared.
850 : @param asciiStrLength the length of the ascii string
851 : @return sal_True if the strings are equal;
852 : sal_False, otherwise.
853 : */
854 114690 : sal_Bool equalsIgnoreAsciiCaseAsciiL( const sal_Char * asciiStr, sal_Int32 asciiStrLength ) const SAL_THROW(())
855 : {
856 114690 : if ( pData->length != asciiStrLength )
857 707 : return sal_False;
858 :
859 113983 : return rtl_ustr_ascii_compareIgnoreAsciiCase_WithLength( pData->buffer, pData->length, asciiStr ) == 0;
860 : }
861 :
862 : /**
863 : Match against a substring appearing in this string.
864 :
865 : The result is true if and only if the second string appears as a substring
866 : of this string, at the given position.
867 : Since this method is optimized for performance, the ASCII character
868 : values are not converted in any way. The caller has to make sure that
869 : all ASCII characters are in the allowed range between 0 and
870 : 127. The ASCII string must be NULL-terminated and must be greater than or
871 : equal to asciiStrLength.
872 : This function can't be used for language specific comparison.
873 :
874 : @param asciiStr the object (substring) to be compared.
875 : @param asciiStrLength the length of asciiStr.
876 : @param fromIndex the index to start the comparion from.
877 : The index must be greater than or equal to 0
878 : and less than or equal to the string length.
879 : @return sal_True if str match with the characters in the string
880 : at the given position;
881 : sal_False, otherwise.
882 : */
883 73861 : sal_Bool matchAsciiL( const sal_Char* asciiStr, sal_Int32 asciiStrLength, sal_Int32 fromIndex = 0 ) const SAL_THROW(())
884 : {
885 73861 : return rtl_ustr_ascii_shortenedCompare_WithLength( pData->buffer+fromIndex, pData->length-fromIndex,
886 147722 : asciiStr, asciiStrLength ) == 0;
887 : }
888 :
889 : // This overload is left undefined, to detect calls of matchAsciiL that
890 : // erroneously use RTL_CONSTASCII_USTRINGPARAM instead of
891 : // RTL_CONSTASCII_STRINGPARAM (but would lead to ambiguities on 32 bit
892 : // platforms):
893 : #if SAL_TYPES_SIZEOFLONG == 8
894 : void matchAsciiL(char const *, sal_Int32, rtl_TextEncoding) const;
895 : #endif
896 :
897 : /**
898 : Match against a substring appearing in this string, ignoring the case of
899 : ASCII letters.
900 :
901 : The result is true if and only if the second string appears as a substring
902 : of this string, at the given position.
903 : Character values between 65 and 90 (ASCII A-Z) are interpreted as
904 : values between 97 and 122 (ASCII a-z).
905 : Since this method is optimized for performance, the ASCII character
906 : values are not converted in any way. The caller has to make sure that
907 : all ASCII characters are in the allowed range between 0 and
908 : 127. The ASCII string must be NULL-terminated and must be greater than or
909 : equal to asciiStrLength.
910 : This function can't be used for language specific comparison.
911 :
912 : @param asciiStr the 8-Bit ASCII character string to be compared.
913 : @param asciiStrLength the length of the ascii string
914 : @param fromIndex the index to start the comparion from.
915 : The index must be greater than or equal to 0
916 : and less than or equal to the string length.
917 : @return sal_True if str match with the characters in the string
918 : at the given position;
919 : sal_False, otherwise.
920 : */
921 785 : sal_Bool matchIgnoreAsciiCaseAsciiL( const sal_Char* asciiStr, sal_Int32 asciiStrLength, sal_Int32 fromIndex = 0 ) const SAL_THROW(())
922 : {
923 785 : return rtl_ustr_ascii_shortenedCompareIgnoreAsciiCase_WithLength( pData->buffer+fromIndex, pData->length-fromIndex,
924 1570 : asciiStr, asciiStrLength ) == 0;
925 : }
926 :
927 : // This overload is left undefined, to detect calls of
928 : // matchIgnoreAsciiCaseAsciiL that erroneously use
929 : // RTL_CONSTASCII_USTRINGPARAM instead of RTL_CONSTASCII_STRINGPARAM (but
930 : // would lead to ambiguities on 32 bit platforms):
931 : #if SAL_TYPES_SIZEOFLONG == 8
932 : void matchIgnoreAsciiCaseAsciiL(char const *, sal_Int32, rtl_TextEncoding)
933 : const;
934 : #endif
935 :
936 : /**
937 : Check whether this string starts with a given substring.
938 :
939 : @param str the substring to be compared
940 :
941 : @return true if and only if the given str appears as a substring at the
942 : start of this string
943 :
944 : @since LibreOffice 4.0
945 : */
946 4151713 : bool startsWith(OUString const & str) const {
947 4151713 : return match(str, 0);
948 : }
949 :
950 : /**
951 : @overload
952 : This function accepts an ASCII string literal as its argument.
953 : @since LibreOffice 4.0
954 : */
955 : template< typename T >
956 1902027 : typename internal::ConstCharArrayDetector< T, bool >::Type startsWith( T& literal ) const
957 : {
958 : assert( strlen( literal ) == internal::ConstCharArrayDetector< T >::size - 1 );
959 : return internal::ConstCharArrayDetector< T, void >::size - 1 <= pData->length
960 : && rtl_ustr_asciil_reverseEquals_WithLength( pData->buffer, literal,
961 1902027 : internal::ConstCharArrayDetector< T, void >::size - 1);
962 : }
963 :
964 : /**
965 : Check whether this string starts with a given string, ignoring the case of
966 : ASCII letters.
967 :
968 : Character values between 65 and 90 (ASCII A-Z) are interpreted as
969 : values between 97 and 122 (ASCII a-z).
970 : This function can't be used for language specific comparison.
971 :
972 : @param str the object (substring) to be compared.
973 : @return true if this string starts with str, ignoring the case of ASCII
974 : letters ("A"--"Z" and "a"--"z"); otherwise, false is returned
975 : @since LibreOffice 4.0
976 : */
977 0 : sal_Bool startsWithIgnoreAsciiCase( const OUString & str ) const SAL_THROW(())
978 : {
979 0 : return matchIgnoreAsciiCase(str, 0);
980 : }
981 :
982 : /**
983 : @overload
984 : This function accepts an ASCII string literal as its argument.
985 : @since LibreOffice 4.0
986 : */
987 : template< typename T >
988 169115 : typename internal::ConstCharArrayDetector< T, bool >::Type startsWithIgnoreAsciiCase( T& literal ) const SAL_THROW(())
989 : {
990 : assert( strlen( literal ) == internal::ConstCharArrayDetector< T >::size - 1 );
991 : return (rtl_ustr_ascii_compareIgnoreAsciiCase_WithLengths(
992 : pData->buffer,
993 : internal::ConstCharArrayDetector< T, void >::size - 1, literal,
994 169115 : internal::ConstCharArrayDetector< T, void >::size - 1)
995 169115 : == 0);
996 : }
997 :
998 : /**
999 : Check whether this string ends with a given substring.
1000 :
1001 : @param str the substring to be compared
1002 :
1003 : @return true if and only if the given str appears as a substring at the
1004 : end of this string
1005 :
1006 : @since LibreOffice 3.6
1007 : */
1008 5 : bool endsWith(OUString const & str) const {
1009 5 : return str.getLength() <= getLength()
1010 5 : && match(str, getLength() - str.getLength());
1011 : }
1012 :
1013 : /**
1014 : @overload
1015 : This function accepts an ASCII string literal as its argument.
1016 : @since LibreOffice 3.6
1017 : */
1018 : template< typename T >
1019 9352 : typename internal::ConstCharArrayDetector< T, bool >::Type endsWith( T& literal ) const
1020 : {
1021 : assert( strlen( literal ) == internal::ConstCharArrayDetector< T >::size - 1 );
1022 : return internal::ConstCharArrayDetector< T, void >::size - 1 <= pData->length
1023 : && rtl_ustr_asciil_reverseEquals_WithLength(
1024 8041 : pData->buffer + pData->length - ( internal::ConstCharArrayDetector< T, void >::size - 1 ), literal,
1025 17393 : internal::ConstCharArrayDetector< T, void >::size - 1);
1026 : }
1027 :
1028 : /**
1029 : Check whether this string ends with a given ASCII string.
1030 :
1031 : @param asciiStr a sequence of at least asciiStrLength ASCII characters
1032 : (bytes in the range 0x00--0x7F)
1033 : @param asciiStrLength the length of asciiStr; must be non-negative
1034 : @return true if this string ends with asciiStr; otherwise, false is
1035 : returned
1036 :
1037 : @since UDK 3.2.7
1038 : */
1039 1584 : inline bool endsWithAsciiL(char const * asciiStr, sal_Int32 asciiStrLength)
1040 : const
1041 : {
1042 1584 : return asciiStrLength <= pData->length
1043 3168 : && rtl_ustr_asciil_reverseEquals_WithLength(
1044 1584 : pData->buffer + pData->length - asciiStrLength, asciiStr,
1045 3168 : asciiStrLength);
1046 : }
1047 :
1048 : /**
1049 : Check whether this string ends with a given string, ignoring the case of
1050 : ASCII letters.
1051 :
1052 : Character values between 65 and 90 (ASCII A-Z) are interpreted as
1053 : values between 97 and 122 (ASCII a-z).
1054 : This function can't be used for language specific comparison.
1055 :
1056 : @param str the object (substring) to be compared.
1057 : @return true if this string ends with str, ignoring the case of ASCII
1058 : letters ("A"--"Z" and "a"--"z"); otherwise, false is returned
1059 : @since LibreOffice 3.6
1060 : */
1061 : sal_Bool endsWithIgnoreAsciiCase( const OUString & str ) const SAL_THROW(())
1062 : {
1063 : return str.getLength() <= getLength()
1064 : && matchIgnoreAsciiCase(str, getLength() - str.getLength());
1065 : }
1066 :
1067 : /**
1068 : @overload
1069 : This function accepts an ASCII string literal as its argument.
1070 : @since LibreOffice 3.6
1071 : */
1072 : template< typename T >
1073 18686 : typename internal::ConstCharArrayDetector< T, bool >::Type endsWithIgnoreAsciiCase( T& literal ) const SAL_THROW(())
1074 : {
1075 : assert( strlen( literal ) == internal::ConstCharArrayDetector< T >::size - 1 );
1076 : return internal::ConstCharArrayDetector< T, void >::size - 1 <= pData->length
1077 : && (rtl_ustr_ascii_compareIgnoreAsciiCase_WithLengths(
1078 18686 : pData->buffer + pData->length - ( internal::ConstCharArrayDetector< T, void >::size - 1 ),
1079 : internal::ConstCharArrayDetector< T, void >::size - 1, literal,
1080 18686 : internal::ConstCharArrayDetector< T, void >::size - 1)
1081 37372 : == 0);
1082 : }
1083 :
1084 : /**
1085 : Check whether this string ends with a given ASCII string, ignoring the
1086 : case of ASCII letters.
1087 :
1088 : @param asciiStr a sequence of at least asciiStrLength ASCII characters
1089 : (bytes in the range 0x00--0x7F)
1090 : @param asciiStrLength the length of asciiStr; must be non-negative
1091 : @return true if this string ends with asciiStr, ignoring the case of ASCII
1092 : letters ("A"--"Z" and "a"--"z"); otherwise, false is returned
1093 : */
1094 2971592 : inline bool endsWithIgnoreAsciiCaseAsciiL(
1095 : char const * asciiStr, sal_Int32 asciiStrLength) const
1096 : {
1097 2971592 : return asciiStrLength <= pData->length
1098 4527901 : && (rtl_ustr_ascii_compareIgnoreAsciiCase_WithLengths(
1099 1556309 : pData->buffer + pData->length - asciiStrLength,
1100 1556309 : asciiStrLength, asciiStr, asciiStrLength)
1101 2971592 : == 0);
1102 : }
1103 :
1104 47706294 : friend sal_Bool operator == ( const OUString& rStr1, const OUString& rStr2 ) SAL_THROW(())
1105 47706294 : { return rStr1.equals(rStr2); }
1106 10037 : friend sal_Bool operator == ( const OUString& rStr1, const sal_Unicode * pStr2 ) SAL_THROW(())
1107 10037 : { return rStr1.compareTo( pStr2 ) == 0; }
1108 : friend sal_Bool operator == ( const sal_Unicode * pStr1, const OUString& rStr2 ) SAL_THROW(())
1109 : { return OUString( pStr1 ).compareTo( rStr2 ) == 0; }
1110 :
1111 6234747 : friend sal_Bool operator != ( const OUString& rStr1, const OUString& rStr2 ) SAL_THROW(())
1112 6234747 : { return !(operator == ( rStr1, rStr2 )); }
1113 10027 : friend sal_Bool operator != ( const OUString& rStr1, const sal_Unicode * pStr2 ) SAL_THROW(())
1114 10027 : { return !(operator == ( rStr1, pStr2 )); }
1115 : friend sal_Bool operator != ( const sal_Unicode * pStr1, const OUString& rStr2 ) SAL_THROW(())
1116 : { return !(operator == ( pStr1, rStr2 )); }
1117 :
1118 114056428 : friend sal_Bool operator < ( const OUString& rStr1, const OUString& rStr2 ) SAL_THROW(())
1119 114056428 : { return rStr1.compareTo( rStr2 ) < 0; }
1120 1804558 : friend sal_Bool operator > ( const OUString& rStr1, const OUString& rStr2 ) SAL_THROW(())
1121 1804558 : { return rStr1.compareTo( rStr2 ) > 0; }
1122 0 : friend sal_Bool operator <= ( const OUString& rStr1, const OUString& rStr2 ) SAL_THROW(())
1123 0 : { return rStr1.compareTo( rStr2 ) <= 0; }
1124 48066 : friend sal_Bool operator >= ( const OUString& rStr1, const OUString& rStr2 ) SAL_THROW(())
1125 48066 : { return rStr1.compareTo( rStr2 ) >= 0; }
1126 :
1127 : /**
1128 : * Compare string to an ASCII string literal.
1129 : *
1130 : * This operator is equal to calling equalsAsciiL().
1131 : *
1132 : * @since LibreOffice 3.6
1133 : */
1134 : template< typename T >
1135 38465118 : friend inline typename internal::ConstCharArrayDetector< T, bool >::Type operator==( const OUString& string, T& literal )
1136 : {
1137 : assert( strlen( literal ) == internal::ConstCharArrayDetector< T >::size - 1 );
1138 38465118 : return string.equalsAsciiL( literal, internal::ConstCharArrayDetector< T, void >::size - 1 );
1139 : }
1140 : /**
1141 : * Compare string to an ASCII string literal.
1142 : *
1143 : * This operator is equal to calling equalsAsciiL().
1144 : *
1145 : * @since LibreOffice 3.6
1146 : */
1147 : template< typename T >
1148 711 : friend inline typename internal::ConstCharArrayDetector< T, bool >::Type operator==( T& literal, const OUString& string )
1149 : {
1150 : assert( strlen( literal ) == internal::ConstCharArrayDetector< T >::size - 1 );
1151 711 : return string.equalsAsciiL( literal, internal::ConstCharArrayDetector< T, void >::size - 1 );
1152 : }
1153 : /**
1154 : * Compare string to an ASCII string literal.
1155 : *
1156 : * This operator is equal to calling !equalsAsciiL().
1157 : *
1158 : * @since LibreOffice 3.6
1159 : */
1160 : template< typename T >
1161 882221 : friend inline typename internal::ConstCharArrayDetector< T, bool >::Type operator!=( const OUString& string, T& literal )
1162 : {
1163 : assert( strlen( literal ) == internal::ConstCharArrayDetector< T >::size - 1 );
1164 882221 : return !string.equalsAsciiL( literal, internal::ConstCharArrayDetector< T, void >::size - 1 );
1165 : }
1166 : /**
1167 : * Compare string to an ASCII string literal.
1168 : *
1169 : * This operator is equal to calling !equalsAsciiL().
1170 : *
1171 : * @since LibreOffice 3.6
1172 : */
1173 : template< typename T >
1174 1 : friend inline typename internal::ConstCharArrayDetector< T, bool >::Type operator!=( T& literal, const OUString& string )
1175 : {
1176 : assert( strlen( literal ) == internal::ConstCharArrayDetector< T >::size - 1 );
1177 1 : return !string.equalsAsciiL( literal, internal::ConstCharArrayDetector< T, void >::size - 1 );
1178 : }
1179 :
1180 : /**
1181 : Returns a hashcode for this string.
1182 :
1183 : @return a hash code value for this object.
1184 :
1185 : @see rtl::OUStringHash for convenient use of boost::unordered_map
1186 : */
1187 12755777 : sal_Int32 hashCode() const SAL_THROW(())
1188 : {
1189 12755777 : return rtl_ustr_hashCode_WithLength( pData->buffer, pData->length );
1190 : }
1191 :
1192 : /**
1193 : Returns the index within this string of the first occurrence of the
1194 : specified character, starting the search at the specified index.
1195 :
1196 : @param ch character to be located.
1197 : @param fromIndex the index to start the search from.
1198 : The index must be greater than or equal to 0
1199 : and less than or equal to the string length.
1200 : @return the index of the first occurrence of the character in the
1201 : character sequence represented by this string that is
1202 : greater than or equal to fromIndex, or
1203 : -1 if the character does not occur.
1204 : */
1205 13910869 : sal_Int32 indexOf( sal_Unicode ch, sal_Int32 fromIndex = 0 ) const SAL_THROW(())
1206 : {
1207 13910869 : sal_Int32 ret = rtl_ustr_indexOfChar_WithLength( pData->buffer+fromIndex, pData->length-fromIndex, ch );
1208 13910869 : return (ret < 0 ? ret : ret+fromIndex);
1209 : }
1210 :
1211 : /**
1212 : Returns the index within this string of the last occurrence of the
1213 : specified character, searching backward starting at the end.
1214 :
1215 : @param ch character to be located.
1216 : @return the index of the last occurrence of the character in the
1217 : character sequence represented by this string, or
1218 : -1 if the character does not occur.
1219 : */
1220 583572 : sal_Int32 lastIndexOf( sal_Unicode ch ) const SAL_THROW(())
1221 : {
1222 583572 : return rtl_ustr_lastIndexOfChar_WithLength( pData->buffer, pData->length, ch );
1223 : }
1224 :
1225 : /**
1226 : Returns the index within this string of the last occurrence of the
1227 : specified character, searching backward starting before the specified
1228 : index.
1229 :
1230 : @param ch character to be located.
1231 : @param fromIndex the index before which to start the search.
1232 : @return the index of the last occurrence of the character in the
1233 : character sequence represented by this string that
1234 : is less than fromIndex, or -1
1235 : if the character does not occur before that point.
1236 : */
1237 19961 : sal_Int32 lastIndexOf( sal_Unicode ch, sal_Int32 fromIndex ) const SAL_THROW(())
1238 : {
1239 19961 : return rtl_ustr_lastIndexOfChar_WithLength( pData->buffer, fromIndex, ch );
1240 : }
1241 :
1242 : /**
1243 : Returns the index within this string of the first occurrence of the
1244 : specified substring, starting at the specified index.
1245 :
1246 : If str doesn't include any character, always -1 is
1247 : returned. This is also the case, if both strings are empty.
1248 :
1249 : @param str the substring to search for.
1250 : @param fromIndex the index to start the search from.
1251 : @return If the string argument occurs one or more times as a substring
1252 : within this string at the starting index, then the index
1253 : of the first character of the first such substring is
1254 : returned. If it does not occur as a substring starting
1255 : at fromIndex or beyond, -1 is returned.
1256 : */
1257 6711664 : sal_Int32 indexOf( const OUString & str, sal_Int32 fromIndex = 0 ) const SAL_THROW(())
1258 : {
1259 6711664 : sal_Int32 ret = rtl_ustr_indexOfStr_WithLength( pData->buffer+fromIndex, pData->length-fromIndex,
1260 13423328 : str.pData->buffer, str.pData->length );
1261 6711664 : return (ret < 0 ? ret : ret+fromIndex);
1262 : }
1263 :
1264 : /**
1265 : @overload
1266 : This function accepts an ASCII string literal as its argument.
1267 : @since LibreOffice 3.6
1268 : */
1269 : template< typename T >
1270 4135454 : typename internal::ConstCharArrayDetector< T, sal_Int32 >::Type indexOf( T& literal, sal_Int32 fromIndex = 0 ) const SAL_THROW(())
1271 : {
1272 : assert( strlen( literal ) == internal::ConstCharArrayDetector< T >::size - 1 );
1273 : sal_Int32 ret = rtl_ustr_indexOfAscii_WithLength(
1274 4135454 : pData->buffer + fromIndex, pData->length - fromIndex, literal,
1275 8270908 : internal::ConstCharArrayDetector< T, void >::size - 1);
1276 4135454 : return ret < 0 ? ret : ret + fromIndex;
1277 : }
1278 :
1279 : /**
1280 : Returns the index within this string of the first occurrence of the
1281 : specified ASCII substring, starting at the specified index.
1282 :
1283 : @param str
1284 : the substring to be searched for. Need not be null-terminated, but must
1285 : be at least as long as the specified len. Must only contain characters
1286 : in the ASCII range 0x00--7F.
1287 :
1288 : @param len
1289 : the length of the substring; must be non-negative.
1290 :
1291 : @param fromIndex
1292 : the index to start the search from. Must be in the range from zero to
1293 : the length of this string, inclusive.
1294 :
1295 : @return
1296 : the index (starting at 0) of the first character of the first occurrence
1297 : of the substring within this string starting at the given fromIndex, or
1298 : -1 if the substring does not occur. If len is zero, -1 is returned.
1299 :
1300 : @since UDK 3.2.7
1301 : */
1302 975443 : sal_Int32 indexOfAsciiL(
1303 : char const * str, sal_Int32 len, sal_Int32 fromIndex = 0) const
1304 : SAL_THROW(())
1305 : {
1306 : sal_Int32 ret = rtl_ustr_indexOfAscii_WithLength(
1307 975443 : pData->buffer + fromIndex, pData->length - fromIndex, str, len);
1308 975443 : return ret < 0 ? ret : ret + fromIndex;
1309 : }
1310 :
1311 : // This overload is left undefined, to detect calls of indexOfAsciiL that
1312 : // erroneously use RTL_CONSTASCII_USTRINGPARAM instead of
1313 : // RTL_CONSTASCII_STRINGPARAM (but would lead to ambiguities on 32 bit
1314 : // platforms):
1315 : #if SAL_TYPES_SIZEOFLONG == 8
1316 : void indexOfAsciiL(char const *, sal_Int32 len, rtl_TextEncoding) const;
1317 : #endif
1318 :
1319 : /**
1320 : Returns the index within this string of the last occurrence of
1321 : the specified substring, searching backward starting at the end.
1322 :
1323 : The returned index indicates the starting index of the substring
1324 : in this string.
1325 : If str doesn't include any character, always -1 is
1326 : returned. This is also the case, if both strings are empty.
1327 :
1328 : @param str the substring to search for.
1329 : @return If the string argument occurs one or more times as a substring
1330 : within this string, then the index of the first character of
1331 : the last such substring is returned. If it does not occur as
1332 : a substring, -1 is returned.
1333 : */
1334 101006 : sal_Int32 lastIndexOf( const OUString & str ) const SAL_THROW(())
1335 : {
1336 : return rtl_ustr_lastIndexOfStr_WithLength( pData->buffer, pData->length,
1337 101006 : str.pData->buffer, str.pData->length );
1338 : }
1339 :
1340 : /**
1341 : Returns the index within this string of the last occurrence of
1342 : the specified substring, searching backward starting before the specified
1343 : index.
1344 :
1345 : The returned index indicates the starting index of the substring
1346 : in this string.
1347 : If str doesn't include any character, always -1 is
1348 : returned. This is also the case, if both strings are empty.
1349 :
1350 : @param str the substring to search for.
1351 : @param fromIndex the index before which to start the search.
1352 : @return If the string argument occurs one or more times as a substring
1353 : within this string before the starting index, then the index
1354 : of the first character of the last such substring is
1355 : returned. Otherwise, -1 is returned.
1356 : */
1357 1 : sal_Int32 lastIndexOf( const OUString & str, sal_Int32 fromIndex ) const SAL_THROW(())
1358 : {
1359 : return rtl_ustr_lastIndexOfStr_WithLength( pData->buffer, fromIndex,
1360 1 : str.pData->buffer, str.pData->length );
1361 : }
1362 :
1363 : /**
1364 : @overload
1365 : This function accepts an ASCII string literal as its argument.
1366 : @since LibreOffice 3.6
1367 : */
1368 : template< typename T >
1369 6359 : typename internal::ConstCharArrayDetector< T, sal_Int32 >::Type lastIndexOf( T& literal ) const SAL_THROW(())
1370 : {
1371 : assert( strlen( literal ) == internal::ConstCharArrayDetector< T >::size - 1 );
1372 : return rtl_ustr_lastIndexOfAscii_WithLength(
1373 6359 : pData->buffer, pData->length, literal, internal::ConstCharArrayDetector< T, void >::size - 1);
1374 : }
1375 :
1376 : /**
1377 : Returns the index within this string of the last occurrence of the
1378 : specified ASCII substring.
1379 :
1380 : @param str
1381 : the substring to be searched for. Need not be null-terminated, but must
1382 : be at least as long as the specified len. Must only contain characters
1383 : in the ASCII range 0x00--7F.
1384 :
1385 : @param len
1386 : the length of the substring; must be non-negative.
1387 :
1388 : @return
1389 : the index (starting at 0) of the first character of the last occurrence
1390 : of the substring within this string, or -1 if the substring does not
1391 : occur. If len is zero, -1 is returned.
1392 :
1393 : @since UDK 3.2.7
1394 : */
1395 0 : sal_Int32 lastIndexOfAsciiL(char const * str, sal_Int32 len) const
1396 : SAL_THROW(())
1397 : {
1398 : return rtl_ustr_lastIndexOfAscii_WithLength(
1399 0 : pData->buffer, pData->length, str, len);
1400 : }
1401 :
1402 : /**
1403 : Returns a new string that is a substring of this string.
1404 :
1405 : The substring begins at the specified beginIndex. If
1406 : beginIndex is negative or be greater than the length of
1407 : this string, behaviour is undefined.
1408 :
1409 : @param beginIndex the beginning index, inclusive.
1410 : @return the specified substring.
1411 : */
1412 1109414 : SAL_WARN_UNUSED_RESULT OUString copy( sal_Int32 beginIndex ) const SAL_THROW(())
1413 : {
1414 1109414 : rtl_uString *pNew = 0;
1415 1109414 : rtl_uString_newFromSubString( &pNew, pData, beginIndex, getLength() - beginIndex );
1416 1109414 : return OUString( pNew, SAL_NO_ACQUIRE );
1417 : }
1418 :
1419 : /**
1420 : Returns a new string that is a substring of this string.
1421 :
1422 : The substring begins at the specified beginIndex and contains count
1423 : characters. If either beginIndex or count are negative,
1424 : or beginIndex + count are greater than the length of this string
1425 : then behaviour is undefined.
1426 :
1427 : @param beginIndex the beginning index, inclusive.
1428 : @param count the number of characters.
1429 : @return the specified substring.
1430 : */
1431 6713578 : SAL_WARN_UNUSED_RESULT OUString copy( sal_Int32 beginIndex, sal_Int32 count ) const SAL_THROW(())
1432 : {
1433 6713578 : rtl_uString *pNew = 0;
1434 6713578 : rtl_uString_newFromSubString( &pNew, pData, beginIndex, count );
1435 6713578 : return OUString( pNew, SAL_NO_ACQUIRE );
1436 : }
1437 :
1438 : /**
1439 : Concatenates the specified string to the end of this string.
1440 :
1441 : @param str the string that is concatenated to the end
1442 : of this string.
1443 : @return a string that represents the concatenation of this string
1444 : followed by the string argument.
1445 : */
1446 271 : SAL_WARN_UNUSED_RESULT OUString concat( const OUString & str ) const SAL_THROW(())
1447 : {
1448 271 : rtl_uString* pNew = 0;
1449 271 : rtl_uString_newConcat( &pNew, pData, str.pData );
1450 271 : return OUString( pNew, SAL_NO_ACQUIRE );
1451 : }
1452 :
1453 : #ifndef RTL_FAST_STRING
1454 : friend OUString operator+( const OUString& rStr1, const OUString& rStr2 ) SAL_THROW(())
1455 : {
1456 : return rStr1.concat( rStr2 );
1457 : }
1458 : #endif
1459 :
1460 : /**
1461 : Returns a new string resulting from replacing n = count characters
1462 : from position index in this string with newStr.
1463 :
1464 : @param index the replacing index in str.
1465 : The index must be greater than or equal to 0 and
1466 : less than or equal to the length of the string.
1467 : @param count the count of characters that will be replaced
1468 : The count must be greater than or equal to 0 and
1469 : less than or equal to the length of the string minus index.
1470 : @param newStr the new substring.
1471 : @return the new string.
1472 : */
1473 673325 : SAL_WARN_UNUSED_RESULT OUString replaceAt( sal_Int32 index, sal_Int32 count, const OUString& newStr ) const SAL_THROW(())
1474 : {
1475 673325 : rtl_uString* pNew = 0;
1476 673325 : rtl_uString_newReplaceStrAt( &pNew, pData, index, count, newStr.pData );
1477 673325 : return OUString( pNew, SAL_NO_ACQUIRE );
1478 : }
1479 :
1480 : /**
1481 : Returns a new string resulting from replacing all occurrences of
1482 : oldChar in this string with newChar.
1483 :
1484 : If the character oldChar does not occur in the character sequence
1485 : represented by this object, then the string is assigned with
1486 : str.
1487 :
1488 : @param oldChar the old character.
1489 : @param newChar the new character.
1490 : @return a string derived from this string by replacing every
1491 : occurrence of oldChar with newChar.
1492 : */
1493 101955 : SAL_WARN_UNUSED_RESULT OUString replace( sal_Unicode oldChar, sal_Unicode newChar ) const SAL_THROW(())
1494 : {
1495 101955 : rtl_uString* pNew = 0;
1496 101955 : rtl_uString_newReplace( &pNew, pData, oldChar, newChar );
1497 101955 : return OUString( pNew, SAL_NO_ACQUIRE );
1498 : }
1499 :
1500 : /**
1501 : Returns a new string resulting from replacing the first occurrence of a
1502 : given substring with another substring.
1503 :
1504 : @param from the substring to be replaced
1505 :
1506 : @param to the replacing substring
1507 :
1508 : @param[in,out] index pointer to a start index; if the pointer is
1509 : non-null: upon entry to the function, its value is the index into this
1510 : string at which to start searching for the \p from substring, the value
1511 : must be non-negative and not greater than this string's length; upon exiting
1512 : the function its value is the index into this string at which the
1513 : replacement took place or -1 if no replacement took place; if the pointer
1514 : is null, searching always starts at index 0
1515 :
1516 : @since LibreOffice 3.6
1517 : */
1518 1147 : SAL_WARN_UNUSED_RESULT OUString replaceFirst(
1519 : OUString const & from, OUString const & to, sal_Int32 * index = 0) const
1520 : {
1521 1147 : rtl_uString * s = 0;
1522 1147 : sal_Int32 i = 0;
1523 : rtl_uString_newReplaceFirst(
1524 1147 : &s, pData, from.pData, to.pData, index == 0 ? &i : index);
1525 1147 : return OUString(s, SAL_NO_ACQUIRE);
1526 : }
1527 :
1528 : /**
1529 : Returns a new string resulting from replacing the first occurrence of a
1530 : given substring with another substring.
1531 :
1532 : @param from ASCII string literal, the substring to be replaced
1533 :
1534 : @param to the replacing substring
1535 :
1536 : @param[in,out] index pointer to a start index; if the pointer is
1537 : non-null: upon entry to the function, its value is the index into the this
1538 : string at which to start searching for the \p from substring, the value
1539 : must be non-negative and not greater than this string's length; upon exiting
1540 : the function its value is the index into this string at which the
1541 : replacement took place or -1 if no replacement took place; if the pointer
1542 : is null, searching always starts at index 0
1543 :
1544 : @since LibreOffice 3.6
1545 : */
1546 : template< typename T >
1547 9 : SAL_WARN_UNUSED_RESULT typename internal::ConstCharArrayDetector< T, OUString >::Type replaceFirst( T& from, OUString const & to,
1548 : sal_Int32 * index = 0) const
1549 : {
1550 9 : rtl_uString * s = 0;
1551 9 : sal_Int32 i = 0;
1552 : assert( strlen( from ) == internal::ConstCharArrayDetector< T >::size - 1 );
1553 9 : rtl_uString_newReplaceFirstAsciiL(
1554 9 : &s, pData, from, internal::ConstCharArrayDetector< T, void >::size - 1, to.pData, index == 0 ? &i : index);
1555 9 : return OUString(s, SAL_NO_ACQUIRE);
1556 : }
1557 :
1558 : /**
1559 : Returns a new string resulting from replacing the first occurrence of a
1560 : given substring with another substring.
1561 :
1562 : @param from ASCII string literal, the substring to be replaced
1563 :
1564 : @param to ASCII string literal, the substring to be replaced
1565 :
1566 : @param[in,out] index pointer to a start index; if the pointer is
1567 : non-null: upon entry to the function, its value is the index into the this
1568 : string at which to start searching for the \p from substring, the value
1569 : must be non-negative and not greater than this string's length; upon exiting
1570 : the function its value is the index into this string at which the
1571 : replacement took place or -1 if no replacement took place; if the pointer
1572 : is null, searching always starts at index 0
1573 :
1574 : @since LibreOffice 3.6
1575 : */
1576 : template< typename T1, typename T2 >
1577 : SAL_WARN_UNUSED_RESULT typename internal::ConstCharArrayDetector< T1, typename internal::ConstCharArrayDetector< T2, OUString >::Type >::Type
1578 2173 : replaceFirst( T1& from, T2& to, sal_Int32 * index = 0) const
1579 : {
1580 2173 : rtl_uString * s = 0;
1581 2173 : sal_Int32 i = 0;
1582 : assert( strlen( from ) == internal::ConstCharArrayDetector< T1 >::size - 1 );
1583 : assert( strlen( to ) == internal::ConstCharArrayDetector< T2 >::size - 1 );
1584 2173 : rtl_uString_newReplaceFirstAsciiLAsciiL(
1585 : &s, pData, from, internal::ConstCharArrayDetector< T1, void >::size - 1, to,
1586 2173 : internal::ConstCharArrayDetector< T2, void >::size - 1, index == 0 ? &i : index);
1587 2173 : return OUString(s, SAL_NO_ACQUIRE);
1588 : }
1589 :
1590 : /**
1591 : Returns a new string resulting from replacing all occurrences of a given
1592 : substring with another substring.
1593 :
1594 : Replacing subsequent occurrences picks up only after a given replacement.
1595 : That is, replacing from "xa" to "xx" in "xaa" results in "xxa", not "xxx".
1596 :
1597 : @param from the substring to be replaced
1598 :
1599 : @param to the replacing substring
1600 :
1601 : @param fromIndex the position in the string where we will begin searching
1602 :
1603 : @since LibreOffice 4.0
1604 : */
1605 98165 : SAL_WARN_UNUSED_RESULT OUString replaceAll(
1606 : OUString const & from, OUString const & to, sal_Int32 fromIndex = 0) const
1607 : {
1608 98165 : rtl_uString * s = 0;
1609 98165 : rtl_uString_newReplaceAllFromIndex(&s, pData, from.pData, to.pData, fromIndex);
1610 98165 : return OUString(s, SAL_NO_ACQUIRE);
1611 : }
1612 :
1613 : /**
1614 : Returns a new string resulting from replacing all occurrences of a given
1615 : substring with another substring.
1616 :
1617 : Replacing subsequent occurrences picks up only after a given replacement.
1618 : That is, replacing from "xa" to "xx" in "xaa" results in "xxa", not "xxx".
1619 :
1620 : @param from ASCII string literal, the substring to be replaced
1621 :
1622 : @param to the replacing substring
1623 :
1624 : @since LibreOffice 3.6
1625 : */
1626 : template< typename T >
1627 14408 : SAL_WARN_UNUSED_RESULT typename internal::ConstCharArrayDetector< T, OUString >::Type replaceAll( T& from, OUString const & to) const
1628 : {
1629 14408 : rtl_uString * s = 0;
1630 : assert( strlen( from ) == internal::ConstCharArrayDetector< T >::size - 1 );
1631 14408 : rtl_uString_newReplaceAllAsciiL(&s, pData, from, internal::ConstCharArrayDetector< T, void >::size - 1, to.pData);
1632 14408 : return OUString(s, SAL_NO_ACQUIRE);
1633 : }
1634 :
1635 : /**
1636 : Returns a new string resulting from replacing all occurrences of a given
1637 : substring with another substring.
1638 :
1639 : Replacing subsequent occurrences picks up only after a given replacement.
1640 : That is, replacing from "xa" to "xx" in "xaa" results in "xxa", not "xxx".
1641 :
1642 : @param from ASCII string literal, the substring to be replaced
1643 :
1644 : @param to ASCII string literal, the substring to be replaced
1645 :
1646 : @since LibreOffice 3.6
1647 : */
1648 : template< typename T1, typename T2 >
1649 : SAL_WARN_UNUSED_RESULT typename internal::ConstCharArrayDetector< T1, typename internal::ConstCharArrayDetector< T2, OUString >::Type >::Type
1650 3103 : replaceAll( T1& from, T2& to ) const
1651 : {
1652 3103 : rtl_uString * s = 0;
1653 : assert( strlen( from ) == internal::ConstCharArrayDetector< T1 >::size - 1 );
1654 : assert( strlen( to ) == internal::ConstCharArrayDetector< T2 >::size - 1 );
1655 3103 : rtl_uString_newReplaceAllAsciiLAsciiL(
1656 : &s, pData, from, internal::ConstCharArrayDetector< T1, void >::size - 1,
1657 3103 : to, internal::ConstCharArrayDetector< T2, void >::size - 1);
1658 3103 : return OUString(s, SAL_NO_ACQUIRE);
1659 : }
1660 :
1661 : /**
1662 : Converts from this string all ASCII uppercase characters (65-90)
1663 : to ASCII lowercase characters (97-122).
1664 :
1665 : This function can't be used for language specific conversion.
1666 : If the string doesn't contain characters which must be converted,
1667 : then the new string is assigned with str.
1668 :
1669 : @return the string, converted to ASCII lowercase.
1670 : */
1671 836062 : SAL_WARN_UNUSED_RESULT OUString toAsciiLowerCase() const SAL_THROW(())
1672 : {
1673 836062 : rtl_uString* pNew = 0;
1674 836062 : rtl_uString_newToAsciiLowerCase( &pNew, pData );
1675 836062 : return OUString( pNew, SAL_NO_ACQUIRE );
1676 : }
1677 :
1678 : /**
1679 : Converts from this string all ASCII lowercase characters (97-122)
1680 : to ASCII uppercase characters (65-90).
1681 :
1682 : This function can't be used for language specific conversion.
1683 : If the string doesn't contain characters which must be converted,
1684 : then the new string is assigned with str.
1685 :
1686 : @return the string, converted to ASCII uppercase.
1687 : */
1688 702074 : SAL_WARN_UNUSED_RESULT OUString toAsciiUpperCase() const SAL_THROW(())
1689 : {
1690 702074 : rtl_uString* pNew = 0;
1691 702074 : rtl_uString_newToAsciiUpperCase( &pNew, pData );
1692 702074 : return OUString( pNew, SAL_NO_ACQUIRE );
1693 : }
1694 :
1695 : /**
1696 : Returns a new string resulting from removing white space from both ends
1697 : of the string.
1698 :
1699 : All characters that have codes less than or equal to
1700 : 32 (the space character) are considered to be white space.
1701 : If the string doesn't contain white spaces at both ends,
1702 : then the new string is assigned with str.
1703 :
1704 : @return the string, with white space removed from the front and end.
1705 : */
1706 114816 : SAL_WARN_UNUSED_RESULT OUString trim() const SAL_THROW(())
1707 : {
1708 114816 : rtl_uString* pNew = 0;
1709 114816 : rtl_uString_newTrim( &pNew, pData );
1710 114816 : return OUString( pNew, SAL_NO_ACQUIRE );
1711 : }
1712 :
1713 : /**
1714 : Returns a token in the string.
1715 :
1716 : Example:
1717 : sal_Int32 nIndex = 0;
1718 : do
1719 : {
1720 : ...
1721 : OUString aToken = aStr.getToken( 0, ';', nIndex );
1722 : ...
1723 : }
1724 : while ( nIndex >= 0 );
1725 :
1726 : @param token the number of the token to return
1727 : @param cTok the character which separate the tokens.
1728 : @param index the position at which the token is searched in the
1729 : string.
1730 : The index must not be greater than the length of the
1731 : string.
1732 : This param is set to the position of the
1733 : next token or to -1, if it is the last token.
1734 : @return the token; if either token or index is negative, an empty token
1735 : is returned (and index is set to -1)
1736 : */
1737 2230597 : OUString getToken( sal_Int32 token, sal_Unicode cTok, sal_Int32& index ) const SAL_THROW(())
1738 : {
1739 2230597 : rtl_uString * pNew = 0;
1740 2230597 : index = rtl_uString_getToken( &pNew, pData, token, cTok, index );
1741 2230596 : return OUString( pNew, SAL_NO_ACQUIRE );
1742 : }
1743 :
1744 : /**
1745 : Returns a token from the string.
1746 :
1747 : The same as getToken(sal_Int32, sal_Unicode, sal_Int32 &), but always
1748 : passing in 0 as the start index in the third argument.
1749 :
1750 : @param count the number of the token to return, starting with 0
1751 : @param separator the character which separates the tokens
1752 :
1753 : @return the given token, or an empty string
1754 :
1755 : @since LibreOffice 3.6
1756 : */
1757 6176 : OUString getToken(sal_Int32 count, sal_Unicode separator) const {
1758 6176 : sal_Int32 n = 0;
1759 6176 : return getToken(count, separator, n);
1760 : }
1761 :
1762 : /**
1763 : Returns the Boolean value from this string.
1764 :
1765 : This function can't be used for language specific conversion.
1766 :
1767 : @return sal_True, if the string is 1 or "True" in any ASCII case.
1768 : sal_False in any other case.
1769 : */
1770 384 : sal_Bool toBoolean() const SAL_THROW(())
1771 : {
1772 384 : return rtl_ustr_toBoolean( pData->buffer );
1773 : }
1774 :
1775 : /**
1776 : Returns the first character from this string.
1777 :
1778 : @return the first character from this string or 0, if this string
1779 : is emptry.
1780 : */
1781 19779 : sal_Unicode toChar() const SAL_THROW(())
1782 : {
1783 19779 : return pData->buffer[0];
1784 : }
1785 :
1786 : /**
1787 : Returns the int32 value from this string.
1788 :
1789 : This function can't be used for language specific conversion.
1790 :
1791 : @param radix the radix (between 2 and 36)
1792 : @return the int32 represented from this string.
1793 : 0 if this string represents no number or one of too large
1794 : magnitude.
1795 : */
1796 168241 : sal_Int32 toInt32( sal_Int16 radix = 10 ) const SAL_THROW(())
1797 : {
1798 168241 : return rtl_ustr_toInt32( pData->buffer, radix );
1799 : }
1800 :
1801 : /**
1802 : Returns the uint32 value from this string.
1803 :
1804 : This function can't be used for language specific conversion.
1805 :
1806 : @param radix the radix (between 2 and 36)
1807 : @return the uint32 represented from this string.
1808 : 0 if this string represents no number or one of too large
1809 : magnitude.
1810 :
1811 : @since LibreOffice 4.2
1812 : */
1813 26137 : sal_uInt32 toUInt32( sal_Int16 radix = 10 ) const SAL_THROW(())
1814 : {
1815 26137 : return rtl_ustr_toUInt32( pData->buffer, radix );
1816 : }
1817 :
1818 : /**
1819 : Returns the int64 value from this string.
1820 :
1821 : This function can't be used for language specific conversion.
1822 :
1823 : @param radix the radix (between 2 and 36)
1824 : @return the int64 represented from this string.
1825 : 0 if this string represents no number or one of too large
1826 : magnitude.
1827 : */
1828 47806 : sal_Int64 toInt64( sal_Int16 radix = 10 ) const SAL_THROW(())
1829 : {
1830 47806 : return rtl_ustr_toInt64( pData->buffer, radix );
1831 : }
1832 :
1833 : /**
1834 : Returns the uint64 value from this string.
1835 :
1836 : This function can't be used for language specific conversion.
1837 :
1838 : @param radix the radix (between 2 and 36)
1839 : @return the uint64 represented from this string.
1840 : 0 if this string represents no number or one of too large
1841 : magnitude.
1842 :
1843 : @since LibreOffice 4.1
1844 : */
1845 3 : sal_uInt64 toUInt64( sal_Int16 radix = 10 ) const SAL_THROW(())
1846 : {
1847 3 : return rtl_ustr_toUInt64( pData->buffer, radix );
1848 : }
1849 :
1850 : /**
1851 : Returns the float value from this string.
1852 :
1853 : This function can't be used for language specific conversion.
1854 :
1855 : @return the float represented from this string.
1856 : 0.0 if this string represents no number.
1857 : */
1858 28 : float toFloat() const SAL_THROW(())
1859 : {
1860 28 : return rtl_ustr_toFloat( pData->buffer );
1861 : }
1862 :
1863 : /**
1864 : Returns the double value from this string.
1865 :
1866 : This function can't be used for language specific conversion.
1867 :
1868 : @return the double represented from this string.
1869 : 0.0 if this string represents no number.
1870 : */
1871 1718 : double toDouble() const SAL_THROW(())
1872 : {
1873 1718 : return rtl_ustr_toDouble( pData->buffer );
1874 : }
1875 :
1876 :
1877 : /**
1878 : Return a canonical representation for a string.
1879 :
1880 : A pool of strings, initially empty is maintained privately
1881 : by the string class. On invocation, if present in the pool
1882 : the original string will be returned. Otherwise this string,
1883 : or a copy thereof will be added to the pool and returned.
1884 :
1885 : @return
1886 : a version of the string from the pool.
1887 :
1888 : @exception std::bad_alloc is thrown if an out-of-memory condition occurs
1889 :
1890 : @since UDK 3.2.7
1891 : */
1892 19422 : OUString intern() const
1893 : {
1894 19422 : rtl_uString * pNew = 0;
1895 19422 : rtl_uString_intern( &pNew, pData );
1896 19422 : if (pNew == 0) {
1897 : #if defined EXCEPTIONS_OFF
1898 : abort();
1899 : #else
1900 0 : throw std::bad_alloc();
1901 : #endif
1902 : }
1903 19422 : return OUString( pNew, SAL_NO_ACQUIRE );
1904 : }
1905 :
1906 : /**
1907 : Return a canonical representation for a converted string.
1908 :
1909 : A pool of strings, initially empty is maintained privately
1910 : by the string class. On invocation, if present in the pool
1911 : the original string will be returned. Otherwise this string,
1912 : or a copy thereof will be added to the pool and returned.
1913 :
1914 : @param value a 8-Bit character array.
1915 : @param length the number of character which should be converted.
1916 : The 8-Bit character array length must be
1917 : greater than or equal to this value.
1918 : @param encoding the text encoding from which the 8-Bit character
1919 : sequence should be converted.
1920 : @param convertFlags flags which controls the conversion.
1921 : see RTL_TEXTTOUNICODE_FLAGS_...
1922 : @param pInfo pointer to return conversion status or NULL.
1923 :
1924 : @return
1925 : a version of the converted string from the pool.
1926 :
1927 : @exception std::bad_alloc is thrown if an out-of-memory condition occurs
1928 :
1929 : @since UDK 3.2.7
1930 : */
1931 163783 : static OUString intern( const sal_Char * value, sal_Int32 length,
1932 : rtl_TextEncoding encoding,
1933 : sal_uInt32 convertFlags = OSTRING_TO_OUSTRING_CVTFLAGS,
1934 : sal_uInt32 *pInfo = NULL )
1935 : {
1936 163783 : rtl_uString * pNew = 0;
1937 : rtl_uString_internConvert( &pNew, value, length, encoding,
1938 163783 : convertFlags, pInfo );
1939 163783 : if (pNew == 0) {
1940 : #if defined EXCEPTIONS_OFF
1941 : abort();
1942 : #else
1943 0 : throw std::bad_alloc();
1944 : #endif
1945 : }
1946 163783 : return OUString( pNew, SAL_NO_ACQUIRE );
1947 : }
1948 :
1949 : /**
1950 : Converts to an OString, signalling failure.
1951 :
1952 : @param pTarget
1953 : An out parameter receiving the converted OString. Must not be null; the
1954 : contents are not modified if conversion fails (convertToOString returns
1955 : false).
1956 :
1957 : @param nEncoding
1958 : The text encoding to convert into. Must be an octet encoding (i.e.,
1959 : rtl_isOctetTextEncoding(nEncoding) must return true).
1960 :
1961 : @param nFlags
1962 : A combination of RTL_UNICODETOTEXT_FLAGS that detail how to do the
1963 : conversion (see rtl_convertUnicodeToText). RTL_UNICODETOTEXT_FLAGS_FLUSH
1964 : need not be included, it is implicitly assumed. Typical uses are either
1965 : RTL_UNICODETOTEXT_FLAGS_UNDEFINED_ERROR |
1966 : RTL_UNICODETOTEXT_FLAGS_INVALID_ERROR (fail if a Unicode character cannot
1967 : be converted to the target nEncoding) or OUSTRING_TO_OSTRING_CVTFLAGS
1968 : (make a best efforts conversion).
1969 :
1970 : @return
1971 : True if the conversion succeeded, false otherwise.
1972 : */
1973 242286 : inline bool convertToString(OString * pTarget, rtl_TextEncoding nEncoding,
1974 : sal_uInt32 nFlags) const
1975 : {
1976 : return rtl_convertUStringToString(&pTarget->pData, pData->buffer,
1977 242286 : pData->length, nEncoding, nFlags);
1978 : }
1979 :
1980 : /** Iterate through this string based on code points instead of UTF-16 code
1981 : units.
1982 :
1983 : See Chapter 3 of The Unicode Standard 5.0 (Addison--Wesley, 2006) for
1984 : definitions of the various terms used in this description.
1985 :
1986 : This string is interpreted as a sequence of zero or more UTF-16 code
1987 : units. For each index into this sequence (from zero to one less than
1988 : the length of the sequence, inclusive), a code point represented
1989 : starting at the given index is computed as follows:
1990 :
1991 : - If the UTF-16 code unit addressed by the index constitutes a
1992 : well-formed UTF-16 code unit sequence, the computed code point is the
1993 : scalar value encoded by that UTF-16 code unit sequence.
1994 :
1995 : - Otherwise, if the index is at least two UTF-16 code units away from
1996 : the end of the sequence, and the sequence of two UTF-16 code units
1997 : addressed by the index constitutes a well-formed UTF-16 code unit
1998 : sequence, the computed code point is the scalar value encoded by that
1999 : UTF-16 code unit sequence.
2000 :
2001 : - Otherwise, the computed code point is the UTF-16 code unit addressed
2002 : by the index. (This last case catches unmatched surrogates as well as
2003 : indices pointing into the middle of surrogate pairs.)
2004 :
2005 : @param indexUtf16
2006 : pointer to a UTF-16 based index into this string; must not be null. On
2007 : entry, the index must be in the range from zero to the length of this
2008 : string (in UTF-16 code units), inclusive. Upon successful return, the
2009 : index will be updated to address the UTF-16 code unit that is the given
2010 : incrementCodePoints away from the initial index.
2011 :
2012 : @param incrementCodePoints
2013 : the number of code points to move the given *indexUtf16. If
2014 : non-negative, moving is done after determining the code point at the
2015 : index. If negative, moving is done before determining the code point
2016 : at the (then updated) index. The value must be such that the resulting
2017 : UTF-16 based index is in the range from zero to the length of this
2018 : string (in UTF-16 code units), inclusive.
2019 :
2020 : @return
2021 : the code point (an integer in the range from 0 to 0x10FFFF, inclusive)
2022 : that is represented within this string starting at the index computed as
2023 : follows: If incrementCodePoints is non-negative, the index is the
2024 : initial value of *indexUtf16; if incrementCodePoints is negative, the
2025 : index is the updated value of *indexUtf16. In either case, the computed
2026 : index must be in the range from zero to one less than the length of this
2027 : string (in UTF-16 code units), inclusive.
2028 :
2029 : @since UDK 3.2.7
2030 : */
2031 32969853 : inline sal_uInt32 iterateCodePoints(
2032 : sal_Int32 * indexUtf16, sal_Int32 incrementCodePoints = 1) const
2033 : {
2034 : return rtl_uString_iterateCodePoints(
2035 32969853 : pData, indexUtf16, incrementCodePoints);
2036 : }
2037 :
2038 : /**
2039 : Returns the string representation of the integer argument.
2040 :
2041 : This function can't be used for language specific conversion.
2042 :
2043 : @param i an integer value
2044 : @param radix the radix (between 2 and 36)
2045 : @return a string with the string representation of the argument.
2046 : @since LibreOffice 4.1
2047 : */
2048 59179 : static OUString number( int i, sal_Int16 radix = 10 )
2049 : {
2050 : sal_Unicode aBuf[RTL_USTR_MAX_VALUEOFINT32];
2051 59179 : rtl_uString* pNewData = 0;
2052 59179 : rtl_uString_newFromStr_WithLength( &pNewData, aBuf, rtl_ustr_valueOfInt32( aBuf, i, radix ) );
2053 59179 : return OUString( pNewData, SAL_NO_ACQUIRE );
2054 : }
2055 : /// @overload
2056 : /// @since LibreOffice 4.1
2057 2 : static OUString number( unsigned int i, sal_Int16 radix = 10 )
2058 : {
2059 2 : return number( static_cast< unsigned long long >( i ), radix );
2060 : }
2061 : /// @overload
2062 : /// @since LibreOffice 4.1
2063 243815 : static OUString number( long i, sal_Int16 radix = 10)
2064 : {
2065 243815 : return number( static_cast< long long >( i ), radix );
2066 : }
2067 : /// @overload
2068 : /// @since LibreOffice 4.1
2069 1353 : static OUString number( unsigned long i, sal_Int16 radix = 10 )
2070 : {
2071 1353 : return number( static_cast< unsigned long long >( i ), radix );
2072 : }
2073 : /// @overload
2074 : /// @since LibreOffice 4.1
2075 319030 : static OUString number( long long ll, sal_Int16 radix = 10 )
2076 : {
2077 : sal_Unicode aBuf[RTL_STR_MAX_VALUEOFINT64];
2078 319030 : rtl_uString* pNewData = 0;
2079 319030 : rtl_uString_newFromStr_WithLength( &pNewData, aBuf, rtl_ustr_valueOfInt64( aBuf, ll, radix ) );
2080 319030 : return OUString( pNewData, SAL_NO_ACQUIRE );
2081 : }
2082 : /// @overload
2083 : /// @since LibreOffice 4.1
2084 1359 : static OUString number( unsigned long long ll, sal_Int16 radix = 10 )
2085 : {
2086 : sal_Unicode aBuf[RTL_STR_MAX_VALUEOFUINT64];
2087 1359 : rtl_uString* pNewData = 0;
2088 1359 : rtl_uString_newFromStr_WithLength( &pNewData, aBuf, rtl_ustr_valueOfUInt64( aBuf, ll, radix ) );
2089 1359 : return OUString( pNewData, SAL_NO_ACQUIRE );
2090 : }
2091 :
2092 : /**
2093 : Returns the string representation of the float argument.
2094 :
2095 : This function can't be used for language specific conversion.
2096 :
2097 : @param f a float.
2098 : @return a string with the string representation of the argument.
2099 : @since LibreOffice 4.1
2100 : */
2101 47 : static OUString number( float f )
2102 : {
2103 : sal_Unicode aBuf[RTL_USTR_MAX_VALUEOFFLOAT];
2104 47 : rtl_uString* pNewData = 0;
2105 47 : rtl_uString_newFromStr_WithLength( &pNewData, aBuf, rtl_ustr_valueOfFloat( aBuf, f ) );
2106 47 : return OUString( pNewData, SAL_NO_ACQUIRE );
2107 : }
2108 :
2109 : /**
2110 : Returns the string representation of the double argument.
2111 :
2112 : This function can't be used for language specific conversion.
2113 :
2114 : @param d a double.
2115 : @return a string with the string representation of the argument.
2116 : @since LibreOffice 4.1
2117 : */
2118 1220 : static OUString number( double d )
2119 : {
2120 : sal_Unicode aBuf[RTL_USTR_MAX_VALUEOFDOUBLE];
2121 1220 : rtl_uString* pNewData = 0;
2122 1220 : rtl_uString_newFromStr_WithLength( &pNewData, aBuf, rtl_ustr_valueOfDouble( aBuf, d ) );
2123 1220 : return OUString( pNewData, SAL_NO_ACQUIRE );
2124 : }
2125 :
2126 : /**
2127 : Returns the string representation of the sal_Bool argument.
2128 :
2129 : If the sal_Bool is true, the string "true" is returned.
2130 : If the sal_Bool is false, the string "false" is returned.
2131 : This function can't be used for language specific conversion.
2132 :
2133 : @param b a sal_Bool.
2134 : @return a string with the string representation of the argument.
2135 : @deprecated use boolean()
2136 : */
2137 15 : SAL_DEPRECATED_INTERNAL("use boolean()") static OUString valueOf( sal_Bool b ) SAL_THROW(())
2138 : {
2139 15 : return boolean(b);
2140 : }
2141 :
2142 : /**
2143 : Returns the string representation of the boolean argument.
2144 :
2145 : If the argument is true, the string "true" is returned.
2146 : If the argument is false, the string "false" is returned.
2147 : This function can't be used for language specific conversion.
2148 :
2149 : @param b a bool.
2150 : @return a string with the string representation of the argument.
2151 : @since LibreOffice 4.1
2152 : */
2153 19 : static OUString boolean( bool b ) SAL_THROW(())
2154 : {
2155 : sal_Unicode aBuf[RTL_USTR_MAX_VALUEOFBOOLEAN];
2156 19 : rtl_uString* pNewData = 0;
2157 19 : rtl_uString_newFromStr_WithLength( &pNewData, aBuf, rtl_ustr_valueOfBoolean( aBuf, b ) );
2158 19 : return OUString( pNewData, SAL_NO_ACQUIRE );
2159 : }
2160 :
2161 : /**
2162 : Returns the string representation of the char argument.
2163 :
2164 : @param c a character.
2165 : @return a string with the string representation of the argument.
2166 : @deprecated use operator, function or constructor taking char or sal_Unicode argument
2167 : */
2168 2711 : SAL_DEPRECATED_INTERNAL("convert to OUString or use directly") static OUString valueOf( sal_Unicode c ) SAL_THROW(())
2169 : {
2170 2711 : return OUString( &c, 1 );
2171 : }
2172 :
2173 : /**
2174 : Returns the string representation of the int argument.
2175 :
2176 : This function can't be used for language specific conversion.
2177 :
2178 : @param i a int32.
2179 : @param radix the radix (between 2 and 36)
2180 : @return a string with the string representation of the argument.
2181 : @deprecated use number()
2182 : */
2183 201396 : SAL_DEPRECATED_INTERNAL("use number()") static OUString valueOf( sal_Int32 i, sal_Int16 radix = 10 ) SAL_THROW(())
2184 : {
2185 201396 : return number( i, radix );
2186 : }
2187 :
2188 : /**
2189 : Returns the string representation of the long argument.
2190 :
2191 : This function can't be used for language specific conversion.
2192 :
2193 : @param ll a int64.
2194 : @param radix the radix (between 2 and 36)
2195 : @return a string with the string representation of the argument.
2196 : @deprecated use number()
2197 : */
2198 75150 : SAL_DEPRECATED_INTERNAL("use number()") static OUString valueOf( sal_Int64 ll, sal_Int16 radix = 10 ) SAL_THROW(())
2199 : {
2200 75150 : return number( ll, radix );
2201 : }
2202 :
2203 : /**
2204 : Returns the string representation of the float argument.
2205 :
2206 : This function can't be used for language specific conversion.
2207 :
2208 : @param f a float.
2209 : @return a string with the string representation of the argument.
2210 : @deprecated use number()
2211 : */
2212 6 : SAL_DEPRECATED_INTERNAL("use number()") static OUString valueOf( float f ) SAL_THROW(())
2213 : {
2214 6 : return number(f);
2215 : }
2216 :
2217 : /**
2218 : Returns the string representation of the double argument.
2219 :
2220 : This function can't be used for language specific conversion.
2221 :
2222 : @param d a double.
2223 : @return a string with the string representation of the argument.
2224 : @deprecated use number()
2225 : */
2226 1207 : SAL_DEPRECATED_INTERNAL("use number()") static OUString valueOf( double d ) SAL_THROW(())
2227 : {
2228 1207 : return number(d);
2229 : }
2230 :
2231 : /**
2232 : Returns a OUString copied without conversion from an ASCII
2233 : character string.
2234 :
2235 : Since this method is optimized for performance, the ASCII character
2236 : values are not converted in any way. The caller has to make sure that
2237 : all ASCII characters are in the allowed range between 0 and
2238 : 127. The ASCII string must be NULL-terminated.
2239 :
2240 : Note that for string literals it is simpler and more efficient
2241 : to directly use the OUString constructor.
2242 :
2243 : @param value the 8-Bit ASCII character string
2244 : @return a string with the string representation of the argument.
2245 : */
2246 5249015 : static OUString createFromAscii( const sal_Char * value ) SAL_THROW(())
2247 : {
2248 5249015 : rtl_uString* pNew = 0;
2249 5249015 : rtl_uString_newFromAscii( &pNew, value );
2250 5249015 : return OUString( pNew, SAL_NO_ACQUIRE );
2251 : }
2252 : };
2253 :
2254 : /* ======================================================================= */
2255 :
2256 : #ifdef RTL_FAST_STRING
2257 : /**
2258 : A simple wrapper around string literal. It is usually not necessary to use, can
2259 : be mostly used to force OUString operator+ working with operands that otherwise would
2260 : not trigger it.
2261 :
2262 : This class is not part of public API and is meant to be used only in LibreOffice code.
2263 : @since LibreOffice 4.0
2264 : */
2265 : struct SAL_WARN_UNUSED OUStringLiteral
2266 : {
2267 : template< int N >
2268 4 : OUStringLiteral( const char (&str)[ N ] ) : size( N - 1 ), data( str ) { assert( strlen( str ) == N - 1 ); }
2269 : int size;
2270 : const char* data;
2271 : };
2272 :
2273 : /**
2274 : @internal
2275 : */
2276 : template<>
2277 : struct ToStringHelper< OUString >
2278 : {
2279 5363825 : static int length( const OUString& s ) { return s.getLength(); }
2280 5363819 : static sal_Unicode* addData( sal_Unicode* buffer, const OUString& s ) { return addDataHelper( buffer, s.getStr(), s.getLength()); }
2281 : static const bool allowOStringConcat = false;
2282 : static const bool allowOUStringConcat = true;
2283 : };
2284 :
2285 : /**
2286 : @internal
2287 : */
2288 : template<>
2289 : struct ToStringHelper< OUStringLiteral >
2290 : {
2291 3 : static int length( const OUStringLiteral& str ) { return str.size; }
2292 3 : static sal_Unicode* addData( sal_Unicode* buffer, const OUStringLiteral& str ) { return addDataLiteral( buffer, str.data, str.size ); }
2293 : static const bool allowOStringConcat = false;
2294 : static const bool allowOUStringConcat = true;
2295 : };
2296 :
2297 : /**
2298 : @internal
2299 : */
2300 : template< typename charT, typename traits, typename T1, typename T2 >
2301 : inline std::basic_ostream<charT, traits> & operator <<(
2302 : std::basic_ostream<charT, traits> & stream, const OUStringConcat< T1, T2 >& concat)
2303 : {
2304 : return stream << OUString( concat );
2305 : }
2306 : #else
2307 : // non-RTL_FAST_STRING needs this to compile
2308 : /// @cond INTERNAL
2309 : typedef OUString OUStringLiteral;
2310 : /// @endcond
2311 : #endif
2312 :
2313 : /** A helper to use OUStrings with hash maps.
2314 :
2315 : Instances of this class are unary function objects that can be used as
2316 : hash function arguments to boost::unordered_map and similar constructs.
2317 : */
2318 : struct OUStringHash
2319 : {
2320 : /** Compute a hash code for a string.
2321 :
2322 : @param rString
2323 : a string.
2324 :
2325 : @return
2326 : a hash code for the string. This hash code should not be stored
2327 : persistently, as its computation may change in later revisions.
2328 : */
2329 9070244 : size_t operator()(const OUString& rString) const
2330 9070244 : { return (size_t)rString.hashCode(); }
2331 : };
2332 :
2333 : /* ======================================================================= */
2334 :
2335 : /** Convert an OString to an OUString, using a specific text encoding.
2336 :
2337 : The lengths of the two strings may differ (e.g., for double-byte
2338 : encodings, UTF-7, UTF-8).
2339 :
2340 : @param rStr
2341 : an OString to convert.
2342 :
2343 : @param encoding
2344 : the text encoding to use for conversion.
2345 :
2346 : @param convertFlags
2347 : flags which control the conversion. Either use
2348 : OSTRING_TO_OUSTRING_CVTFLAGS, or see
2349 : <http://udk.openoffice.org/cpp/man/spec/textconversion.html> for more
2350 : details.
2351 : */
2352 1155856 : inline OUString OStringToOUString( const OString & rStr,
2353 : rtl_TextEncoding encoding,
2354 : sal_uInt32 convertFlags = OSTRING_TO_OUSTRING_CVTFLAGS )
2355 : {
2356 1155856 : return OUString( rStr.getStr(), rStr.getLength(), encoding, convertFlags );
2357 : }
2358 :
2359 : /** Convert an OUString to an OString, using a specific text encoding.
2360 :
2361 : The lengths of the two strings may differ (e.g., for double-byte
2362 : encodings, UTF-7, UTF-8).
2363 :
2364 : @param rUnicode
2365 : an OUString to convert.
2366 :
2367 : @param encoding
2368 : the text encoding to use for conversion.
2369 :
2370 : @param convertFlags
2371 : flags which control the conversion. Either use
2372 : OUSTRING_TO_OSTRING_CVTFLAGS, or see
2373 : <http://udk.openoffice.org/cpp/man/spec/textconversion.html> for more
2374 : details.
2375 : */
2376 4543601 : inline OString OUStringToOString( const OUString & rUnicode,
2377 : rtl_TextEncoding encoding,
2378 : sal_uInt32 convertFlags = OUSTRING_TO_OSTRING_CVTFLAGS )
2379 : {
2380 4543601 : return OString( rUnicode.getStr(), rUnicode.getLength(), encoding, convertFlags );
2381 : }
2382 :
2383 : /* ======================================================================= */
2384 :
2385 : /**
2386 : Support for rtl::OUString in std::ostream (and thus in
2387 : CPPUNIT_ASSERT or SAL_INFO macros, for example).
2388 :
2389 : The rtl::OUString is converted to UTF-8.
2390 :
2391 : @since LibreOffice 3.5.
2392 : */
2393 : template< typename charT, typename traits >
2394 227 : inline std::basic_ostream<charT, traits> & operator <<(
2395 : std::basic_ostream<charT, traits> & stream, OUString const & string)
2396 : {
2397 454 : return stream <<
2398 454 : OUStringToOString(string, RTL_TEXTENCODING_UTF8).getStr();
2399 : // best effort; potentially loses data due to conversion failures
2400 : // (stray surrogate halves) and embedded null characters
2401 : }
2402 :
2403 : } // namespace
2404 :
2405 : #ifdef RTL_STRING_UNITTEST
2406 : namespace rtl
2407 : {
2408 : typedef rtlunittest::OUString OUString;
2409 : }
2410 : #endif
2411 :
2412 : // RTL_USING is defined by gbuild for all modules except those with stable public API
2413 : // (as listed in ure/source/README). It allows to use classes like OUString without
2414 : // having to explicitly refer to the rtl namespace, which is kind of superfluous
2415 : // given that OUString itself is namespaced by its OU prefix.
2416 : #ifdef RTL_USING
2417 : using ::rtl::OUString;
2418 : using ::rtl::OUStringHash;
2419 : using ::rtl::OStringToOUString;
2420 : using ::rtl::OUStringToOString;
2421 : using ::rtl::OUStringLiteral;
2422 : #endif
2423 :
2424 : #endif /* _RTL_USTRING_HXX */
2425 :
2426 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|