]>
Commit | Line | Data |
---|---|---|
b37bf2e1 A |
1 | /* The contents of this file are subject to the Netscape Public |
2 | * License Version 1.1 (the "License"); you may not use this file | |
3 | * except in compliance with the License. You may obtain a copy of | |
4 | * the License at http://www.mozilla.org/NPL/ | |
5 | * | |
6 | * Software distributed under the License is distributed on an "AS | |
7 | * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or | |
8 | * implied. See the License for the specific language governing | |
9 | * rights and limitations under the License. | |
10 | * | |
11 | * The Original Code is Mozilla Communicator client code, released March | |
12 | * 31, 1998. | |
13 | * | |
14 | * The Initial Developer of the Original Code is Netscape Communications | |
15 | * Corporation. Portions created by Netscape are | |
16 | * Copyright (C) 1998 Netscape Communications Corporation. All | |
17 | * Rights Reserved. | |
18 | * | |
19 | * Contributor(s): | |
20 | * | |
21 | */ | |
22 | /** | |
23 | File Name: 15.5.4.12-1.js | |
24 | ECMA Section: 15.5.4.12 String.prototype.toUpperCase() | |
25 | Description: | |
26 | ||
27 | Returns a string equal in length to the length of the result of converting | |
28 | this object to a string. The result is a string value, not a String object. | |
29 | ||
30 | Every character of the result is equal to the corresponding character of the | |
31 | string, unless that character has a Unicode 2.0 uppercase equivalent, in which | |
32 | case the uppercase equivalent is used instead. (The canonical Unicode 2.0 case | |
33 | mapping shall be used, which does not depend on implementation or locale.) | |
34 | ||
35 | Note that the toUpperCase function is intentionally generic; it does not require | |
36 | that its this value be a String object. Therefore it can be transferred to other | |
37 | kinds of objects for use as a method. | |
38 | ||
39 | Author: christine@netscape.com | |
40 | Date: 12 november 1997 | |
41 | */ | |
42 | ||
43 | var SECTION = "15.5.4.12-1"; | |
44 | var VERSION = "ECMA_1"; | |
45 | startTest(); | |
46 | var TITLE = "String.prototype.toUpperCase()"; | |
47 | ||
48 | writeHeaderToLog( SECTION + " "+ TITLE); | |
49 | ||
50 | var testcases = getTestCases(); | |
51 | test(); | |
52 | ||
53 | function getTestCases() { | |
54 | var array = new Array(); | |
55 | var item = 0; | |
56 | ||
57 | // Armenian | |
58 | // Range: U+0530 to U+058F | |
59 | for ( var i = 0x0530; i <= 0x058F; i++ ) { | |
60 | var U = new Unicode( i ); | |
61 | /* | |
62 | array[item++] = new TestCase( SECTION, | |
63 | "var s = new String( String.fromCharCode("+i+") ); s.toUpperCase()", | |
64 | String.fromCharCode(U.upper), | |
65 | eval("var s = new String( String.fromCharCode("+i+") ); s.toUpperCase()") ); | |
66 | */ | |
67 | array[item++] = new TestCase( SECTION, | |
68 | "var s = new String( String.fromCharCode("+i+") ); s.toUpperCase().charCodeAt(0)", | |
69 | U.upper, | |
70 | eval("var s = new String( String.fromCharCode(i) ); s.toUpperCase().charCodeAt(0)") ); | |
71 | ||
72 | } | |
73 | ||
74 | return array; | |
75 | } | |
76 | function test() { | |
77 | for ( tc=0; tc < testcases.length; tc++ ) { | |
78 | testcases[tc].passed = writeTestCaseResult( | |
79 | testcases[tc].expect, | |
80 | testcases[tc].actual, | |
81 | testcases[tc].description +" = "+ | |
82 | testcases[tc].actual ); | |
83 | ||
84 | testcases[tc].reason += ( testcases[tc].passed ) ? "" : "wrong value "; | |
85 | } | |
86 | stopTest(); | |
87 | return ( testcases ); | |
88 | } | |
89 | function MyObject( value ) { | |
90 | this.value = value; | |
91 | this.substring = String.prototype.substring; | |
92 | this.toString = new Function ( "return this.value+''" ); | |
93 | } | |
94 | function Unicode( c ) { | |
95 | u = GetUnicodeValues( c ); | |
96 | this.upper = u[0]; | |
97 | this.lower = u[1] | |
98 | return this; | |
99 | } | |
100 | function GetUnicodeValues( c ) { | |
101 | u = new Array(); | |
102 | ||
103 | u[0] = c; | |
104 | u[1] = c; | |
105 | ||
106 | // upper case Basic Latin | |
107 | ||
108 | if ( c >= 0x0041 && c <= 0x005A) { | |
109 | u[0] = c; | |
110 | u[1] = c + 32; | |
111 | return u; | |
112 | } | |
113 | ||
114 | // lower case Basic Latin | |
115 | if ( c >= 0x0061 && c <= 0x007a ) { | |
116 | u[0] = c - 32; | |
117 | u[1] = c; | |
118 | return u; | |
119 | } | |
120 | ||
121 | // upper case Latin-1 Supplement | |
122 | if ( c == 0x00B5 ) { | |
123 | u[0] = 0x039C; | |
124 | u[1] = c; | |
125 | return u; | |
126 | } | |
127 | if ( (c >= 0x00C0 && c <= 0x00D6) || (c >= 0x00D8 && c<=0x00DE) ) { | |
128 | u[0] = c; | |
129 | u[1] = c + 32; | |
130 | return u; | |
131 | } | |
132 | ||
133 | // lower case Latin-1 Supplement | |
134 | if ( (c >= 0x00E0 && c <= 0x00F6) || (c >= 0x00F8 && c <= 0x00FE) ) { | |
135 | u[0] = c - 32; | |
136 | u[1] = c; | |
137 | return u; | |
138 | } | |
139 | if ( c == 0x00FF ) { | |
140 | u[0] = 0x0178; | |
141 | u[1] = c; | |
142 | return u; | |
143 | } | |
144 | // Latin Extended A | |
145 | if ( (c >= 0x0100 && c < 0x0138) || (c > 0x0149 && c < 0x0178) ) { | |
146 | // special case for capital I | |
147 | if ( c == 0x0130 ) { | |
148 | u[0] = c; | |
149 | u[1] = 0x0069; | |
150 | return u; | |
151 | } | |
152 | if ( c == 0x0131 ) { | |
153 | u[0] = 0x0049; | |
154 | u[1] = c; | |
155 | return u; | |
156 | } | |
157 | ||
158 | if ( c % 2 == 0 ) { | |
159 | // if it's even, it's a capital and the lower case is c +1 | |
160 | u[0] = c; | |
161 | u[1] = c+1; | |
162 | } else { | |
163 | // if it's odd, it's a lower case and upper case is c-1 | |
164 | u[0] = c-1; | |
165 | u[1] = c; | |
166 | } | |
167 | return u; | |
168 | } | |
169 | if ( c == 0x0178 ) { | |
170 | u[0] = c; | |
171 | u[1] = 0x00FF; | |
172 | return u; | |
173 | } | |
174 | ||
175 | // LATIN SMALL LETTER N PRECEDED BY APOSTROPHE, uppercase takes two code points | |
176 | if (c == 0x0149) { | |
177 | u[0] = 0x02bc; | |
178 | u[1] = c; | |
179 | return u; | |
180 | } | |
181 | ||
182 | if ( (c >= 0x0139 && c < 0x0149) || (c > 0x0178 && c < 0x017F) ) { | |
183 | if ( c % 2 == 1 ) { | |
184 | // if it's odd, it's a capital and the lower case is c +1 | |
185 | u[0] = c; | |
186 | u[1] = c+1; | |
187 | } else { | |
188 | // if it's even, it's a lower case and upper case is c-1 | |
189 | u[0] = c-1; | |
190 | u[1] = c; | |
191 | } | |
192 | return u; | |
193 | } | |
194 | if ( c == 0x017F ) { | |
195 | u[0] = 0x0053; | |
196 | u[1] = c; | |
197 | } | |
198 | ||
199 | // Latin Extended B | |
200 | // need to improve this set | |
201 | ||
202 | if ( c >= 0x0200 && c <= 0x0217 ) { | |
203 | if ( c % 2 == 0 ) { | |
204 | u[0] = c; | |
205 | u[1] = c+1; | |
206 | } else { | |
207 | u[0] = c-1; | |
208 | u[1] = c; | |
209 | } | |
210 | return u; | |
211 | } | |
212 | ||
213 | // Latin Extended Additional | |
214 | // Range: U+1E00 to U+1EFF | |
215 | // http://www.unicode.org/Unicode.charts/glyphless/U1E00.html | |
216 | ||
217 | // Spacing Modifier Leters | |
218 | // Range: U+02B0 to U+02FF | |
219 | ||
220 | // Combining Diacritical Marks | |
221 | // Range: U+0300 to U+036F | |
222 | ||
223 | // skip Greek for now | |
224 | // Greek | |
225 | // Range: U+0370 to U+03FF | |
226 | ||
227 | // Cyrillic | |
228 | // Range: U+0400 to U+04FF | |
229 | ||
230 | if ( c >= 0x0400 && c <= 0x040F) { | |
231 | u[0] = c; | |
232 | u[1] = c + 80; | |
233 | return u; | |
234 | } | |
235 | ||
236 | ||
237 | if ( c >= 0x0410 && c <= 0x042F ) { | |
238 | u[0] = c; | |
239 | u[1] = c + 32; | |
240 | return u; | |
241 | } | |
242 | ||
243 | if ( c >= 0x0430 && c<= 0x044F ) { | |
244 | u[0] = c - 32; | |
245 | u[1] = c; | |
246 | return u; | |
247 | ||
248 | } | |
249 | if ( c >= 0x0450 && c<= 0x045F ) { | |
250 | u[0] = c -80; | |
251 | u[1] = c; | |
252 | return u; | |
253 | } | |
254 | ||
255 | if ( c >= 0x0460 && c <= 0x047F ) { | |
256 | if ( c % 2 == 0 ) { | |
257 | u[0] = c; | |
258 | u[1] = c +1; | |
259 | } else { | |
260 | u[0] = c - 1; | |
261 | u[1] = c; | |
262 | } | |
263 | return u; | |
264 | } | |
265 | ||
266 | // Armenian | |
267 | // Range: U+0530 to U+058F | |
268 | if ( c >= 0x0531 && c <= 0x0556 ) { | |
269 | u[0] = c; | |
270 | u[1] = c + 48; | |
271 | return u; | |
272 | } | |
273 | if ( c >= 0x0561 && c < 0x0587 ) { | |
274 | u[0] = c - 48; | |
275 | u[1] = c; | |
276 | return u; | |
277 | } | |
278 | if (c == 0x0587) { | |
279 | u[0] = 0x0535; | |
280 | u[1] = c; | |
281 | return u; | |
282 | } | |
283 | ||
284 | // Hebrew | |
285 | // Range: U+0590 to U+05FF | |
286 | ||
287 | ||
288 | // Arabic | |
289 | // Range: U+0600 to U+06FF | |
290 | ||
291 | // Devanagari | |
292 | // Range: U+0900 to U+097F | |
293 | ||
294 | ||
295 | // Bengali | |
296 | // Range: U+0980 to U+09FF | |
297 | ||
298 | ||
299 | // Gurmukhi | |
300 | // Range: U+0A00 to U+0A7F | |
301 | ||
302 | ||
303 | // Gujarati | |
304 | // Range: U+0A80 to U+0AFF | |
305 | ||
306 | ||
307 | // Oriya | |
308 | // Range: U+0B00 to U+0B7F | |
309 | // no capital / lower case | |
310 | ||
311 | ||
312 | // Tamil | |
313 | // Range: U+0B80 to U+0BFF | |
314 | // no capital / lower case | |
315 | ||
316 | ||
317 | // Telugu | |
318 | // Range: U+0C00 to U+0C7F | |
319 | // no capital / lower case | |
320 | ||
321 | ||
322 | // Kannada | |
323 | // Range: U+0C80 to U+0CFF | |
324 | // no capital / lower case | |
325 | ||
326 | ||
327 | // Malayalam | |
328 | // Range: U+0D00 to U+0D7F | |
329 | ||
330 | // Thai | |
331 | // Range: U+0E00 to U+0E7F | |
332 | ||
333 | ||
334 | // Lao | |
335 | // Range: U+0E80 to U+0EFF | |
336 | ||
337 | ||
338 | // Tibetan | |
339 | // Range: U+0F00 to U+0FBF | |
340 | ||
341 | // Georgian | |
342 | // Range: U+10A0 to U+10F0 | |
343 | ||
344 | // Hangul Jamo | |
345 | // Range: U+1100 to U+11FF | |
346 | ||
347 | // Greek Extended | |
348 | // Range: U+1F00 to U+1FFF | |
349 | // skip for now | |
350 | ||
351 | ||
352 | // General Punctuation | |
353 | // Range: U+2000 to U+206F | |
354 | ||
355 | // Superscripts and Subscripts | |
356 | // Range: U+2070 to U+209F | |
357 | ||
358 | // Currency Symbols | |
359 | // Range: U+20A0 to U+20CF | |
360 | ||
361 | ||
362 | // Combining Diacritical Marks for Symbols | |
363 | // Range: U+20D0 to U+20FF | |
364 | // skip for now | |
365 | ||
366 | ||
367 | // Number Forms | |
368 | // Range: U+2150 to U+218F | |
369 | // skip for now | |
370 | ||
371 | ||
372 | // Arrows | |
373 | // Range: U+2190 to U+21FF | |
374 | ||
375 | // Mathematical Operators | |
376 | // Range: U+2200 to U+22FF | |
377 | ||
378 | // Miscellaneous Technical | |
379 | // Range: U+2300 to U+23FF | |
380 | ||
381 | // Control Pictures | |
382 | // Range: U+2400 to U+243F | |
383 | ||
384 | // Optical Character Recognition | |
385 | // Range: U+2440 to U+245F | |
386 | ||
387 | // Enclosed Alphanumerics | |
388 | // Range: U+2460 to U+24FF | |
389 | ||
390 | // Box Drawing | |
391 | // Range: U+2500 to U+257F | |
392 | ||
393 | // Block Elements | |
394 | // Range: U+2580 to U+259F | |
395 | ||
396 | // Geometric Shapes | |
397 | // Range: U+25A0 to U+25FF | |
398 | ||
399 | // Miscellaneous Symbols | |
400 | // Range: U+2600 to U+26FF | |
401 | ||
402 | // Dingbats | |
403 | // Range: U+2700 to U+27BF | |
404 | ||
405 | // CJK Symbols and Punctuation | |
406 | // Range: U+3000 to U+303F | |
407 | ||
408 | // Hiragana | |
409 | // Range: U+3040 to U+309F | |
410 | ||
411 | // Katakana | |
412 | // Range: U+30A0 to U+30FF | |
413 | ||
414 | // Bopomofo | |
415 | // Range: U+3100 to U+312F | |
416 | ||
417 | // Hangul Compatibility Jamo | |
418 | // Range: U+3130 to U+318F | |
419 | ||
420 | // Kanbun | |
421 | // Range: U+3190 to U+319F | |
422 | ||
423 | ||
424 | // Enclosed CJK Letters and Months | |
425 | // Range: U+3200 to U+32FF | |
426 | ||
427 | // CJK Compatibility | |
428 | // Range: U+3300 to U+33FF | |
429 | ||
430 | // Hangul Syllables | |
431 | // Range: U+AC00 to U+D7A3 | |
432 | ||
433 | // High Surrogates | |
434 | // Range: U+D800 to U+DB7F | |
435 | ||
436 | // Private Use High Surrogates | |
437 | // Range: U+DB80 to U+DBFF | |
438 | ||
439 | // Low Surrogates | |
440 | // Range: U+DC00 to U+DFFF | |
441 | ||
442 | // Private Use Area | |
443 | // Range: U+E000 to U+F8FF | |
444 | ||
445 | // CJK Compatibility Ideographs | |
446 | // Range: U+F900 to U+FAFF | |
447 | ||
448 | // Alphabetic Presentation Forms | |
449 | // Range: U+FB00 to U+FB4F | |
450 | ||
451 | // Arabic Presentation Forms-A | |
452 | // Range: U+FB50 to U+FDFF | |
453 | ||
454 | // Combining Half Marks | |
455 | // Range: U+FE20 to U+FE2F | |
456 | ||
457 | // CJK Compatibility Forms | |
458 | // Range: U+FE30 to U+FE4F | |
459 | ||
460 | // Small Form Variants | |
461 | // Range: U+FE50 to U+FE6F | |
462 | ||
463 | // Arabic Presentation Forms-B | |
464 | // Range: U+FE70 to U+FEFF | |
465 | ||
466 | // Halfwidth and Fullwidth Forms | |
467 | // Range: U+FF00 to U+FFEF | |
468 | ||
469 | if ( c >= 0xFF21 && c <= 0xFF3A ) { | |
470 | u[0] = c; | |
471 | u[1] = c + 32; | |
472 | return u; | |
473 | } | |
474 | ||
475 | if ( c >= 0xFF41 && c <= 0xFF5A ) { | |
476 | u[0] = c - 32; | |
477 | u[1] = c; | |
478 | return u; | |
479 | } | |
480 | ||
481 | // Specials | |
482 | // Range: U+FFF0 to U+FFFF | |
483 | ||
484 | return u; | |
485 | } | |
486 | ||
487 | function DecimalToHexString( n ) { | |
488 | n = Number( n ); | |
489 | var h = "0x"; | |
490 | ||
491 | for ( var i = 3; i >= 0; i-- ) { | |
492 | if ( n >= Math.pow(16, i) ){ | |
493 | var t = Math.floor( n / Math.pow(16, i)); | |
494 | n -= t * Math.pow(16, i); | |
495 | if ( t >= 10 ) { | |
496 | if ( t == 10 ) { | |
497 | h += "A"; | |
498 | } | |
499 | if ( t == 11 ) { | |
500 | h += "B"; | |
501 | } | |
502 | if ( t == 12 ) { | |
503 | h += "C"; | |
504 | } | |
505 | if ( t == 13 ) { | |
506 | h += "D"; | |
507 | } | |
508 | if ( t == 14 ) { | |
509 | h += "E"; | |
510 | } | |
511 | if ( t == 15 ) { | |
512 | h += "F"; | |
513 | } | |
514 | } else { | |
515 | h += String( t ); | |
516 | } | |
517 | } else { | |
518 | h += "0"; | |
519 | } | |
520 | } | |
521 | ||
522 | return h; | |
523 | } |