1 /* ***** BEGIN LICENSE BLOCK *****
2 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4 * The contents of this file are subject to the Mozilla Public License Version
5 * 1.1 (the "License"); you may not use this file except in compliance with
6 * the License. You may obtain a copy of the License at
7 * http://www.mozilla.org/MPL/
9 * Software distributed under the License is distributed on an "AS IS" basis,
10 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
11 * for the specific language governing rights and limitations under the
14 * The Original Code is Mozilla Application Update.
15 * This file is based on code originally located at
16 * mozilla/toolkit/mozapps/update/src/updater/updater.cpp
18 * The Initial Developer of the Original Code is
19 * Benjamin Smedberg <benjamin@smedbergs.us>
21 * Portions created by the Initial Developer are Copyright (C) 2005
22 * the Initial Developer. All Rights Reserved.
25 * Darin Fisher <darin@meer.net>
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 ***** */
41 #include "nsCRTGlue.h"
53 NS_strspnp(const char *delims
, const char *str
)
57 for (d
= delims
; *d
!= '\0'; ++d
) {
69 NS_strtok(const char *delims
, char **str
)
74 char *ret
= (char*) NS_strspnp(delims
, *str
);
83 for (const char *d
= delims
; *d
!= '\0'; ++d
) {
98 NS_strlen(const PRUnichar
*aString
)
100 const PRUnichar
*end
;
102 for (end
= aString
; *end
; ++end
) {
106 return end
- aString
;
110 NS_strcmp(const PRUnichar
*a
, const PRUnichar
*b
)
125 NS_strdup(const PRUnichar
*aString
)
127 PRUint32 len
= NS_strlen(aString
);
128 return NS_strndup(aString
, len
);
132 NS_strndup(const PRUnichar
*aString
, PRUint32 aLen
)
134 PRUnichar
*newBuf
= (PRUnichar
*) NS_Alloc((aLen
+ 1) * sizeof(PRUnichar
));
136 memcpy(newBuf
, aString
, aLen
* sizeof(PRUnichar
));
143 NS_strdup(const char *aString
)
145 PRUint32 len
= strlen(aString
);
146 char *str
= (char*) NS_Alloc(len
+ 1);
148 memcpy(str
, aString
, len
);
154 // This table maps uppercase characters to lower case characters;
155 // characters that are neither upper nor lower case are unaffected.
156 const unsigned char nsLowerUpperUtils::kUpper2Lower
[256] = {
157 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
158 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
159 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
160 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63,
163 // upper band mapped to lower [A-Z] => [a-z]
164 97, 98, 99,100,101,102,103,104,105,106,107,108,109,110,111,
165 112,113,114,115,116,117,118,119,120,121,122,
168 96, 97, 98, 99,100,101,102,103,104,105,106,107,108,109,110,111,
169 112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127,
170 128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,
171 144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159,
172 160,161,162,163,164,165,166,167,168,169,170,171,172,173,174,175,
173 176,177,178,179,180,181,182,183,184,185,186,187,188,189,190,191,
174 192,193,194,195,196,197,198,199,200,201,202,203,204,205,206,207,
175 208,209,210,211,212,213,214,215,216,217,218,219,220,221,222,223,
176 224,225,226,227,228,229,230,231,232,233,234,235,236,237,238,239,
177 240,241,242,243,244,245,246,247,248,249,250,251,252,253,254,255
180 const unsigned char nsLowerUpperUtils::kLower2Upper
[256] = {
181 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
182 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
183 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
184 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63,
185 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79,
186 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95,
189 // lower band mapped to upper [a-z] => [A-Z]
190 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79,
191 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90,
194 128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,
195 144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159,
196 160,161,162,163,164,165,166,167,168,169,170,171,172,173,174,175,
197 176,177,178,179,180,181,182,183,184,185,186,187,188,189,190,191,
198 192,193,194,195,196,197,198,199,200,201,202,203,204,205,206,207,
199 208,209,210,211,212,213,214,215,216,217,218,219,220,221,222,223,
200 224,225,226,227,228,229,230,231,232,233,234,235,236,237,238,239,
201 240,241,242,243,244,245,246,247,248,249,250,251,252,253,254,255
204 PRBool
NS_IsUpper(char aChar
)
206 return aChar
!= (char)nsLowerUpperUtils::kUpper2Lower
[(unsigned char)aChar
];
209 PRBool
NS_IsLower(char aChar
)
211 return aChar
!= (char)nsLowerUpperUtils::kLower2Upper
[(unsigned char)aChar
];
214 PRBool
NS_IsAscii(PRUnichar aChar
)
216 return (0x0080 > aChar
);
219 PRBool
NS_IsAscii(const PRUnichar
*aString
)
222 if( 0x0080 <= *aString
)
229 PRBool
NS_IsAscii(const char *aString
)
239 PRBool
NS_IsAscii(const char* aString
, PRUint32 aLength
)
241 const char* end
= aString
+ aLength
;
242 while (aString
< end
) {
250 PRBool
NS_IsAsciiAlpha(PRUnichar aChar
)
252 return ((aChar
>= 'A') && (aChar
<= 'Z')) ||
253 ((aChar
>= 'a') && (aChar
<= 'z'));
256 PRBool
NS_IsAsciiWhitespace(PRUnichar aChar
)
258 return aChar
== ' ' ||
264 PRBool
NS_IsAsciiDigit(PRUnichar aChar
)
266 return aChar
>= '0' && aChar
<= '9';
269 #if defined(XP_WIN) && !defined(WINCE)
271 printf_stderr(const char *fmt
, ...)
273 FILE *fp
= _fdopen(_dup(2), "a");
277 vfprintf(fp
, fmt
, args
);
284 printf_stderr(const char *fmt
, ...)
288 vfprintf(stderr
, fmt
, args
);