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.11-2.js
9 ECMA Section: 15.5.4.11 String.prototype.toLowerCase()
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 toLowerCase 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.11-2";
29 var VERSION = "ECMA_1";
30 startTest();
31 var TITLE = "String.prototype.toLowerCase()";
33 writeHeaderToLog( SECTION + " "+ TITLE);
35 // Halfwidth and Fullwidth Forms
36 // Range: U+FF00 to U+FFEF
37 for ( var i = 0xFF00; i <= 0xFFEF; i++ ) {
38 var U = new Unicode(i);
39 /*
40 new TestCase( SECTION,
41 "var s = new String( String.fromCharCode("+i+") ); s.toLowerCase()",
42 String.fromCharCode(U.lower),
43 eval("var s = new String( String.fromCharCode("+i+") ); s.toLowerCase()") );
44 */
45 new TestCase( SECTION,
46 "var s = new String( String.fromCharCode("+i+") ); s.toLowerCase().charCodeAt(0)",
47 U.lower,
48 eval("var s = new String( String.fromCharCode(i) ); s.toLowerCase().charCodeAt(0)") );
49 }
51 test();
53 function MyObject( value ) {
54 this.value = value;
55 this.substring = String.prototype.substring;
56 this.toString = new Function ( "return this.value+''" );
57 }
58 function Unicode( c ) {
59 u = GetUnicodeValues( c );
60 this.upper = u[0];
61 this.lower = u[1]
62 return this;
63 }
64 function GetUnicodeValues( c ) {
65 u = new Array();
67 u[0] = c;
68 u[1] = c;
70 // upper case Basic Latin
72 if ( c >= 0x0041 && c <= 0x005A) {
73 u[0] = c;
74 u[1] = c + 32;
75 return u;
76 }
78 // lower case Basic Latin
79 if ( c >= 0x0061 && c <= 0x007a ) {
80 u[0] = c - 32;
81 u[1] = c;
82 return u;
83 }
85 // upper case Latin-1 Supplement
86 if ( (c >= 0x00C0 && c <= 0x00D6) || (c >= 0x00D8 && c<=0x00DE) ) {
87 u[0] = c;
88 u[1] = c + 32;
89 return u;
90 }
92 // lower case Latin-1 Supplement
93 if ( (c >= 0x00E0 && c <= 0x00F6) || (c >= 0x00F8 && c <= 0x00FE) ) {
94 u[0] = c - 32;
95 u[1] = c;
96 return u;
97 }
98 if ( c == 0x00FF ) {
99 u[0] = 0x0178;
100 u[1] = c;
101 return u;
102 }
103 // Latin Extended A
104 if ( (c >= 0x0100 && c < 0x0138) || (c > 0x0149 && c < 0x0178) ) {
105 // special case for capital I
106 if ( c == 0x0130 ) {
107 u[0] = c;
108 u[1] = 0x0069;
109 return u;
110 }
111 if ( c == 0x0131 ) {
112 u[0] = 0x0049;
113 u[1] = c;
114 return u;
115 }
117 if ( c % 2 == 0 ) {
118 // if it's even, it's a capital and the lower case is c +1
119 u[0] = c;
120 u[1] = c+1;
121 } else {
122 // if it's odd, it's a lower case and upper case is c-1
123 u[0] = c-1;
124 u[1] = c;
125 }
126 return u;
127 }
128 if ( c == 0x0178 ) {
129 u[0] = c;
130 u[1] = 0x00FF;
131 return u;
132 }
134 if ( (c >= 0x0139 && c < 0x0149) || (c > 0x0178 && c < 0x017F) ) {
135 if ( c % 2 == 1 ) {
136 // if it's odd, it's a capital and the lower case is c +1
137 u[0] = c;
138 u[1] = c+1;
139 } else {
140 // if it's even, it's a lower case and upper case is c-1
141 u[0] = c-1;
142 u[1] = c;
143 }
144 return u;
145 }
146 if ( c == 0x017F ) {
147 u[0] = 0x0053;
148 u[1] = c;
149 }
151 // Latin Extended B
152 // need to improve this set
154 if ( c >= 0x0200 && c <= 0x0217 ) {
155 if ( c % 2 == 0 ) {
156 u[0] = c;
157 u[1] = c+1;
158 } else {
159 u[0] = c-1;
160 u[1] = c;
161 }
162 return u;
163 }
165 // Latin Extended Additional
166 // Range: U+1E00 to U+1EFF
167 // http://www.unicode.org/Unicode.charts/glyphless/U1E00.html
169 // Spacing Modifier Leters
170 // Range: U+02B0 to U+02FF
172 // Combining Diacritical Marks
173 // Range: U+0300 to U+036F
175 // skip Greek for now
176 // Greek
177 // Range: U+0370 to U+03FF
179 // Cyrillic
180 // Range: U+0400 to U+04FF
182 if ( (c >= 0x0401 && c <= 0x040C) || ( c>= 0x040E && c <= 0x040F ) ) {
183 u[0] = c;
184 u[1] = c + 80;
185 return u;
186 }
189 if ( c >= 0x0410 && c <= 0x042F ) {
190 u[0] = c;
191 u[1] = c + 32;
192 return u;
193 }
195 if ( c >= 0x0430 && c<= 0x044F ) {
196 u[0] = c - 32;
197 u[1] = c;
198 return u;
200 }
201 if ( (c >= 0x0451 && c <= 0x045C) || (c >=0x045E && c<= 0x045F) ) {
202 u[0] = c -80;
203 u[1] = c;
204 return u;
205 }
207 if ( c >= 0x0460 && c <= 0x047F ) {
208 if ( c % 2 == 0 ) {
209 u[0] = c;
210 u[1] = c +1;
211 } else {
212 u[0] = c - 1;
213 u[1] = c;
214 }
215 return u;
216 }
218 // Armenian
219 // Range: U+0530 to U+058F
220 if ( c >= 0x0531 && c <= 0x0556 ) {
221 u[0] = c;
222 u[1] = c + 48;
223 return u;
224 }
225 if ( c >= 0x0561 && c < 0x0587 ) {
226 u[0] = c - 48;
227 u[1] = c;
228 return u;
229 }
231 // Hebrew
232 // Range: U+0590 to U+05FF
235 // Arabic
236 // Range: U+0600 to U+06FF
238 // Devanagari
239 // Range: U+0900 to U+097F
242 // Bengali
243 // Range: U+0980 to U+09FF
246 // Gurmukhi
247 // Range: U+0A00 to U+0A7F
250 // Gujarati
251 // Range: U+0A80 to U+0AFF
254 // Oriya
255 // Range: U+0B00 to U+0B7F
256 // no capital / lower case
259 // Tamil
260 // Range: U+0B80 to U+0BFF
261 // no capital / lower case
264 // Telugu
265 // Range: U+0C00 to U+0C7F
266 // no capital / lower case
269 // Kannada
270 // Range: U+0C80 to U+0CFF
271 // no capital / lower case
274 // Malayalam
275 // Range: U+0D00 to U+0D7F
277 // Thai
278 // Range: U+0E00 to U+0E7F
281 // Lao
282 // Range: U+0E80 to U+0EFF
285 // Tibetan
286 // Range: U+0F00 to U+0FBF
288 // Georgian
289 // Range: U+10A0 to U+10F0
290 if ( c >= 0x10A0 && c <= 0x10C5 ) {
291 u[0] = c;
292 u[1] = c + 48;
293 return u;
294 }
295 if ( c >= 0x10D0 && c <= 0x10F5 ) {
296 u[0] = c;
297 u[1] = c;
298 return u;
299 }
301 // Hangul Jamo
302 // Range: U+1100 to U+11FF
304 // Greek Extended
305 // Range: U+1F00 to U+1FFF
306 // skip for now
309 // General Punctuation
310 // Range: U+2000 to U+206F
312 // Superscripts and Subscripts
313 // Range: U+2070 to U+209F
315 // Currency Symbols
316 // Range: U+20A0 to U+20CF
319 // Combining Diacritical Marks for Symbols
320 // Range: U+20D0 to U+20FF
321 // skip for now
324 // Number Forms
325 // Range: U+2150 to U+218F
326 // skip for now
329 // Arrows
330 // Range: U+2190 to U+21FF
332 // Mathematical Operators
333 // Range: U+2200 to U+22FF
335 // Miscellaneous Technical
336 // Range: U+2300 to U+23FF
338 // Control Pictures
339 // Range: U+2400 to U+243F
341 // Optical Character Recognition
342 // Range: U+2440 to U+245F
344 // Enclosed Alphanumerics
345 // Range: U+2460 to U+24FF
347 // Box Drawing
348 // Range: U+2500 to U+257F
350 // Block Elements
351 // Range: U+2580 to U+259F
353 // Geometric Shapes
354 // Range: U+25A0 to U+25FF
356 // Miscellaneous Symbols
357 // Range: U+2600 to U+26FF
359 // Dingbats
360 // Range: U+2700 to U+27BF
362 // CJK Symbols and Punctuation
363 // Range: U+3000 to U+303F
365 // Hiragana
366 // Range: U+3040 to U+309F
368 // Katakana
369 // Range: U+30A0 to U+30FF
371 // Bopomofo
372 // Range: U+3100 to U+312F
374 // Hangul Compatibility Jamo
375 // Range: U+3130 to U+318F
377 // Kanbun
378 // Range: U+3190 to U+319F
381 // Enclosed CJK Letters and Months
382 // Range: U+3200 to U+32FF
384 // CJK Compatibility
385 // Range: U+3300 to U+33FF
387 // Hangul Syllables
388 // Range: U+AC00 to U+D7A3
390 // High Surrogates
391 // Range: U+D800 to U+DB7F
393 // Private Use High Surrogates
394 // Range: U+DB80 to U+DBFF
396 // Low Surrogates
397 // Range: U+DC00 to U+DFFF
399 // Private Use Area
400 // Range: U+E000 to U+F8FF
402 // CJK Compatibility Ideographs
403 // Range: U+F900 to U+FAFF
405 // Alphabetic Presentation Forms
406 // Range: U+FB00 to U+FB4F
408 // Arabic Presentation Forms-A
409 // Range: U+FB50 to U+FDFF
411 // Combining Half Marks
412 // Range: U+FE20 to U+FE2F
414 // CJK Compatibility Forms
415 // Range: U+FE30 to U+FE4F
417 // Small Form Variants
418 // Range: U+FE50 to U+FE6F
420 // Arabic Presentation Forms-B
421 // Range: U+FE70 to U+FEFF
423 // Halfwidth and Fullwidth Forms
424 // Range: U+FF00 to U+FFEF
426 if ( c >= 0xFF21 && c <= 0xFF3A ) {
427 u[0] = c;
428 u[1] = c + 32;
429 return u;
430 }
432 if ( c >= 0xFF41 && c <= 0xFF5A ) {
433 u[0] = c - 32;
434 u[1] = c;
435 return u;
436 }
438 // Specials
439 // Range: U+FFF0 to U+FFFF
441 return u;
442 }
444 function DecimalToHexString( n ) {
445 n = Number( n );
446 var h = "0x";
448 for ( var i = 3; i >= 0; i-- ) {
449 if ( n >= Math.pow(16, i) ){
450 var t = Math.floor( n / Math.pow(16, i));
451 n -= t * Math.pow(16, i);
452 if ( t >= 10 ) {
453 if ( t == 10 ) {
454 h += "A";
455 }
456 if ( t == 11 ) {
457 h += "B";
458 }
459 if ( t == 12 ) {
460 h += "C";
461 }
462 if ( t == 13 ) {
463 h += "D";
464 }
465 if ( t == 14 ) {
466 h += "E";
467 }
468 if ( t == 15 ) {
469 h += "F";
470 }
471 } else {
472 h += String( t );
473 }
474 } else {
475 h += "0";
476 }
477 }
479 return h;
480 }