1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
|
/*************************************************************************
*
* $RCSfile: ustring.hxx,v $
*
* $Revision: 1.9 $
*
* last change: $Author: hr $ $Date: 2001-09-11 13:07:14 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
*
* - GNU Lesser General Public License Version 2.1
* - Sun Industry Standards Source License Version 1.1
*
* Sun Microsystems Inc., October, 2000
*
* GNU Lesser General Public License Version 2.1
* =============================================
* Copyright 2000 by Sun Microsystems, Inc.
* 901 San Antonio Road, Palo Alto, CA 94303, USA
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License version 2.1, as published by the Free Software Foundation.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
* MA 02111-1307 USA
*
*
* Sun Industry Standards Source License Version 1.1
* =================================================
* The contents of this file are subject to the Sun Industry Standards
* Source License Version 1.1 (the "License"); You may not use this file
* except in compliance with the License. You may obtain a copy of the
* License at http://www.openoffice.org/license.html.
*
* Software provided under this License is provided on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
* WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
* MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
* See the License for the specific provisions governing your rights and
* obligations concerning the Software.
*
* The Initial Developer of the Original Code is: Sun Microsystems, Inc.
*
* Copyright: 2000 by Sun Microsystems, Inc.
*
* All Rights Reserved.
*
* Contributor(s): _______________________________________
*
*
************************************************************************/
#ifndef _RTL_USTRING_HXX_
#define _RTL_USTRING_HXX_
#ifdef __cplusplus
#ifndef _RTL_USTRING_H_
#include <rtl/ustring.h>
#endif
#ifndef _RTL_STRING_HXX_
#include <rtl/string.hxx>
#endif
#ifndef _RTL_MEMORY_H_
#include <rtl/memory.h>
#endif
class String;
namespace rtl
{
/* ======================================================================= */
/**
This String class provide base functionality for C++ like Unicode
character array handling. The advantage of this class is, that it
handle all the memory managament for you - and it do it
more efficient. If you assign a string to another string, the
data of both strings are shared (without any copy operation or
memory allocation) as long as you change the string. This class
stores also the length of the string, so that many operations are
faster as the C-str-functions.
This class provide only readonly string handling. So you could create
a string and you could only query the content from this string.
It provide also functionality to change the string, but this results
in every case in a new string instance (in the most cases with an
memory allocation). You don't have functionality to change the
content of the string. If you want change the string content, than
you should us the OStringBuffer class, which provide these
functionality and avoid to much memory allocation.
The design of this class is similar to the string classes in Java
and so more people should have fewer understanding problems when they
use this class.
*/
class OUString
{
friend class ::String;
public:
rtl_uString * pData;
private:
class DO_NOT_ACQUIRE;
OUString( rtl_uString * value, DO_NOT_ACQUIRE * )
{
pData = value;
}
public:
/**
New string containing no characters.
*/
OUString() SAL_THROW(())
{
pData = 0;
rtl_uString_new( &pData );
}
/**
New string from OUString.
@param str a OUString.
*/
OUString( const OUString & str ) SAL_THROW(())
{
pData = str.pData;
rtl_uString_acquire( pData );
}
/**
New string from OUString data.
@param str a OUString data.
*/
OUString( rtl_uString * str ) SAL_THROW(())
{
pData = str;
rtl_uString_acquire( pData );
}
/**
New string from a Unicode character buffer array.
@param value a NULL-terminated Unicode character array.
*/
OUString( const sal_Unicode * value ) SAL_THROW(())
{
pData = 0;
rtl_uString_newFromStr( &pData, value );
}
/**
New string from a Uniocde character buffer array.
@param value a Unicode character array.
@param length the number of character which should be copied.
The character array length must be greater or
equal than this value.
*/
OUString( const sal_Unicode * value, sal_Int32 length ) SAL_THROW(())
{
pData = 0;
rtl_uString_newFromStr_WithLength( &pData, value, length );
}
/**
New string from a 8-Bit character buffer array.
@param value a 8-Bit character array.
@param length the number of character which should be converted.
The 8-Bit character array length must be
greater or equal than this value.
@param encoding the text encoding from which the 8-Bit character
sequence should be converted.
@param convertFlags flags which controls the conversion.
see RTL_TEXTTOUNICODE_FLAGS_...
*/
OUString( const sal_Char * value, sal_Int32 length,
rtl_TextEncoding encoding,
sal_uInt32 convertFlags = OSTRING_TO_OUSTRING_CVTFLAGS ) SAL_THROW(())
{
pData = 0;
rtl_string2UString( &pData, value, length, encoding, convertFlags );
}
OUString( const String & value ) SAL_THROW(());
/**
Release the string data.
*/
~OUString() SAL_THROW(())
{
rtl_uString_release( pData );
}
/**
Assign a new string.
@param str a OUString.
*/
OUString & operator=( const OUString & str ) SAL_THROW(())
{
rtl_uString_assign( &pData, str.pData );
return *this;
}
/**
Append a string to this string.
@param str a OUString.
*/
OUString & operator+=( const OUString & str ) SAL_THROW(())
{
rtl_uString_newConcat( &pData, pData, str.pData );
return *this;
}
/**
Returns the length of this string.
The length is equal to the number of Unicode characters in this string.
@return the length of the sequence of characters represented by this
object.
*/
sal_Int32 getLength() const SAL_THROW(()) { return pData->length; }
/**
Returns a pointer to the Unicode character buffer from this string.
It isn't necessarily NULL terminated.
@return a pointer to the Unicode characters buffer from this object.
*/
operator const sal_Unicode *() const SAL_THROW(()) { return pData->buffer; }
/**
Returns a pointer to the Unicode character buffer from this string.
It isn't necessarily NULL terminated.
@return a pointer to the Unicode characters buffer from this object.
*/
const sal_Unicode * getStr() const SAL_THROW(()) { return pData->buffer; }
/**
Compares two strings.
The comparison is based on the numeric value of each character in
the strings and return a value indicating their relationship.
This function can't be used for language specific sorting.
@param str the object to be compared.
@return <code>0</code> - if both strings are equal
<code>< 0</code> - if this string is less than the string argument
<code>> 0</code> - if this string is greater than the string argument
*/
sal_Int32 compareTo( const OUString & str ) const SAL_THROW(())
{
return rtl_ustr_compare_WithLength( pData->buffer, pData->length,
str.pData->buffer, str.pData->length );
}
/**
Compares two strings with an maximum count of characters.
The comparison is based on the numeric value of each character in
the strings and return a value indicating their relationship.
This function can't be used for language specific sorting.
@param str the object to be compared.
@param maxLength the maximum count of characters to be compared.
@return <code>0</code> - if both strings are equal
<code>< 0</code> - if this string is less than the string argument
<code>> 0</code> - if this string is greater than the string argument
*/
sal_Int32 compareTo( const OUString & str, sal_Int32 maxLength ) const SAL_THROW(())
{
return rtl_ustr_shortenedCompare_WithLength( pData->buffer, pData->length,
str.pData->buffer, str.pData->length, maxLength );
}
/**
Compares two strings in reverse order.
The comparison is based on the numeric value of each character in
the strings and return a value indicating their relationship.
This function can't be used for language specific sorting.
@param str the object to be compared.
@return <code>0</code> - if both strings are equal
<code>< 0</code> - if this string is less than the string argument
<code>> 0</code> - if this string is greater than the string argument
*/
sal_Int32 reverseCompareTo( const OUString & str ) const SAL_THROW(())
{
return rtl_ustr_reverseCompare_WithLength( pData->buffer, pData->length,
str.pData->buffer, str.pData->length );
}
/**
Perform a comparison of two strings.
The result is true if and only if second string
represents the same sequence of characters as the first string.
This function can't be used for language specific comparison.
@param str the object to be compared.
@return sal_True if the strings are equal;
sal_False, otherwise.
*/
sal_Bool equals( const OUString & str ) const SAL_THROW(())
{
if ( pData->length != str.pData->length )
return sal_False;
if ( pData == str.pData )
return sal_True;
return rtl_ustr_reverseCompare_WithLength( pData->buffer, pData->length,
str.pData->buffer, str.pData->length ) == 0;
}
/**
Perform a ASCII lowercase comparison of two strings.
The result is true if and only if second string
represents the same sequence of characters as the first string,
ignoring the case.
Character values between 65 and 90 (ASCII A-Z) are interpreted as
values between 97 and 122 (ASCII a-z).
This function can't be used for language specific comparison.
@param str the object to be compared.
@return sal_True if the strings are equal;
sal_False, otherwise.
*/
sal_Bool equalsIgnoreAsciiCase( const OUString & str ) const SAL_THROW(())
{
if ( pData->length != str.pData->length )
return sal_False;
if ( pData == str.pData )
return sal_True;
return rtl_ustr_compareIgnoreAsciiCase_WithLength( pData->buffer, pData->length,
str.pData->buffer, str.pData->length ) == 0;
}
/**
Perform a comparison of a substring in this string.
The result is true if and only if second string
represents the same sequence of characters in the first string at
the given position.
This function can't be used for language specific comparison.
@param str the object (substring) to be compared.
@param fromIndex the index to start the comparion from.
The index must be greater or equal than 0
and less or equal as the string length.
@return sal_True if str match with the characters in the string
at the given position;
sal_False, otherwise.
*/
sal_Bool match( const OUString & str, sal_Int32 fromIndex = 0 ) const SAL_THROW(())
{
return rtl_ustr_shortenedCompare_WithLength( pData->buffer+fromIndex, pData->length-fromIndex,
str.pData->buffer, str.pData->length, str.pData->length ) == 0;
}
/**
Perform a ASCII lowercase comparison of a substring in this string.
The result is true if and only if second string
represents the same sequence of characters in the first string at
the given position.
Character values between 65 and 90 (ASCII A-Z) are interpreted as
values between 97 and 122 (ASCII a-z).
This function can't be used for language specific comparison.
@param str the object (substring) to be compared.
@param fromIndex the index to start the comparion from.
The index must be greater or equal than 0
and less or equal as the string length.
@return sal_True if str match with the characters in the string
at the given position;
sal_False, otherwise.
*/
sal_Bool matchIgnoreAsciiCase( const OUString & str, sal_Int32 fromIndex = 0 ) const SAL_THROW(())
{
return rtl_ustr_shortenedCompareIgnoreAsciiCase_WithLength( pData->buffer+fromIndex, pData->length-fromIndex,
str.pData->buffer, str.pData->length,
str.pData->length ) == 0;
}
/**
Compares two strings.
The comparison is based on the numeric value of each character in
the strings and return a value indicating their relationship.
Since this method is optimized for performance, the ASCII character
values are not converted in any way. The caller has to make sure that
all ASCII characters are in the allowed range between 0 and
127. The ASCII string must be NULL-terminated.
This function can't be used for language specific sorting.
@param asciiStr the 8-Bit ASCII character string to be compared.
@return <code>0</code> - if both strings are equal
<code>< 0</code> - if this string is less than the string argument
<code>> 0</code> - if this string is greater than the string argument
*/
sal_Int32 compareToAscii( const sal_Char* asciiStr ) const SAL_THROW(())
{
return rtl_ustr_ascii_compare_WithLength( pData->buffer, pData->length, asciiStr );
}
/**
Compares two strings with an maximum count of characters.
The comparison is based on the numeric value of each character in
the strings and return a value indicating their relationship.
Since this method is optimized for performance, the ASCII character
values are not converted in any way. The caller has to make sure that
all ASCII characters are in the allowed range between 0 and
127. The ASCII string must be NULL-terminated.
This function can't be used for language specific sorting.
@param asciiStr the 8-Bit ASCII character string to be compared.
@param maxLength the maximum count of characters to be compared.
@return <code>0</code> - if both strings are equal
<code>< 0</code> - if this string is less than the string argument
<code>> 0</code> - if this string is greater than the string argument
*/
sal_Int32 compareToAscii( const sal_Char * asciiStr, sal_Int32 maxLength ) const SAL_THROW(())
{
return rtl_ustr_ascii_shortenedCompare_WithLength( pData->buffer, pData->length,
asciiStr, maxLength );
}
/**
Compares two strings in reverse order. This could be useful,
if normally both strings start with the same content.
The comparison is based on the numeric value of each character in
the strings and return a value indicating their relationship.
Since this method is optimized for performance, the ASCII character
values are not converted in any way. The caller has to make sure that
all ASCII characters are in the allowed range between 0 and
127. The ASCII string must be NULL-terminated and must be greater or
equal as asciiStrLength.
This function can't be used for language specific sorting.
@param asciiStr the 8-Bit ASCII character string to be compared.
@param asciiStrLength the length of the ascii string
@return <code>0</code> - if both strings are equal
<code>< 0</code> - if this string is less than the string argument
<code>> 0</code> - if this string is greater than the string argument
*/
sal_Int32 reverseCompareToAsciiL( const sal_Char * asciiStr, sal_Int32 asciiStrLength ) const SAL_THROW(())
{
return rtl_ustr_asciil_reverseCompare_WithLength( pData->buffer, pData->length,
asciiStr, asciiStrLength );
}
/**
Perform a comparison of two strings.
The result is true if and only if second string
represents the same sequence of characters as the first string.
Since this method is optimized for performance, the ASCII character
values are not converted in any way. The caller has to make sure that
all ASCII characters are in the allowed range between 0 and
127. The ASCII string must be NULL-terminated.
This function can't be used for language specific comparison.
@param asciiStr the 8-Bit ASCII character string to be compared.
@return sal_True if the strings are equal;
sal_False, otherwise.
*/
sal_Bool equalsAscii( const sal_Char* asciiStr ) const SAL_THROW(())
{
return rtl_ustr_ascii_compare_WithLength( pData->buffer, pData->length,
asciiStr ) == 0;
}
/**
Perform a comparison of two strings.
The result is true if and only if second string
represents the same sequence of characters as the first string.
Since this method is optimized for performance, the ASCII character
values are not converted in any way. The caller has to make sure that
all ASCII characters are in the allowed range between 0 and
127. The ASCII string must be NULL-terminated and must be greater or
equal as asciiStrLength.
This function can't be used for language specific comparison.
@param asciiStr the 8-Bit ASCII character string to be compared.
@param asciiStrLength the length of the ascii string
@return sal_True if the strings are equal;
sal_False, otherwise.
*/
sal_Bool equalsAsciiL( const sal_Char* asciiStr, sal_Int32 asciiStrLength ) const SAL_THROW(())
{
if ( pData->length != asciiStrLength )
return sal_False;
return rtl_ustr_asciil_reverseCompare_WithLength( pData->buffer, pData->length,
asciiStr, asciiStrLength ) == 0;
}
/**
Perform a ASCII lowercase comparison of two strings.
The result is true if and only if second string
represents the same sequence of characters as the first string,
ignoring the case.
Character values between 65 and 90 (ASCII A-Z) are interpreted as
values between 97 and 122 (ASCII a-z).
Since this method is optimized for performance, the ASCII character
values are not converted in any way. The caller has to make sure that
all ASCII characters are in the allowed range between 0 and
127. The ASCII string must be NULL-terminated.
This function can't be used for language specific comparison.
@param asciiStr the 8-Bit ASCII character string to be compared.
@return sal_True if the strings are equal;
sal_False, otherwise.
*/
sal_Bool equalsIgnoreAsciiCaseAscii( const sal_Char * asciiStr ) const SAL_THROW(())
{
return rtl_ustr_ascii_compareIgnoreAsciiCase_WithLength( pData->buffer, pData->length, asciiStr ) == 0;
}
/**
Perform a ASCII lowercase comparison of two strings.
The result is true if and only if second string
represents the same sequence of characters as the first string,
ignoring the case.
Character values between 65 and 90 (ASCII A-Z) are interpreted as
values between 97 and 122 (ASCII a-z).
Since this method is optimized for performance, the ASCII character
values are not converted in any way. The caller has to make sure that
all ASCII characters are in the allowed range between 0 and
127. The ASCII string must be NULL-terminated and must be greater or
equal as asciiStrLength.
This function can't be used for language specific comparison.
@param asciiStr the 8-Bit ASCII character string to be compared.
@param asciiStrLength the length of the ascii string
@return sal_True if the strings are equal;
sal_False, otherwise.
*/
sal_Bool equalsIgnoreAsciiCaseAsciiL( const sal_Char * asciiStr, sal_Int32 asciiStrLength ) const SAL_THROW(())
{
if ( pData->length != asciiStrLength )
return sal_False;
return rtl_ustr_ascii_compareIgnoreAsciiCase_WithLength( pData->buffer, pData->length, asciiStr ) == 0;
}
/**
Perform a comparison of a substring in this string.
The result is true if and only if second string
represents the same sequence of characters in the first string at
the given position.
Since this method is optimized for performance, the ASCII character
values are not converted in any way. The caller has to make sure that
all ASCII characters are in the allowed range between 0 and
127. The ASCII string must be NULL-terminated and must be greater or
equal as asciiStrLength.
This function can't be used for language specific comparison.
@param str the object (substring) to be compared.
@param fromIndex the index to start the comparion from.
The index must be greater or equal than 0
and less or equal as the string length.
@return sal_True if str match with the characters in the string
at the given position;
sal_False, otherwise.
*/
sal_Bool matchAsciiL( const sal_Char* asciiStr, sal_Int32 asciiStrLength, sal_Int32 fromIndex = 0 ) const SAL_THROW(())
{
return rtl_ustr_ascii_shortenedCompare_WithLength( pData->buffer+fromIndex, pData->length-fromIndex,
asciiStr, asciiStrLength ) == 0;
}
/**
Perform a ASCII lowercase comparison of a substring in this string.
The result is true if and only if second string
represents the same sequence of characters in the first string at
the given position.
Character values between 65 and 90 (ASCII A-Z) are interpreted as
values between 97 and 122 (ASCII a-z).
Since this method is optimized for performance, the ASCII character
values are not converted in any way. The caller has to make sure that
all ASCII characters are in the allowed range between 0 and
127. The ASCII string must be NULL-terminated and must be greater or
equal as asciiStrLength.
This function can't be used for language specific comparison.
@param asciiStr the 8-Bit ASCII character string to be compared.
@param asciiStrLength the length of the ascii string
@param fromIndex the index to start the comparion from.
The index must be greater or equal than 0
and less or equal as the string length.
@return sal_True if str match with the characters in the string
at the given position;
sal_False, otherwise.
*/
sal_Bool matchIgnoreAsciiCaseAsciiL( const sal_Char* asciiStr, sal_Int32 asciiStrLength, sal_Int32 fromIndex = 0 ) const SAL_THROW(())
{
return rtl_ustr_ascii_shortenedCompareIgnoreAsciiCase_WithLength( pData->buffer+fromIndex, pData->length-fromIndex,
asciiStr, asciiStrLength ) == 0;
}
friend sal_Bool operator == ( const OUString& rStr1, const OUString& rStr2 ) SAL_THROW(())
{ return rStr1.getLength() == rStr2.getLength() && rStr1.compareTo( rStr2 ) == 0; }
friend sal_Bool operator == ( const OUString& rStr1, const sal_Unicode * pStr2 ) SAL_THROW(())
{ return rStr1.compareTo( pStr2 ) == 0; }
friend sal_Bool operator == ( const sal_Unicode * pStr1, const OUString& rStr2 ) SAL_THROW(())
{ return OUString( pStr1 ).compareTo( rStr2 ) == 0; }
friend sal_Bool operator != ( const OUString& rStr1, const OUString& rStr2 ) SAL_THROW(())
{ return !(operator == ( rStr1, rStr2 )); }
friend sal_Bool operator != ( const OUString& rStr1, const sal_Unicode * pStr2 ) SAL_THROW(())
{ return !(operator == ( rStr1, pStr2 )); }
friend sal_Bool operator != ( const sal_Unicode * pStr1, const OUString& rStr2 ) SAL_THROW(())
{ return !(operator == ( pStr1, rStr2 )); }
friend sal_Bool operator < ( const OUString& rStr1, const OUString& rStr2 ) SAL_THROW(())
{ return rStr1.compareTo( rStr2 ) < 0; }
friend sal_Bool operator > ( const OUString& rStr1, const OUString& rStr2 ) SAL_THROW(())
{ return rStr1.compareTo( rStr2 ) > 0; }
friend sal_Bool operator <= ( const OUString& rStr1, const OUString& rStr2 ) SAL_THROW(())
{ return rStr1.compareTo( rStr2 ) <= 0; }
friend sal_Bool operator >= ( const OUString& rStr1, const OUString& rStr2 ) SAL_THROW(())
{ return rStr1.compareTo( rStr2 ) >= 0; }
/**
Returns a hashcode for this string.
@return a hash code value for this object.
*/
sal_Int32 hashCode() const SAL_THROW(())
{
return rtl_ustr_hashCode_WithLength( pData->buffer, pData->length );
}
/**
Returns the index within this string of the first occurrence of the
specified character, starting the search at the specified index.
@param ch character to be located.
@param fromIndex the index to start the search from.
The index must be greater or equal than 0
and less or equal as the string length.
@return the index of the first occurrence of the character in the
character sequence represented by this string that is
greater than or equal to fromIndex, or
<code>-1</code> if the character does not occur.
*/
sal_Int32 indexOf( sal_Unicode ch, sal_Int32 fromIndex = 0 ) const SAL_THROW(())
{
sal_Int32 ret = rtl_ustr_indexOfChar_WithLength( pData->buffer+fromIndex, pData->length-fromIndex, ch );
return (ret < 0 ? ret : ret+fromIndex);
}
/**
Returns the index within this string of the last occurrence of the
specified character, searching backward starting at the end.
@param ch character to be located.
@return the index of the last occurrence of the character in the
character sequence represented by this string, or
<code>-1</code> if the character does not occur.
*/
sal_Int32 lastIndexOf( sal_Unicode ch ) const SAL_THROW(())
{
return rtl_ustr_lastIndexOfChar_WithLength( pData->buffer, pData->length, ch );
}
/**
Returns the index within this string of the last occurrence of the
specified character, searching backward starting at the specified index.
@param ch character to be located.
@return the index of the last occurrence of the character in the
character sequence represented by this string that
is less or than or equal to fromIndex, or <code>-1</code>
if the character does not occur before that point.
*/
sal_Int32 lastIndexOf( sal_Unicode ch, sal_Int32 fromIndex ) const SAL_THROW(())
{
return rtl_ustr_lastIndexOfChar_WithLength( pData->buffer, fromIndex, ch );
}
/**
Returns the index within this string of the first occurrence of the
specified substring, starting at the specified index.
If str doesn't include any character, always <code>-1</code> is
returned. This is also the case, if both strings are empty.
@param str the substring to search for.
@param fromIndex the index to start the search from.
@return If the string argument occurs one or more times as a substring
within this string at the starting index, then the index
of the first character of the first such substring is
returned. If it does not occur as a substring starting
at fromIndex or beyond, <code>-1</code> is returned.
*/
sal_Int32 indexOf( const OUString & str, sal_Int32 fromIndex = 0 ) const SAL_THROW(())
{
sal_Int32 ret = rtl_ustr_indexOfStr_WithLength( pData->buffer+fromIndex, pData->length-fromIndex,
str.pData->buffer, str.pData->length );
return (ret < 0 ? ret : ret+fromIndex);
}
/**
Returns the index within this string of the last occurrence of
the specified substring, searching backward starting at the end.
The returned index indicates the starting index of the substring
in this string.
If str doesn't include any character, always <code>-1</code> is
returned. This is also the case, if both strings are empty.
@param str the substring to search for.
@return If the string argument occurs one or more times as a substring
within this string, then the index of the first character of
the last such substring is returned. If it does not occur as
a substring, <code>-1</code> is returned.
*/
sal_Int32 lastIndexOf( const OUString & str ) const SAL_THROW(())
{
return rtl_ustr_lastIndexOfStr_WithLength( pData->buffer, pData->length,
str.pData->buffer, str.pData->length );
}
/**
Returns the index within this string of the last occurrence of
the specified substring, searching backward starting at the end.
The returned index indicates the starting index of the substring
in this string.
If str doesn't include any character, always <code>-1</code> is
returned. This is also the case, if both strings are empty.
@param str the substring to search for.
@param fromIndex the index to start the search from.
@return If the string argument occurs one or more times as a substring
within this string at the starting index, then the index
of the first character of the last such substring is
returned. If it does not occur as a substring starting
at fromIndex or earlier, <code>-1</code> is returned.
*/
sal_Int32 lastIndexOf( const OUString & str, sal_Int32 fromIndex ) const SAL_THROW(())
{
return rtl_ustr_lastIndexOfStr_WithLength( pData->buffer, fromIndex,
str.pData->buffer, str.pData->length );
}
/**
Returns a new string that is a substring of this string. The
substring begins at the specified beginIndex.
@param beginIndex the beginning index, inclusive.
@return the specified substring.
*/
OUString copy( sal_Int32 beginIndex ) const SAL_THROW(())
{
if ( beginIndex == 0 )
return *this;
else
{
rtl_uString* pNew = 0;
rtl_uString_newFromStr_WithLength( &pNew, pData->buffer+beginIndex, getLength()-beginIndex );
return OUString( pNew, (DO_NOT_ACQUIRE*)0 );
}
}
/**
Returns a new string that is a substring of this string. The
substring begins at the specified beginIndex and
extends to the character at index endIndex - 1.
@param beginIndex the beginning index, inclusive.
@param count the number of characters.
@return the specified substring.
*/
OUString copy( sal_Int32 beginIndex, sal_Int32 count ) const SAL_THROW(())
{
if ( (beginIndex == 0) && (count == getLength()) )
return *this;
else
{
rtl_uString* pNew = 0;
rtl_uString_newFromStr_WithLength( &pNew, pData->buffer+beginIndex, count );
return OUString( pNew, (DO_NOT_ACQUIRE*)0 );
}
}
/**
Concatenates the specified string to the end of this string.
@param str the string that is concatenated to the end
of this string.
@return a string that represents the concatenation of this string
followed by the string argument.
*/
OUString concat( const OUString & str ) const SAL_THROW(())
{
rtl_uString* pNew = 0;
rtl_uString_newConcat( &pNew, pData, str.pData );
return OUString( pNew, (DO_NOT_ACQUIRE*)0 );
}
friend OUString operator+( const OUString& rStr1, const OUString& rStr2 ) SAL_THROW(())
{
return rStr1.concat( rStr2 );
}
/**
Returns a new string resulting from replacing n = count characters
from position index in this string with newStr.
@param index the replacing index in str.
The index must be greater or equal as 0 and
less or equal as the length of the string.
@param count the count of charcters that will replaced
The count must be greater or equal as 0 and
less or equal as the length of the string minus index.
@param newStr the new substring.
@return the new string.
*/
OUString replaceAt( sal_Int32 index, sal_Int32 count, const OUString& newStr ) const SAL_THROW(())
{
rtl_uString* pNew = 0;
rtl_uString_newReplaceStrAt( &pNew, pData, index, count, newStr.pData );
return OUString( pNew, (DO_NOT_ACQUIRE*)0 );
}
/**
Returns a new string resulting from replacing all occurrences of
oldChar in this string with newChar.
If the character oldChar does not occur in the character sequence
represented by this object, then the string is assigned with
str.
@param oldChar the old character.
@param newChar the new character.
@return a string derived from this string by replacing every
occurrence of oldChar with newChar.
*/
OUString replace( sal_Unicode oldChar, sal_Unicode newChar ) const SAL_THROW(())
{
rtl_uString* pNew = 0;
rtl_uString_newReplace( &pNew, pData, oldChar, newChar );
return OUString( pNew, (DO_NOT_ACQUIRE*)0 );
}
/**
Converts from this string all ASCII uppercase characters (65-90)
to ASCII lowercase characters (97-122).
This function can't be used for language specific conversion.
If the string doesn't contain characters which must be converted,
then the new string is assigned with str.
@return the string, converted to ASCII lowercase.
*/
OUString toAsciiLowerCase() const SAL_THROW(())
{
rtl_uString* pNew = 0;
rtl_uString_newToAsciiLowerCase( &pNew, pData );
return OUString( pNew, (DO_NOT_ACQUIRE*)0 );
}
/**
Converts from this string all ASCII lowercase characters (97-122)
to ASCII uppercase characters (65-90).
This function can't be used for language specific conversion.
If the string doesn't contain characters which must be converted,
then the new string is assigned with str.
@return the string, converted to ASCII uppercase.
*/
OUString toAsciiUpperCase() const SAL_THROW(())
{
rtl_uString* pNew = 0;
rtl_uString_newToAsciiUpperCase( &pNew, pData );
return OUString( pNew, (DO_NOT_ACQUIRE*)0 );
}
/**
Returns a new string resulting from removing white space from both ends
of the string. All characters that have codes less than or equal to
32 (the space character) are considered to be white space.
If the string doesn't contain white spaces at both ends,
then the new string is assigned with str.
@return the string, with white space removed from the front and end.
*/
OUString trim() const SAL_THROW(())
{
rtl_uString* pNew = 0;
rtl_uString_newTrim( &pNew, pData );
return OUString( pNew, (DO_NOT_ACQUIRE*)0 );
}
/**
Returns a token in the string.
Example:
sal_Int32 nIndex = 0;
do
{
...
OUString aToken = aStr.getToken( 0, ';', nIndex );
...
}
while ( nIndex >= 0 );
@param token the number of the token to return. The number
must be greater or equal as 0.
@param cTok the character which seperate the tokens.
@param index the position at which the token is searched in the
string.
The index must be greater or equal as 0 and
less or equal as the length of the string.
This param is set to the position of the
next token or to -1, if it is the last token.
@return the token
*/
OUString getToken( sal_Int32 token, sal_Unicode cTok, sal_Int32& index ) const SAL_THROW(())
{
rtl_uString * pNew = 0;
index = rtl_uString_getToken( &pNew, pData, token, cTok, index );
return OUString( pNew, (DO_NOT_ACQUIRE *)0 );
}
/**
Returns the Boolean value from this string.
This function can't be used for language specific conversion.
@return sal_True, if the string is 1 or "True" in any ASCII case.
sal_False in any other case.
*/
sal_Bool toBoolean() const SAL_THROW(())
{
return rtl_ustr_toBoolean( pData->buffer );
}
/**
Returns the first character from this string.
@return the first character from this string or 0, if this string
is emptry.
*/
sal_Unicode toChar() const SAL_THROW(())
{
return pData->buffer[0];
}
/**
Returns the int32 value from this string.
This function can't be used for language specific conversion.
@param radix the radix (between 2 and 36)
@return the int32 represented from this string.
0 if this string represents no number.
*/
sal_Int32 toInt32( sal_Int16 radix = 10 ) const SAL_THROW(())
{
return rtl_ustr_toInt32( pData->buffer, radix );
}
/**
Returns the int64 value from this string.
This function can't be used for language specific conversion.
@param radix the radix (between 2 and 36)
@return the int64 represented from this string.
0 if this string represents no number.
*/
sal_Int64 toInt64( sal_Int16 radix = 10 ) const SAL_THROW(())
{
return rtl_ustr_toInt64( pData->buffer, radix );
}
/**
Returns the float value from this string.
This function can't be used for language specific conversion.
@return the float represented from this string.
0.0 if this string represents no number.
*/
float toFloat() const SAL_THROW(())
{
return rtl_ustr_toFloat( pData->buffer );
}
/**
Returns the double value from this string.
This function can't be used for language specific conversion.
@return the double represented from this string.
0.0 if this string represents no number.
*/
double toDouble() const SAL_THROW(())
{
return rtl_ustr_toDouble( pData->buffer );
}
/**
Returns the string representation of the sal_Bool argument.
If the sal_Bool is true, the string "true" is returned.
If the sal_Bool is false, the string "false" is returned.
This function can't be used for language specific conversion.
@param b a sal_Bool.
@return a string with the string representation of the argument.
*/
static OUString valueOf( sal_Bool b ) SAL_THROW(())
{
sal_Unicode aBuf[RTL_USTR_MAX_VALUEOFBOOLEAN];
rtl_uString* pNewData = 0;
rtl_uString_newFromStr_WithLength( &pNewData, aBuf, rtl_ustr_valueOfBoolean( aBuf, b ) );
return OUString( pNewData, (DO_NOT_ACQUIRE*)0 );
}
/**
Returns the string representation of the char argument.
@param c a character.
@return a string with the string representation of the argument.
*/
static OUString valueOf( sal_Unicode c ) SAL_THROW(())
{
return OUString( &c, 1 );
}
/**
Returns the string representation of the int argument.
This function can't be used for language specific conversion.
@param i a int32.
@param radix the radix (between 2 and 36)
@return a string with the string representation of the argument.
*/
static OUString valueOf( sal_Int32 i, sal_Int16 radix = 10 ) SAL_THROW(())
{
sal_Unicode aBuf[RTL_USTR_MAX_VALUEOFINT32];
rtl_uString* pNewData = 0;
rtl_uString_newFromStr_WithLength( &pNewData, aBuf, rtl_ustr_valueOfInt32( aBuf, i, radix ) );
return OUString( pNewData, (DO_NOT_ACQUIRE*)0 );
}
/**
Returns the string representation of the long argument.
This function can't be used for language specific conversion.
@param l a int64.
@param radix the radix (between 2 and 36)
@return a string with the string representation of the argument.
*/
static OUString valueOf( sal_Int64 l, sal_Int16 radix = 10 ) SAL_THROW(())
{
sal_Unicode aBuf[RTL_USTR_MAX_VALUEOFINT64];
rtl_uString* pNewData = 0;
rtl_uString_newFromStr_WithLength( &pNewData, aBuf, rtl_ustr_valueOfInt64( aBuf, l, radix ) );
return OUString( pNewData, (DO_NOT_ACQUIRE*)0 );
}
/**
Returns the string representation of the float argument.
This function can't be used for language specific conversion.
@param f a float.
@return a string with the string representation of the argument.
*/
static OUString valueOf( float f ) SAL_THROW(())
{
sal_Unicode aBuf[RTL_USTR_MAX_VALUEOFFLOAT];
rtl_uString* pNewData = 0;
rtl_uString_newFromStr_WithLength( &pNewData, aBuf, rtl_ustr_valueOfFloat( aBuf, f ) );
return OUString( pNewData, (DO_NOT_ACQUIRE*)0 );
}
/**
Returns the string representation of the double argument.
This function can't be used for language specific conversion.
@param d a double.
@return a string with the string representation of the argument.
*/
static OUString valueOf( double d ) SAL_THROW(())
{
sal_Unicode aBuf[RTL_USTR_MAX_VALUEOFDOUBLE];
rtl_uString* pNewData = 0;
rtl_uString_newFromStr_WithLength( &pNewData, aBuf, rtl_ustr_valueOfDouble( aBuf, d ) );
return OUString( pNewData, (DO_NOT_ACQUIRE*)0 );
}
/**
Returns a OUString copied without conversion from an ASCII
character string.
Since this method is optimized for performance, the ASCII character
values are not converted in any way. The caller has to make sure that
all ASCII characters are in the allowed range between 0 and
127. The ASCII string must be NULL-terminated.
@param value the 8-Bit ASCII character string
@return a string with the string representation of the argument.
*/
static OUString createFromAscii( const sal_Char * value ) SAL_THROW(())
{
rtl_uString* pNew = 0;
rtl_uString_newFromAscii( &pNew, value );
return OUString( pNew, (DO_NOT_ACQUIRE*)0 );
}
};
/* ======================================================================= */
struct OUStringHash
{
size_t operator()(const rtl::OUString& rString) const
{ return (size_t)rString.hashCode(); }
};
/* ======================================================================= */
inline OUString OStringToOUString( const OString & rStr,
rtl_TextEncoding encoding,
sal_uInt32 convertFlags = OSTRING_TO_OUSTRING_CVTFLAGS )
{
return OUString( rStr.getStr(), rStr.getLength(), encoding, convertFlags );
}
inline OString OUStringToOString( const OUString & rUnicode,
rtl_TextEncoding encoding,
sal_uInt32 convertFlags = OUSTRING_TO_OSTRING_CVTFLAGS )
{
return OString( rUnicode.getStr(), rUnicode.getLength(), encoding, convertFlags );
}
/* ======================================================================= */
} /* Namespace */
#endif /* __cplusplus */
#endif /* _RTL_USTRING_HXX */
|