Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 /**
8 File Name: 15.5.4.12-2.js
9 ECMA Section: 15.5.4.12 String.prototype.toUpperCase()
10 Description:
12 Returns a string equal in length to the length of the result of converting
13 this object to a string. The result is a string value, not a String object.
15 Every character of the result is equal to the corresponding character of the
16 string, unless that character has a Unicode 2.0 uppercase equivalent, in which
17 case the uppercase equivalent is used instead. (The canonical Unicode 2.0 case
18 mapping shall be used, which does not depend on implementation or locale.)
20 Note that the toUpperCase function is intentionally generic; it does not require
21 that its this value be a String object. Therefore it can be transferred to other
22 kinds of objects for use as a method.
24 Author: christine@netscape.com
25 Date: 12 november 1997
26 */
28 var SECTION = "15.5.4.12-2";
29 var VERSION = "ECMA_1";
30 startTest();
31 var TITLE = "String.prototype.toUpperCase()";
33 writeHeaderToLog( SECTION + " "+ TITLE);
35 var TEST_STRING = "";
36 var EXPECT_STRING = "";
38 // basic latin test
40 for ( var i = 0; i < 0x007A; i++ ) {
41 var u = new Unicode(i);
42 TEST_STRING += String.fromCharCode(i);
43 EXPECT_STRING += String.fromCharCode( u.upper );
44 }
46 // don't print out the value of the strings since they contain control
47 // characters that break the driver
48 var isEqual = EXPECT_STRING == (new String( TEST_STRING )).toUpperCase();
50 new TestCase( SECTION,
51 "isEqual",
52 true,
53 isEqual);
54 test();
56 function MyObject( value ) {
57 this.value = value;
58 this.substring = String.prototype.substring;
59 this.toString = new Function ( "return this.value+''" );
60 }
61 function Unicode( c ) {
62 u = GetUnicodeValues( c );
63 this.upper = u[0];
64 this.lower = u[1]
65 return this;
66 }
67 function GetUnicodeValues( c ) {
68 u = new Array();
70 u[0] = c;
71 u[1] = c;
73 // upper case Basic Latin
75 if ( c >= 0x0041 && c <= 0x005A) {
76 u[0] = c;
77 u[1] = c + 32;
78 return u;
79 }
81 // lower case Basic Latin
82 if ( c >= 0x0061 && c <= 0x007a ) {
83 u[0] = c - 32;
84 u[1] = c;
85 return u;
86 }
88 // upper case Latin-1 Supplement
89 if ( (c >= 0x00C0 && c <= 0x00D6) || (c >= 0x00D8 && c<=0x00DE) ) {
90 u[0] = c;
91 u[1] = c + 32;
92 return u;
93 }
95 // lower case Latin-1 Supplement
96 if ( (c >= 0x00E0 && c <= 0x00F6) || (c >= 0x00F8 && c <= 0x00FE) ) {
97 u[0] = c - 32;
98 u[1] = c;
99 return u;
100 }
101 if ( c == 0x00FF ) {
102 u[0] = 0x0178;
103 u[1] = c;
104 return u;
105 }
106 // Latin Extended A
107 if ( (c >= 0x0100 && c < 0x0138) || (c > 0x0149 && c < 0x0178) ) {
108 // special case for capital I
109 if ( c == 0x0130 ) {
110 u[0] = c;
111 u[1] = 0x0069;
112 return u;
113 }
114 if ( c == 0x0131 ) {
115 u[0] = 0x0049;
116 u[1] = c;
117 return u;
118 }
120 if ( c % 2 == 0 ) {
121 // if it's even, it's a capital and the lower case is c +1
122 u[0] = c;
123 u[1] = c+1;
124 } else {
125 // if it's odd, it's a lower case and upper case is c-1
126 u[0] = c-1;
127 u[1] = c;
128 }
129 return u;
130 }
131 if ( c == 0x0178 ) {
132 u[0] = c;
133 u[1] = 0x00FF;
134 return u;
135 }
137 if ( (c >= 0x0139 && c < 0x0149) || (c > 0x0178 && c < 0x017F) ) {
138 if ( c % 2 == 1 ) {
139 // if it's odd, it's a capital and the lower case is c +1
140 u[0] = c;
141 u[1] = c+1;
142 } else {
143 // if it's even, it's a lower case and upper case is c-1
144 u[0] = c-1;
145 u[1] = c;
146 }
147 return u;
148 }
149 if ( c == 0x017F ) {
150 u[0] = 0x0053;
151 u[1] = c;
152 }
154 // Latin Extended B
155 // need to improve this set
157 if ( c >= 0x0200 && c <= 0x0217 ) {
158 if ( c % 2 == 0 ) {
159 u[0] = c;
160 u[1] = c+1;
161 } else {
162 u[0] = c-1;
163 u[1] = c;
164 }
165 return u;
166 }
168 // Latin Extended Additional
169 // Range: U+1E00 to U+1EFF
170 // http://www.unicode.org/Unicode.charts/glyphless/U1E00.html
172 // Spacing Modifier Leters
173 // Range: U+02B0 to U+02FF
175 // Combining Diacritical Marks
176 // Range: U+0300 to U+036F
178 // skip Greek for now
179 // Greek
180 // Range: U+0370 to U+03FF
182 // Cyrillic
183 // Range: U+0400 to U+04FF
185 if ( (c >= 0x0401 && c <= 0x040C) || ( c>= 0x040E && c <= 0x040F ) ) {
186 u[0] = c;
187 u[1] = c + 80;
188 return u;
189 }
192 if ( c >= 0x0410 && c <= 0x042F ) {
193 u[0] = c;
194 u[1] = c + 32;
195 return u;
196 }
198 if ( c >= 0x0430 && c<= 0x044F ) {
199 u[0] = c - 32;
200 u[1] = c;
201 return u;
203 }
204 if ( (c >= 0x0451 && c <= 0x045C) || (c >=0x045E && c<= 0x045F) ) {
205 u[0] = c -80;
206 u[1] = c;
207 return u;
208 }
210 if ( c >= 0x0460 && c <= 0x047F ) {
211 if ( c % 2 == 0 ) {
212 u[0] = c;
213 u[1] = c +1;
214 } else {
215 u[0] = c - 1;
216 u[1] = c;
217 }
218 return u;
219 }
221 // Armenian
222 // Range: U+0530 to U+058F
223 if ( c >= 0x0531 && c <= 0x0556 ) {
224 u[0] = c;
225 u[1] = c + 48;
226 return u;
227 }
228 if ( c >= 0x0561 && c < 0x0587 ) {
229 u[0] = c - 48;
230 u[1] = c;
231 return u;
232 }
234 // Hebrew
235 // Range: U+0590 to U+05FF
238 // Arabic
239 // Range: U+0600 to U+06FF
241 // Devanagari
242 // Range: U+0900 to U+097F
245 // Bengali
246 // Range: U+0980 to U+09FF
249 // Gurmukhi
250 // Range: U+0A00 to U+0A7F
253 // Gujarati
254 // Range: U+0A80 to U+0AFF
257 // Oriya
258 // Range: U+0B00 to U+0B7F
259 // no capital / lower case
262 // Tamil
263 // Range: U+0B80 to U+0BFF
264 // no capital / lower case
267 // Telugu
268 // Range: U+0C00 to U+0C7F
269 // no capital / lower case
272 // Kannada
273 // Range: U+0C80 to U+0CFF
274 // no capital / lower case
277 // Malayalam
278 // Range: U+0D00 to U+0D7F
280 // Thai
281 // Range: U+0E00 to U+0E7F
284 // Lao
285 // Range: U+0E80 to U+0EFF
288 // Tibetan
289 // Range: U+0F00 to U+0FBF
291 // Georgian
292 // Range: U+10A0 to U+10F0
293 if ( c >= 0x10A0 && c <= 0x10C5 ) {
294 u[0] = c;
295 u[1] = c + 48;
296 return u;
297 }
298 if ( c >= 0x10D0 && c <= 0x10F5 ) {
299 u[0] = c;
300 u[1] = c;
301 return u;
302 }
304 // Hangul Jamo
305 // Range: U+1100 to U+11FF
307 // Greek Extended
308 // Range: U+1F00 to U+1FFF
309 // skip for now
312 // General Punctuation
313 // Range: U+2000 to U+206F
315 // Superscripts and Subscripts
316 // Range: U+2070 to U+209F
318 // Currency Symbols
319 // Range: U+20A0 to U+20CF
322 // Combining Diacritical Marks for Symbols
323 // Range: U+20D0 to U+20FF
324 // skip for now
327 // Number Forms
328 // Range: U+2150 to U+218F
329 // skip for now
332 // Arrows
333 // Range: U+2190 to U+21FF
335 // Mathematical Operators
336 // Range: U+2200 to U+22FF
338 // Miscellaneous Technical
339 // Range: U+2300 to U+23FF
341 // Control Pictures
342 // Range: U+2400 to U+243F
344 // Optical Character Recognition
345 // Range: U+2440 to U+245F
347 // Enclosed Alphanumerics
348 // Range: U+2460 to U+24FF
350 // Box Drawing
351 // Range: U+2500 to U+257F
353 // Block Elements
354 // Range: U+2580 to U+259F
356 // Geometric Shapes
357 // Range: U+25A0 to U+25FF
359 // Miscellaneous Symbols
360 // Range: U+2600 to U+26FF
362 // Dingbats
363 // Range: U+2700 to U+27BF
365 // CJK Symbols and Punctuation
366 // Range: U+3000 to U+303F
368 // Hiragana
369 // Range: U+3040 to U+309F
371 // Katakana
372 // Range: U+30A0 to U+30FF
374 // Bopomofo
375 // Range: U+3100 to U+312F
377 // Hangul Compatibility Jamo
378 // Range: U+3130 to U+318F
380 // Kanbun
381 // Range: U+3190 to U+319F
384 // Enclosed CJK Letters and Months
385 // Range: U+3200 to U+32FF
387 // CJK Compatibility
388 // Range: U+3300 to U+33FF
390 // Hangul Syllables
391 // Range: U+AC00 to U+D7A3
393 // High Surrogates
394 // Range: U+D800 to U+DB7F
396 // Private Use High Surrogates
397 // Range: U+DB80 to U+DBFF
399 // Low Surrogates
400 // Range: U+DC00 to U+DFFF
402 // Private Use Area
403 // Range: U+E000 to U+F8FF
405 // CJK Compatibility Ideographs
406 // Range: U+F900 to U+FAFF
408 // Alphabetic Presentation Forms
409 // Range: U+FB00 to U+FB4F
411 // Arabic Presentation Forms-A
412 // Range: U+FB50 to U+FDFF
414 // Combining Half Marks
415 // Range: U+FE20 to U+FE2F
417 // CJK Compatibility Forms
418 // Range: U+FE30 to U+FE4F
420 // Small Form Variants
421 // Range: U+FE50 to U+FE6F
423 // Arabic Presentation Forms-B
424 // Range: U+FE70 to U+FEFF
426 // Halfwidth and Fullwidth Forms
427 // Range: U+FF00 to U+FFEF
429 if ( c >= 0xFF21 && c <= 0xFF3A ) {
430 u[0] = c;
431 u[1] = c + 32;
432 return u;
433 }
435 if ( c >= 0xFF41 && c <= 0xFF5A ) {
436 u[0] = c - 32;
437 u[1] = c;
438 return u;
439 }
441 // Specials
442 // Range: U+FFF0 to U+FFFF
444 return u;
445 }
447 function DecimalToHexString( n ) {
448 n = Number( n );
449 var h = "0x";
451 for ( var i = 3; i >= 0; i-- ) {
452 if ( n >= Math.pow(16, i) ){
453 var t = Math.floor( n / Math.pow(16, i));
454 n -= t * Math.pow(16, i);
455 if ( t >= 10 ) {
456 if ( t == 10 ) {
457 h += "A";
458 }
459 if ( t == 11 ) {
460 h += "B";
461 }
462 if ( t == 12 ) {
463 h += "C";
464 }
465 if ( t == 13 ) {
466 h += "D";
467 }
468 if ( t == 14 ) {
469 h += "E";
470 }
471 if ( t == 15 ) {
472 h += "F";
473 }
474 } else {
475 h += String( t );
476 }
477 } else {
478 h += "0";
479 }
480 }
482 return h;
483 }