1 /* vim:set ts=2 sw=2 et cindent: */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
15 * The Original Code is Mozilla.
17 * The Initial Developer of the Original Code is IBM Corporation.
18 * Portions created by IBM Corporation are Copyright (C) 2003
19 * IBM Corporation. All Rights Reserved.
22 * Darin Fisher <darin@meer.net>
23 * Benjamin Smedberg <benjamin@smedbergs.us>
24 * Ben Turner <mozilla@songbirdnest.com>
25 * Prasad Sunkari <prasad@medhas.org>
27 * Alternatively, the contents of this file may be used under the terms of
28 * either the GNU General Public License Version 2 or later (the "GPL"), or
29 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
30 * in which case the provisions of the GPL or the LGPL are applicable instead
31 * of those above. If you wish to allow use of your version of this file only
32 * under the terms of either the GPL or the LGPL, and not to allow others to
33 * use your version of this file under the terms of the MPL, indicate your
34 * decision by deleting the provisions above and replace them with the notice
35 * and other provisions required by the GPL or the LGPL. If you do not delete
36 * the provisions above, a recipient may use your version of this file under
37 * the terms of any one of the MPL, the GPL or the LGPL.
39 * ***** END LICENSE BLOCK ***** */
42 #include "nsCRTGlue.h"
44 #include "nsStringAPI.h"
45 #include "nsXPCOMStrings.h"
51 #define snprintf _snprintf
57 nsAString::BeginReading(const char_type
**begin
, const char_type
**end
) const
59 PRUint32 len
= NS_StringGetData(*this, begin
);
66 const nsAString::char_type
*
67 nsAString::BeginReading() const
69 const char_type
*data
;
70 NS_StringGetData(*this, &data
);
74 const nsAString::char_type
*
75 nsAString::EndReading() const
77 const char_type
*data
;
78 PRUint32 len
= NS_StringGetData(*this, &data
);
83 nsAString::BeginWriting(char_type
**begin
, char_type
**end
, PRUint32 newSize
)
85 PRUint32 len
= NS_StringGetMutableData(*this, newSize
, begin
);
93 nsAString::BeginWriting(PRUint32 aLen
)
96 NS_StringGetMutableData(*this, aLen
, &data
);
100 nsAString::char_type
*
101 nsAString::EndWriting()
104 PRUint32 len
= NS_StringGetMutableData(*this, PR_UINT32_MAX
, &data
);
109 nsAString::SetLength(PRUint32 aLen
)
112 NS_StringGetMutableData(*this, aLen
, &data
);
113 return data
!= nsnull
;
117 nsAString::AssignLiteral(const char *aStr
)
119 PRUint32 len
= strlen(aStr
);
120 PRUnichar
*buf
= BeginWriting(len
);
124 for (; *aStr
; ++aStr
, ++buf
)
129 nsAString::AppendLiteral(const char *aASCIIStr
)
131 PRUint32 appendLen
= strlen(aASCIIStr
);
133 PRUint32 thisLen
= Length();
134 PRUnichar
*begin
, *end
;
135 BeginWriting(&begin
, &end
, appendLen
+ thisLen
);
139 for (begin
+= thisLen
; begin
< end
; ++begin
, ++aASCIIStr
)
144 nsAString::StripChars(const char *aSet
)
146 nsString
copy(*this);
148 const char_type
*source
, *sourceEnd
;
149 copy
.BeginReading(&source
, &sourceEnd
);
156 char_type
*curDest
= dest
;
158 for (; source
< sourceEnd
; ++source
) {
160 for (test
= aSet
; *test
; ++test
) {
161 if (*source
== char_type(*test
))
166 // not stripped, copy this char
172 SetLength(curDest
- dest
);
176 nsAString::Trim(const char *aSet
, PRBool aLeading
, PRBool aTrailing
)
178 NS_ASSERTION(aLeading
|| aTrailing
, "Ineffective Trim");
180 const PRUnichar
*start
, *end
;
184 BeginReading(&start
, &end
);
185 for (cutLen
= 0; start
< end
; ++start
, ++cutLen
) {
187 for (test
= aSet
; *test
; ++test
) {
195 NS_StringCutData(*this, 0, cutLen
);
199 PRUint32 len
= BeginReading(&start
, &end
);
201 for (cutLen
= 0; end
>= start
; --end
, ++cutLen
) {
203 for (test
= aSet
; *test
; ++test
) {
211 NS_StringCutData(*this, len
- cutLen
, cutLen
);
217 nsAString::DefaultComparator(const char_type
*a
, const char_type
*b
,
220 for (const char_type
*end
= a
+ len
; a
< end
; ++a
, ++b
) {
224 return *a
< *b
? -1 : 1;
231 nsAString::Compare(const char_type
*other
, ComparatorFunc c
) const
233 const char_type
*cself
;
234 PRUint32 selflen
= NS_StringGetData(*this, &cself
);
235 PRUint32 otherlen
= NS_strlen(other
);
236 PRUint32 comparelen
= selflen
<= otherlen
? selflen
: otherlen
;
238 PRInt32 result
= c(cself
, other
, comparelen
);
240 if (selflen
< otherlen
)
242 else if (selflen
> otherlen
)
249 nsAString::Compare(const self_type
&other
, ComparatorFunc c
) const
251 const char_type
*cself
, *cother
;
252 PRUint32 selflen
= NS_StringGetData(*this, &cself
);
253 PRUint32 otherlen
= NS_StringGetData(other
, &cother
);
254 PRUint32 comparelen
= selflen
<= otherlen
? selflen
: otherlen
;
256 PRInt32 result
= c(cself
, cother
, comparelen
);
258 if (selflen
< otherlen
)
260 else if (selflen
> otherlen
)
267 nsAString::Equals(const char_type
*other
, ComparatorFunc c
) const
269 const char_type
*cself
;
270 PRUint32 selflen
= NS_StringGetData(*this, &cself
);
271 PRUint32 otherlen
= NS_strlen(other
);
273 if (selflen
!= otherlen
)
276 return c(cself
, other
, selflen
) == 0;
280 nsAString::Equals(const self_type
&other
, ComparatorFunc c
) const
282 const char_type
*cself
;
283 const char_type
*cother
;
284 PRUint32 selflen
= NS_StringGetData(*this, &cself
);
285 PRUint32 otherlen
= NS_StringGetData(other
, &cother
);
287 if (selflen
!= otherlen
)
290 return c(cself
, cother
, selflen
) == 0;
294 nsAString::EqualsLiteral(const char *aASCIIString
) const
296 const PRUnichar
*begin
, *end
;
297 BeginReading(&begin
, &end
);
299 for (; begin
< end
; ++begin
, ++aASCIIString
) {
300 if (!*aASCIIString
|| !NS_IsAscii(*begin
) ||
301 (char) *begin
!= *aASCIIString
) {
306 return *aASCIIString
== nsnull
;
310 nsAString::LowerCaseEqualsLiteral(const char *aASCIIString
) const
312 const PRUnichar
*begin
, *end
;
313 BeginReading(&begin
, &end
);
315 for (; begin
< end
; ++begin
, ++aASCIIString
) {
316 if (!*aASCIIString
|| !NS_IsAscii(*begin
) ||
317 NS_ToLower((char) *begin
) != *aASCIIString
) {
322 return *aASCIIString
== nsnull
;
326 nsAString::Find(const self_type
& aStr
, PRUint32 aOffset
,
327 ComparatorFunc c
) const
329 const char_type
*begin
, *end
;
330 PRUint32 selflen
= BeginReading(&begin
, &end
);
332 if (aOffset
> selflen
)
335 const char_type
*other
;
336 PRUint32 otherlen
= aStr
.BeginReading(&other
);
338 if (otherlen
> selflen
- aOffset
)
341 // We want to stop searching otherlen characters before the end of the string
344 for (const char_type
*cur
= begin
+ aOffset
; cur
<= end
; ++cur
) {
345 if (!c(cur
, other
, otherlen
))
351 static PRBool
ns_strnmatch(const PRUnichar
*aStr
, const char* aSubstring
,
354 for (; aLen
; ++aStr
, ++aSubstring
, --aLen
) {
355 if (!NS_IsAscii(*aStr
))
358 if ((char) *aStr
!= *aSubstring
)
365 static PRBool
ns_strnimatch(const PRUnichar
*aStr
, const char* aSubstring
,
368 for (; aLen
; ++aStr
, ++aSubstring
, --aLen
) {
369 if (!NS_IsAscii(*aStr
))
372 if (NS_ToLower((char) *aStr
) != NS_ToLower(*aSubstring
))
380 nsAString::Find(const char *aStr
, PRUint32 aOffset
, PRBool aIgnoreCase
) const
382 PRBool (*match
)(const PRUnichar
*, const char*, PRUint32
) =
383 aIgnoreCase
? ns_strnimatch
: ns_strnmatch
;
385 const char_type
*begin
, *end
;
386 PRUint32 selflen
= BeginReading(&begin
, &end
);
388 if (aOffset
> selflen
)
391 PRUint32 otherlen
= strlen(aStr
);
393 if (otherlen
> selflen
- aOffset
)
396 // We want to stop searching otherlen characters before the end of the string
399 for (const char_type
*cur
= begin
+ aOffset
; cur
<= end
; ++cur
) {
400 if (match(cur
, aStr
, otherlen
)) {
408 nsAString::RFind(const self_type
& aStr
, PRInt32 aOffset
, ComparatorFunc c
) const
410 const char_type
*begin
, *end
;
411 PRUint32 selflen
= BeginReading(&begin
, &end
);
413 const char_type
*other
;
414 PRUint32 otherlen
= aStr
.BeginReading(&other
);
416 if (selflen
< otherlen
)
419 if (aOffset
< 0 || PRUint32(aOffset
) > (selflen
- otherlen
))
422 end
= begin
+ aOffset
;
424 for (const char_type
*cur
= end
; cur
>= begin
; --cur
) {
425 if (!c(cur
, other
, otherlen
))
432 nsAString::RFind(const char *aStr
, PRInt32 aOffset
, PRBool aIgnoreCase
) const
434 PRBool (*match
)(const PRUnichar
*, const char*, PRUint32
) =
435 aIgnoreCase
? ns_strnimatch
: ns_strnmatch
;
437 const char_type
*begin
, *end
;
438 PRUint32 selflen
= BeginReading(&begin
, &end
);
439 PRUint32 otherlen
= strlen(aStr
);
441 if (selflen
< otherlen
)
444 if (aOffset
< 0 || PRUint32(aOffset
) > (selflen
- otherlen
))
447 end
= begin
+ aOffset
;
449 for (const char_type
*cur
= end
; cur
>= begin
; --cur
) {
450 if (match(cur
, aStr
, otherlen
)) {
458 nsAString::FindChar(char_type aChar
, PRUint32 aOffset
) const
460 const char_type
*start
, *end
;
461 PRUint32 len
= BeginReading(&start
, &end
);
465 const char_type
*cur
;
467 for (cur
= start
+ aOffset
; cur
< end
; ++cur
) {
476 nsAString::RFindChar(char_type aChar
) const
478 const PRUnichar
*start
, *end
;
479 BeginReading(&start
, &end
);
487 } while (end
>= start
);
493 nsAString::AppendInt(int aInt
, PRInt32 aRadix
)
510 NS_ERROR("Unrecognized radix");
515 int len
= snprintf(buf
, sizeof(buf
), fmt
, aInt
);
516 buf
[sizeof(buf
) - 1] = '\0';
518 Append(NS_ConvertASCIItoUTF16(buf
, len
));
523 #ifndef XPCOM_GLUE_AVOID_NSPR
525 nsAString::ToInteger(nsresult
*aErrorCode
, PRUint32 aRadix
) const
527 NS_ConvertUTF16toUTF8
narrow(*this);
540 NS_ERROR("Unrecognized radix!");
541 *aErrorCode
= NS_ERROR_INVALID_ARG
;
546 if (PR_sscanf(narrow
.get(), fmt
, &result
) == 1)
549 *aErrorCode
= NS_ERROR_FAILURE
;
553 #endif // XPCOM_GLUE_AVOID_NSPR
558 nsACString::BeginReading(const char_type
**begin
, const char_type
**end
) const
560 PRUint32 len
= NS_CStringGetData(*this, begin
);
567 const nsACString::char_type
*
568 nsACString::BeginReading() const
570 const char_type
*data
;
571 NS_CStringGetData(*this, &data
);
575 const nsACString::char_type
*
576 nsACString::EndReading() const
578 const char_type
*data
;
579 PRUint32 len
= NS_CStringGetData(*this, &data
);
584 nsACString::BeginWriting(char_type
**begin
, char_type
**end
, PRUint32 newSize
)
586 PRUint32 len
= NS_CStringGetMutableData(*this, newSize
, begin
);
593 nsACString::char_type
*
594 nsACString::BeginWriting(PRUint32 aLen
)
597 NS_CStringGetMutableData(*this, aLen
, &data
);
601 nsACString::char_type
*
602 nsACString::EndWriting()
605 PRUint32 len
= NS_CStringGetMutableData(*this, PR_UINT32_MAX
, &data
);
610 nsACString::SetLength(PRUint32 aLen
)
613 NS_CStringGetMutableData(*this, aLen
, &data
);
614 return data
!= nsnull
;
618 nsACString::StripChars(const char *aSet
)
620 nsCString
copy(*this);
622 const char_type
*source
, *sourceEnd
;
623 copy
.BeginReading(&source
, &sourceEnd
);
630 char_type
*curDest
= dest
;
632 for (; source
< sourceEnd
; ++source
) {
634 for (test
= aSet
; *test
; ++test
) {
635 if (*source
== char_type(*test
))
640 // not stripped, copy this char
646 SetLength(curDest
- dest
);
650 nsACString::Trim(const char *aSet
, PRBool aLeading
, PRBool aTrailing
)
652 NS_ASSERTION(aLeading
|| aTrailing
, "Ineffective Trim");
654 const char *start
, *end
;
658 BeginReading(&start
, &end
);
659 for (cutLen
= 0; start
< end
; ++start
, ++cutLen
) {
661 for (test
= aSet
; *test
; ++test
) {
669 NS_CStringCutData(*this, 0, cutLen
);
673 PRUint32 len
= BeginReading(&start
, &end
);
675 for (cutLen
= 0; end
>= start
; --end
, ++cutLen
) {
677 for (test
= aSet
; *test
; ++test
) {
685 NS_CStringCutData(*this, len
- cutLen
, cutLen
);
691 nsACString::DefaultComparator(const char_type
*a
, const char_type
*b
,
694 return memcmp(a
, b
, len
);
698 nsACString::Compare(const char_type
*other
, ComparatorFunc c
) const
700 const char_type
*cself
;
701 PRUint32 selflen
= NS_CStringGetData(*this, &cself
);
702 PRUint32 otherlen
= strlen(other
);
703 PRUint32 comparelen
= selflen
<= otherlen
? selflen
: otherlen
;
705 PRInt32 result
= c(cself
, other
, comparelen
);
707 if (selflen
< otherlen
)
709 else if (selflen
> otherlen
)
716 nsACString::Compare(const self_type
&other
, ComparatorFunc c
) const
718 const char_type
*cself
, *cother
;
719 PRUint32 selflen
= NS_CStringGetData(*this, &cself
);
720 PRUint32 otherlen
= NS_CStringGetData(other
, &cother
);
721 PRUint32 comparelen
= selflen
<= otherlen
? selflen
: otherlen
;
723 PRInt32 result
= c(cself
, cother
, comparelen
);
725 if (selflen
< otherlen
)
727 else if (selflen
> otherlen
)
734 nsACString::Equals(const char_type
*other
, ComparatorFunc c
) const
736 const char_type
*cself
;
737 PRUint32 selflen
= NS_CStringGetData(*this, &cself
);
738 PRUint32 otherlen
= strlen(other
);
740 if (selflen
!= otherlen
)
743 return c(cself
, other
, selflen
) == 0;
747 nsACString::Equals(const self_type
&other
, ComparatorFunc c
) const
749 const char_type
*cself
;
750 const char_type
*cother
;
751 PRUint32 selflen
= NS_CStringGetData(*this, &cself
);
752 PRUint32 otherlen
= NS_CStringGetData(other
, &cother
);
754 if (selflen
!= otherlen
)
757 return c(cself
, cother
, selflen
) == 0;
761 nsACString::Find(const self_type
& aStr
, PRUint32 aOffset
,
762 ComparatorFunc c
) const
764 const char_type
*begin
, *end
;
765 PRUint32 selflen
= BeginReading(&begin
, &end
);
767 if (aOffset
> selflen
)
770 const char_type
*other
;
771 PRUint32 otherlen
= aStr
.BeginReading(&other
);
773 if (otherlen
> selflen
- aOffset
)
776 // We want to stop searching otherlen characters before the end of the string
779 for (const char_type
*cur
= begin
+ aOffset
; cur
<= end
; ++cur
) {
780 if (!c(cur
, other
, otherlen
))
787 nsACString::Find(const char_type
*aStr
, ComparatorFunc c
) const
789 return Find(aStr
, strlen(aStr
), c
);
793 nsACString::Find(const char_type
*aStr
, PRUint32 aLen
, ComparatorFunc c
) const
795 const char_type
*begin
, *end
;
796 PRUint32 selflen
= BeginReading(&begin
, &end
);
799 NS_WARNING("Searching for zero-length string.");
806 // We want to stop searching otherlen characters before the end of the string
809 for (const char_type
*cur
= begin
; cur
<= end
; ++cur
) {
810 if (!c(cur
, aStr
, aLen
))
817 nsACString::RFind(const self_type
& aStr
, PRInt32 aOffset
, ComparatorFunc c
) const
819 const char_type
*begin
, *end
;
820 PRUint32 selflen
= BeginReading(&begin
, &end
);
822 const char_type
*other
;
823 PRUint32 otherlen
= aStr
.BeginReading(&other
);
825 if (selflen
< otherlen
)
828 if (aOffset
< 0 || PRUint32(aOffset
) > (selflen
- otherlen
))
831 end
= begin
+ aOffset
;
833 for (const char_type
*cur
= end
; cur
>= begin
; --cur
) {
834 if (!c(cur
, other
, otherlen
))
841 nsACString::RFind(const char_type
*aStr
, ComparatorFunc c
) const
843 return RFind(aStr
, strlen(aStr
), c
);
847 nsACString::RFind(const char_type
*aStr
, PRInt32 aLen
, ComparatorFunc c
) const
849 const char_type
*begin
, *end
;
850 PRUint32 selflen
= BeginReading(&begin
, &end
);
853 NS_WARNING("Searching for zero-length string.");
857 if (PRUint32(aLen
) > selflen
)
860 // We want to start searching otherlen characters before the end of the string
863 for (const char_type
*cur
= end
; cur
>= begin
; --cur
) {
864 if (!c(cur
, aStr
, aLen
))
871 nsACString::FindChar(char_type aChar
, PRUint32 aOffset
) const
873 const char_type
*start
, *end
;
874 PRUint32 len
= BeginReading(&start
, &end
);
878 const char_type
*cur
;
880 for (cur
= start
+ aOffset
; cur
< end
; ++cur
) {
889 nsACString::RFindChar(char_type aChar
) const
891 const char *start
, *end
;
892 BeginReading(&start
, &end
);
894 for (; end
>= start
; --end
) {
903 nsACString::AppendInt(int aInt
, PRInt32 aRadix
)
920 NS_ERROR("Unrecognized radix");
925 int len
= snprintf(buf
, sizeof(buf
), fmt
, aInt
);
926 buf
[sizeof(buf
) - 1] = '\0';
931 #ifndef XPCOM_GLUE_AVOID_NSPR
933 nsACString::ToInteger(nsresult
*aErrorCode
, PRUint32 aRadix
) const
946 NS_ERROR("Unrecognized radix!");
947 *aErrorCode
= NS_ERROR_INVALID_ARG
;
952 if (PR_sscanf(nsCString(*this).get(), fmt
, &result
) == 1)
955 *aErrorCode
= NS_ERROR_FAILURE
;
959 #endif // XPCOM_GLUE_AVOID_NSPR
963 nsDependentSubstring::nsDependentSubstring(const abstract_string_type
& aStr
,
966 const PRUnichar
* data
;
967 PRUint32 len
= NS_StringGetData(aStr
, &data
);
972 NS_StringContainerInit2(*this, data
+ aStartPos
, len
- aStartPos
,
973 NS_STRING_CONTAINER_INIT_DEPEND
|
974 NS_STRING_CONTAINER_INIT_SUBSTRING
);
977 nsDependentSubstring::nsDependentSubstring(const abstract_string_type
& aStr
,
981 const PRUnichar
* data
;
982 PRUint32 len
= NS_StringGetData(aStr
, &data
);
987 if (aStartPos
+ aLength
> len
)
988 aLength
= len
- aStartPos
;
990 NS_StringContainerInit2(*this, data
+ aStartPos
, aLength
,
991 NS_STRING_CONTAINER_INIT_DEPEND
|
992 NS_STRING_CONTAINER_INIT_SUBSTRING
);
995 nsDependentCSubstring::nsDependentCSubstring(const abstract_string_type
& aStr
,
999 PRUint32 len
= NS_CStringGetData(aStr
, &data
);
1001 if (aStartPos
> len
)
1004 NS_CStringContainerInit2(*this, data
+ aStartPos
, len
- aStartPos
,
1005 NS_CSTRING_CONTAINER_INIT_DEPEND
|
1006 NS_CSTRING_CONTAINER_INIT_SUBSTRING
);
1009 nsDependentCSubstring::nsDependentCSubstring(const abstract_string_type
& aStr
,
1014 PRUint32 len
= NS_CStringGetData(aStr
, &data
);
1016 if (aStartPos
> len
)
1019 if (aStartPos
+ aLength
> len
)
1020 aLength
= len
- aStartPos
;
1022 NS_CStringContainerInit2(*this, data
+ aStartPos
, aLength
,
1023 NS_CSTRING_CONTAINER_INIT_DEPEND
|
1024 NS_CSTRING_CONTAINER_INIT_SUBSTRING
);
1030 ToNewUTF8String(const nsAString
& aSource
)
1033 CopyUTF16toUTF8(aSource
, temp
);
1034 return NS_CStringCloneData(temp
);
1038 CompressWhitespace(nsAString
& aString
)
1041 PRUint32 len
= NS_StringGetMutableData(aString
, PR_UINT32_MAX
, &start
);
1042 PRUnichar
*end
= start
+ len
;
1043 PRUnichar
*from
= start
, *to
= start
;
1045 // Skip any leading whitespace
1046 while (from
< end
&& NS_IsAsciiWhitespace(*from
))
1049 while (from
< end
) {
1050 PRUnichar theChar
= *from
++;
1052 if (NS_IsAsciiWhitespace(theChar
)) {
1053 // We found a whitespace char, so skip over any more
1054 while (from
< end
&& NS_IsAsciiWhitespace(*from
))
1057 // Turn all whitespace into spaces
1064 // Drop any trailing space
1065 if (to
> start
&& to
[-1] == ' ')
1068 // Re-terminate the string
1071 // Set the new length
1072 aString
.SetLength(to
- start
);
1076 ToLowerCase(nsACString
& aStr
)
1079 PRUint32 len
= aStr
.BeginWriting(&begin
, &end
);
1081 for (; begin
< end
; ++begin
) {
1082 *begin
= NS_ToLower(*begin
);
1089 ToUpperCase(nsACString
& aStr
)
1092 PRUint32 len
= aStr
.BeginWriting(&begin
, &end
);
1094 for (; begin
< end
; ++begin
) {
1095 *begin
= NS_ToUpper(*begin
);
1102 ToLowerCase(const nsACString
& aSrc
, nsACString
& aDest
)
1104 const char *begin
, *end
;
1105 PRUint32 len
= aSrc
.BeginReading(&begin
, &end
);
1108 NS_CStringGetMutableData(aDest
, len
, &dest
);
1110 for (; begin
< end
; ++begin
, ++dest
) {
1111 *dest
= NS_ToLower(*begin
);
1118 ToUpperCase(const nsACString
& aSrc
, nsACString
& aDest
)
1120 const char *begin
, *end
;
1121 PRUint32 len
= aSrc
.BeginReading(&begin
, &end
);
1124 NS_CStringGetMutableData(aDest
, len
, &dest
);
1126 for (; begin
< end
; ++begin
, ++dest
) {
1127 *dest
= NS_ToUpper(*begin
);
1134 CaseInsensitiveCompare(const char *a
, const char *b
,
1137 for (const char *aend
= a
+ len
; a
< aend
; ++a
, ++b
) {
1138 char la
= NS_ToLower(*a
);
1139 char lb
= NS_ToLower(*b
);
1144 return la
< lb
? -1 : 1;
1151 ParseString(const nsACString
& aSource
, char aDelimiter
,
1152 nsTArray
<nsCString
>& aArray
)
1155 PRInt32 end
= aSource
.Length();
1157 PRUint32 oldLength
= aArray
.Length();
1160 PRInt32 delimiter
= aSource
.FindChar(aDelimiter
, start
);
1161 if (delimiter
< 0) {
1165 if (delimiter
!= start
) {
1166 if (!aArray
.AppendElement(Substring(aSource
, start
, delimiter
- start
))) {
1167 aArray
.RemoveElementsAt(oldLength
, aArray
.Length() - oldLength
);
1172 if (delimiter
== end
)
1174 start
= ++delimiter
;