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