1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
15 * The Original Code is Mozilla Communicator client code, released
18 * The Initial Developer of the Original Code is
19 * Netscape Communications Corporation.
20 * Portions created by the Initial Developer are Copyright (C) 1998
21 * the Initial Developer. All Rights Reserved.
25 * Alternatively, the contents of this file may be used under the terms of
26 * either the GNU General Public License Version 2 or later (the "GPL"), or
27 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28 * in which case the provisions of the GPL or the LGPL are applicable instead
29 * of those above. If you wish to allow use of your version of this file only
30 * under the terms of either the GPL or the LGPL, and not to allow others to
31 * use your version of this file under the terms of the MPL, indicate your
32 * decision by deleting the provisions above and replace them with the notice
33 * and other provisions required by the GPL or the LGPL. If you do not delete
34 * the provisions above, a recipient may use your version of this file under
35 * the terms of any one of the MPL, the GPL or the LGPL.
37 * ***** END LICENSE BLOCK ***** */
39 File Name: 15.5.4.11-5.js
40 ECMA Section: 15.5.4.11 String.prototype.toLowerCase()
43 Returns a string equal in length to the length of the result of converting
44 this object to a string. The result is a string value, not a String object.
46 Every character of the result is equal to the corresponding character of the
47 string, unless that character has a Unicode 2.0 uppercase equivalent, in which
48 case the uppercase equivalent is used instead. (The canonical Unicode 2.0 case
49 mapping shall be used, which does not depend on implementation or locale.)
51 Note that the toLowerCase function is intentionally generic; it does not require
52 that its this value be a String object. Therefore it can be transferred to other
53 kinds of objects for use as a method.
55 Author: christine@netscape.com
56 Date: 12 november 1997
59 var SECTION = "15.5.4.11-5";
60 var VERSION = "ECMA_1";
62 var TITLE = "String.prototype.toLowerCase()";
64 writeHeaderToLog( SECTION + " "+ TITLE);
66 new TestCase( SECTION, "String.prototype.toLowerCase.length", 0, String.prototype.toLowerCase.length );
68 new TestCase( SECTION, "delete String.prototype.toLowerCase.length", false, delete String.prototype.toLowerCase.length );
70 new TestCase( SECTION, "delete String.prototype.toLowerCase.length; String.prototype.toLowerCase.length", 0, eval("delete String.prototype.toLowerCase.length; String.prototype.toLowerCase.length") );
73 // Range: U+0400 to U+04FF
74 for ( var i = 0x0400; i <= 0x047F; i++ ) {
75 var U = new Unicode( i );
77 new TestCase( SECTION,
78 "var s = new String( String.fromCharCode("+i+") ); s.toLowerCase()",
79 String.fromCharCode(U.lower),
80 eval("var s = new String( String.fromCharCode("+i+") ); s.toLowerCase()") );
82 new TestCase( SECTION,
83 "var s = new String( String.fromCharCode("+i+") ); s.toLowerCase().charCodeAt(0)",
85 eval("var s = new String( String.fromCharCode(i) ); s.toLowerCase().charCodeAt(0)") );
90 function MyObject( value ) {
92 this.substring = String.prototype.substring;
93 this.toString = new Function ( "return this.value+''" );
95 function Unicode( c ) {
96 u = GetUnicodeValues( c );
101 function GetUnicodeValues( c ) {
107 // upper case Basic Latin
109 if ( c >= 0x0041 && c <= 0x005A) {
115 // lower case Basic Latin
116 if ( c >= 0x0061 && c <= 0x007a ) {
122 // upper case Latin-1 Supplement
123 if ( (c >= 0x00C0 && c <= 0x00D6) || (c >= 0x00D8 && c<=0x00DE) ) {
129 // lower case Latin-1 Supplement
130 if ( (c >= 0x00E0 && c <= 0x00F6) || (c >= 0x00F8 && c <= 0x00FE) ) {
141 if ( (c >= 0x0100 && c < 0x0138) || (c > 0x0149 && c < 0x0178) ) {
142 // special case for capital I
155 // if it's even, it's a capital and the lower case is c +1
159 // if it's odd, it's a lower case and upper case is c-1
171 if ( (c >= 0x0139 && c < 0x0149) || (c > 0x0178 && c < 0x017F) ) {
173 // if it's odd, it's a capital and the lower case is c +1
177 // if it's even, it's a lower case and upper case is c-1
189 // need to improve this set
191 if ( c >= 0x0200 && c <= 0x0217 ) {
202 // Latin Extended Additional
203 // Range: U+1E00 to U+1EFF
204 // http://www.unicode.org/Unicode.charts/glyphless/U1E00.html
206 // Spacing Modifier Leters
207 // Range: U+02B0 to U+02FF
209 // Combining Diacritical Marks
210 // Range: U+0300 to U+036F
212 // skip Greek for now
214 // Range: U+0370 to U+03FF
217 // Range: U+0400 to U+04FF
219 if ( (c >= 0x0401 && c <= 0x040C) || ( c>= 0x040E && c <= 0x040F ) ) {
226 if ( c >= 0x0410 && c <= 0x042F ) {
232 if ( c >= 0x0430 && c<= 0x044F ) {
238 if ( (c >= 0x0451 && c <= 0x045C) || (c >=0x045E && c<= 0x045F) ) {
244 if ( c >= 0x0460 && c <= 0x047F ) {
256 // Range: U+0530 to U+058F
257 if ( c >= 0x0531 && c <= 0x0556 ) {
262 if ( c >= 0x0561 && c < 0x0587 ) {
269 // Range: U+0590 to U+05FF
273 // Range: U+0600 to U+06FF
276 // Range: U+0900 to U+097F
280 // Range: U+0980 to U+09FF
284 // Range: U+0A00 to U+0A7F
288 // Range: U+0A80 to U+0AFF
292 // Range: U+0B00 to U+0B7F
293 // no capital / lower case
297 // Range: U+0B80 to U+0BFF
298 // no capital / lower case
302 // Range: U+0C00 to U+0C7F
303 // no capital / lower case
307 // Range: U+0C80 to U+0CFF
308 // no capital / lower case
312 // Range: U+0D00 to U+0D7F
315 // Range: U+0E00 to U+0E7F
319 // Range: U+0E80 to U+0EFF
323 // Range: U+0F00 to U+0FBF
326 // Range: U+10A0 to U+10F0
327 if ( c >= 0x10A0 && c <= 0x10C5 ) {
332 if ( c >= 0x10D0 && c <= 0x10F5 ) {
339 // Range: U+1100 to U+11FF
342 // Range: U+1F00 to U+1FFF
346 // General Punctuation
347 // Range: U+2000 to U+206F
349 // Superscripts and Subscripts
350 // Range: U+2070 to U+209F
353 // Range: U+20A0 to U+20CF
356 // Combining Diacritical Marks for Symbols
357 // Range: U+20D0 to U+20FF
362 // Range: U+2150 to U+218F
367 // Range: U+2190 to U+21FF
369 // Mathematical Operators
370 // Range: U+2200 to U+22FF
372 // Miscellaneous Technical
373 // Range: U+2300 to U+23FF
376 // Range: U+2400 to U+243F
378 // Optical Character Recognition
379 // Range: U+2440 to U+245F
381 // Enclosed Alphanumerics
382 // Range: U+2460 to U+24FF
385 // Range: U+2500 to U+257F
388 // Range: U+2580 to U+259F
391 // Range: U+25A0 to U+25FF
393 // Miscellaneous Symbols
394 // Range: U+2600 to U+26FF
397 // Range: U+2700 to U+27BF
399 // CJK Symbols and Punctuation
400 // Range: U+3000 to U+303F
403 // Range: U+3040 to U+309F
406 // Range: U+30A0 to U+30FF
409 // Range: U+3100 to U+312F
411 // Hangul Compatibility Jamo
412 // Range: U+3130 to U+318F
415 // Range: U+3190 to U+319F
418 // Enclosed CJK Letters and Months
419 // Range: U+3200 to U+32FF
422 // Range: U+3300 to U+33FF
425 // Range: U+AC00 to U+D7A3
428 // Range: U+D800 to U+DB7F
430 // Private Use High Surrogates
431 // Range: U+DB80 to U+DBFF
434 // Range: U+DC00 to U+DFFF
437 // Range: U+E000 to U+F8FF
439 // CJK Compatibility Ideographs
440 // Range: U+F900 to U+FAFF
442 // Alphabetic Presentation Forms
443 // Range: U+FB00 to U+FB4F
445 // Arabic Presentation Forms-A
446 // Range: U+FB50 to U+FDFF
448 // Combining Half Marks
449 // Range: U+FE20 to U+FE2F
451 // CJK Compatibility Forms
452 // Range: U+FE30 to U+FE4F
454 // Small Form Variants
455 // Range: U+FE50 to U+FE6F
457 // Arabic Presentation Forms-B
458 // Range: U+FE70 to U+FEFF
460 // Halfwidth and Fullwidth Forms
461 // Range: U+FF00 to U+FFEF
463 if ( c >= 0xFF21 && c <= 0xFF3A ) {
469 if ( c >= 0xFF41 && c <= 0xFF5A ) {
476 // Range: U+FFF0 to U+FFFF
481 function DecimalToHexString( n ) {
485 for ( var i = 3; i >= 0; i-- ) {
486 if ( n >= Math.pow(16, i) ){
487 var t = Math.floor( n / Math.pow(16, i));
488 n -= t * Math.pow(16, i);