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