michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: michael@0: /** michael@0: File Name: 15.5.4.11-6.js michael@0: ECMA Section: 15.5.4.11 String.prototype.toLowerCase() michael@0: Description: michael@0: michael@0: Returns a string equal in length to the length of the result of converting michael@0: this object to a string. The result is a string value, not a String object. michael@0: michael@0: Every character of the result is equal to the corresponding character of the michael@0: string, unless that character has a Unicode 2.0 uppercase equivalent, in which michael@0: case the uppercase equivalent is used instead. (The canonical Unicode 2.0 case michael@0: mapping shall be used, which does not depend on implementation or locale.) michael@0: michael@0: Note that the toLowerCase function is intentionally generic; it does not require michael@0: that its this value be a String object. Therefore it can be transferred to other michael@0: kinds of objects for use as a method. michael@0: michael@0: Author: christine@netscape.com michael@0: Date: 12 november 1997 michael@0: */ michael@0: michael@0: var SECTION = "15.5.4.11-6"; michael@0: var VERSION = "ECMA_1"; michael@0: startTest(); michael@0: var TITLE = "String.prototype.toLowerCase()"; michael@0: michael@0: writeHeaderToLog( SECTION + " "+ TITLE); michael@0: michael@0: // Armenian michael@0: // Range: U+0530 to U+058F michael@0: for ( var i = 0x0530; i <= 0x058F; i++ ) { michael@0: michael@0: var U = new Unicode( i ); michael@0: /* michael@0: new TestCase( SECTION, michael@0: "var s = new String( String.fromCharCode("+i+") ); s.toLowerCase()", michael@0: String.fromCharCode(U.lower), michael@0: eval("var s = new String( String.fromCharCode("+i+") ); s.toLowerCase()") ); michael@0: */ michael@0: new TestCase( SECTION, michael@0: "var s = new String( String.fromCharCode("+i+") ); s.toLowerCase().charCodeAt(0)", michael@0: U.lower, michael@0: eval("var s = new String( String.fromCharCode(i) ); s.toLowerCase().charCodeAt(0)") ); michael@0: michael@0: } michael@0: michael@0: test(); michael@0: michael@0: function MyObject( value ) { michael@0: this.value = value; michael@0: this.substring = String.prototype.substring; michael@0: this.toString = new Function ( "return this.value+''" ); michael@0: } michael@0: function Unicode( c ) { michael@0: u = GetUnicodeValues( c ); michael@0: this.upper = u[0]; michael@0: this.lower = u[1] michael@0: return this; michael@0: } michael@0: function GetUnicodeValues( c ) { michael@0: u = new Array(); michael@0: michael@0: u[0] = c; michael@0: u[1] = c; michael@0: michael@0: // upper case Basic Latin michael@0: michael@0: if ( c >= 0x0041 && c <= 0x005A) { michael@0: u[0] = c; michael@0: u[1] = c + 32; michael@0: return u; michael@0: } michael@0: michael@0: // lower case Basic Latin michael@0: if ( c >= 0x0061 && c <= 0x007a ) { michael@0: u[0] = c - 32; michael@0: u[1] = c; michael@0: return u; michael@0: } michael@0: michael@0: // upper case Latin-1 Supplement michael@0: if ( (c >= 0x00C0 && c <= 0x00D6) || (c >= 0x00D8 && c<=0x00DE) ) { michael@0: u[0] = c; michael@0: u[1] = c + 32; michael@0: return u; michael@0: } michael@0: michael@0: // lower case Latin-1 Supplement michael@0: if ( (c >= 0x00E0 && c <= 0x00F6) || (c >= 0x00F8 && c <= 0x00FE) ) { michael@0: u[0] = c - 32; michael@0: u[1] = c; michael@0: return u; michael@0: } michael@0: if ( c == 0x00FF ) { michael@0: u[0] = 0x0178; michael@0: u[1] = c; michael@0: return u; michael@0: } michael@0: // Latin Extended A michael@0: if ( (c >= 0x0100 && c < 0x0138) || (c > 0x0149 && c < 0x0178) ) { michael@0: // special case for capital I michael@0: if ( c == 0x0130 ) { michael@0: u[0] = c; michael@0: u[1] = 0x0069; michael@0: return u; michael@0: } michael@0: if ( c == 0x0131 ) { michael@0: u[0] = 0x0049; michael@0: u[1] = c; michael@0: return u; michael@0: } michael@0: michael@0: if ( c % 2 == 0 ) { michael@0: // if it's even, it's a capital and the lower case is c +1 michael@0: u[0] = c; michael@0: u[1] = c+1; michael@0: } else { michael@0: // if it's odd, it's a lower case and upper case is c-1 michael@0: u[0] = c-1; michael@0: u[1] = c; michael@0: } michael@0: return u; michael@0: } michael@0: if ( c == 0x0178 ) { michael@0: u[0] = c; michael@0: u[1] = 0x00FF; michael@0: return u; michael@0: } michael@0: michael@0: if ( (c >= 0x0139 && c < 0x0149) || (c > 0x0178 && c < 0x017F) ) { michael@0: if ( c % 2 == 1 ) { michael@0: // if it's odd, it's a capital and the lower case is c +1 michael@0: u[0] = c; michael@0: u[1] = c+1; michael@0: } else { michael@0: // if it's even, it's a lower case and upper case is c-1 michael@0: u[0] = c-1; michael@0: u[1] = c; michael@0: } michael@0: return u; michael@0: } michael@0: if ( c == 0x017F ) { michael@0: u[0] = 0x0053; michael@0: u[1] = c; michael@0: } michael@0: michael@0: // Latin Extended B michael@0: // need to improve this set michael@0: michael@0: if ( c >= 0x0200 && c <= 0x0217 ) { michael@0: if ( c % 2 == 0 ) { michael@0: u[0] = c; michael@0: u[1] = c+1; michael@0: } else { michael@0: u[0] = c-1; michael@0: u[1] = c; michael@0: } michael@0: return u; michael@0: } michael@0: michael@0: // Latin Extended Additional michael@0: // Range: U+1E00 to U+1EFF michael@0: // http://www.unicode.org/Unicode.charts/glyphless/U1E00.html michael@0: michael@0: // Spacing Modifier Leters michael@0: // Range: U+02B0 to U+02FF michael@0: michael@0: // Combining Diacritical Marks michael@0: // Range: U+0300 to U+036F michael@0: michael@0: // skip Greek for now michael@0: // Greek michael@0: // Range: U+0370 to U+03FF michael@0: michael@0: // Cyrillic michael@0: // Range: U+0400 to U+04FF michael@0: michael@0: if ( (c >= 0x0401 && c <= 0x040C) || ( c>= 0x040E && c <= 0x040F ) ) { michael@0: u[0] = c; michael@0: u[1] = c + 80; michael@0: return u; michael@0: } michael@0: michael@0: michael@0: if ( c >= 0x0410 && c <= 0x042F ) { michael@0: u[0] = c; michael@0: u[1] = c + 32; michael@0: return u; michael@0: } michael@0: michael@0: if ( c >= 0x0430 && c<= 0x044F ) { michael@0: u[0] = c - 32; michael@0: u[1] = c; michael@0: return u; michael@0: michael@0: } michael@0: if ( (c >= 0x0451 && c <= 0x045C) || (c >=0x045E && c<= 0x045F) ) { michael@0: u[0] = c -80; michael@0: u[1] = c; michael@0: return u; michael@0: } michael@0: michael@0: if ( c >= 0x0460 && c <= 0x047F ) { michael@0: if ( c % 2 == 0 ) { michael@0: u[0] = c; michael@0: u[1] = c +1; michael@0: } else { michael@0: u[0] = c - 1; michael@0: u[1] = c; michael@0: } michael@0: return u; michael@0: } michael@0: michael@0: // Armenian michael@0: // Range: U+0530 to U+058F michael@0: if ( c >= 0x0531 && c <= 0x0556 ) { michael@0: u[0] = c; michael@0: u[1] = c + 48; michael@0: return u; michael@0: } michael@0: if ( c >= 0x0561 && c < 0x0587 ) { michael@0: u[0] = c - 48; michael@0: u[1] = c; michael@0: return u; michael@0: } michael@0: michael@0: // Hebrew michael@0: // Range: U+0590 to U+05FF michael@0: michael@0: michael@0: // Arabic michael@0: // Range: U+0600 to U+06FF michael@0: michael@0: // Devanagari michael@0: // Range: U+0900 to U+097F michael@0: michael@0: michael@0: // Bengali michael@0: // Range: U+0980 to U+09FF michael@0: michael@0: michael@0: // Gurmukhi michael@0: // Range: U+0A00 to U+0A7F michael@0: michael@0: michael@0: // Gujarati michael@0: // Range: U+0A80 to U+0AFF michael@0: michael@0: michael@0: // Oriya michael@0: // Range: U+0B00 to U+0B7F michael@0: // no capital / lower case michael@0: michael@0: michael@0: // Tamil michael@0: // Range: U+0B80 to U+0BFF michael@0: // no capital / lower case michael@0: michael@0: michael@0: // Telugu michael@0: // Range: U+0C00 to U+0C7F michael@0: // no capital / lower case michael@0: michael@0: michael@0: // Kannada michael@0: // Range: U+0C80 to U+0CFF michael@0: // no capital / lower case michael@0: michael@0: michael@0: // Malayalam michael@0: // Range: U+0D00 to U+0D7F michael@0: michael@0: // Thai michael@0: // Range: U+0E00 to U+0E7F michael@0: michael@0: michael@0: // Lao michael@0: // Range: U+0E80 to U+0EFF michael@0: michael@0: michael@0: // Tibetan michael@0: // Range: U+0F00 to U+0FBF michael@0: michael@0: // Georgian michael@0: // Range: U+10A0 to U+10F0 michael@0: if ( c >= 0x10A0 && c <= 0x10C5 ) { michael@0: u[0] = c; michael@0: u[1] = c + 48; michael@0: return u; michael@0: } michael@0: if ( c >= 0x10D0 && c <= 0x10F5 ) { michael@0: u[0] = c; michael@0: u[1] = c; michael@0: return u; michael@0: } michael@0: michael@0: // Hangul Jamo michael@0: // Range: U+1100 to U+11FF michael@0: michael@0: // Greek Extended michael@0: // Range: U+1F00 to U+1FFF michael@0: // skip for now michael@0: michael@0: michael@0: // General Punctuation michael@0: // Range: U+2000 to U+206F michael@0: michael@0: // Superscripts and Subscripts michael@0: // Range: U+2070 to U+209F michael@0: michael@0: // Currency Symbols michael@0: // Range: U+20A0 to U+20CF michael@0: michael@0: michael@0: // Combining Diacritical Marks for Symbols michael@0: // Range: U+20D0 to U+20FF michael@0: // skip for now michael@0: michael@0: michael@0: // Number Forms michael@0: // Range: U+2150 to U+218F michael@0: // skip for now michael@0: michael@0: michael@0: // Arrows michael@0: // Range: U+2190 to U+21FF michael@0: michael@0: // Mathematical Operators michael@0: // Range: U+2200 to U+22FF michael@0: michael@0: // Miscellaneous Technical michael@0: // Range: U+2300 to U+23FF michael@0: michael@0: // Control Pictures michael@0: // Range: U+2400 to U+243F michael@0: michael@0: // Optical Character Recognition michael@0: // Range: U+2440 to U+245F michael@0: michael@0: // Enclosed Alphanumerics michael@0: // Range: U+2460 to U+24FF michael@0: michael@0: // Box Drawing michael@0: // Range: U+2500 to U+257F michael@0: michael@0: // Block Elements michael@0: // Range: U+2580 to U+259F michael@0: michael@0: // Geometric Shapes michael@0: // Range: U+25A0 to U+25FF michael@0: michael@0: // Miscellaneous Symbols michael@0: // Range: U+2600 to U+26FF michael@0: michael@0: // Dingbats michael@0: // Range: U+2700 to U+27BF michael@0: michael@0: // CJK Symbols and Punctuation michael@0: // Range: U+3000 to U+303F michael@0: michael@0: // Hiragana michael@0: // Range: U+3040 to U+309F michael@0: michael@0: // Katakana michael@0: // Range: U+30A0 to U+30FF michael@0: michael@0: // Bopomofo michael@0: // Range: U+3100 to U+312F michael@0: michael@0: // Hangul Compatibility Jamo michael@0: // Range: U+3130 to U+318F michael@0: michael@0: // Kanbun michael@0: // Range: U+3190 to U+319F michael@0: michael@0: michael@0: // Enclosed CJK Letters and Months michael@0: // Range: U+3200 to U+32FF michael@0: michael@0: // CJK Compatibility michael@0: // Range: U+3300 to U+33FF michael@0: michael@0: // Hangul Syllables michael@0: // Range: U+AC00 to U+D7A3 michael@0: michael@0: // High Surrogates michael@0: // Range: U+D800 to U+DB7F michael@0: michael@0: // Private Use High Surrogates michael@0: // Range: U+DB80 to U+DBFF michael@0: michael@0: // Low Surrogates michael@0: // Range: U+DC00 to U+DFFF michael@0: michael@0: // Private Use Area michael@0: // Range: U+E000 to U+F8FF michael@0: michael@0: // CJK Compatibility Ideographs michael@0: // Range: U+F900 to U+FAFF michael@0: michael@0: // Alphabetic Presentation Forms michael@0: // Range: U+FB00 to U+FB4F michael@0: michael@0: // Arabic Presentation Forms-A michael@0: // Range: U+FB50 to U+FDFF michael@0: michael@0: // Combining Half Marks michael@0: // Range: U+FE20 to U+FE2F michael@0: michael@0: // CJK Compatibility Forms michael@0: // Range: U+FE30 to U+FE4F michael@0: michael@0: // Small Form Variants michael@0: // Range: U+FE50 to U+FE6F michael@0: michael@0: // Arabic Presentation Forms-B michael@0: // Range: U+FE70 to U+FEFF michael@0: michael@0: // Halfwidth and Fullwidth Forms michael@0: // Range: U+FF00 to U+FFEF michael@0: michael@0: if ( c >= 0xFF21 && c <= 0xFF3A ) { michael@0: u[0] = c; michael@0: u[1] = c + 32; michael@0: return u; michael@0: } michael@0: michael@0: if ( c >= 0xFF41 && c <= 0xFF5A ) { michael@0: u[0] = c - 32; michael@0: u[1] = c; michael@0: return u; michael@0: } michael@0: michael@0: // Specials michael@0: // Range: U+FFF0 to U+FFFF michael@0: michael@0: return u; michael@0: } michael@0: michael@0: function DecimalToHexString( n ) { michael@0: n = Number( n ); michael@0: var h = "0x"; michael@0: michael@0: for ( var i = 3; i >= 0; i-- ) { michael@0: if ( n >= Math.pow(16, i) ){ michael@0: var t = Math.floor( n / Math.pow(16, i)); michael@0: n -= t * Math.pow(16, i); michael@0: if ( t >= 10 ) { michael@0: if ( t == 10 ) { michael@0: h += "A"; michael@0: } michael@0: if ( t == 11 ) { michael@0: h += "B"; michael@0: } michael@0: if ( t == 12 ) { michael@0: h += "C"; michael@0: } michael@0: if ( t == 13 ) { michael@0: h += "D"; michael@0: } michael@0: if ( t == 14 ) { michael@0: h += "E"; michael@0: } michael@0: if ( t == 15 ) { michael@0: h += "F"; michael@0: } michael@0: } else { michael@0: h += String( t ); michael@0: } michael@0: } else { michael@0: h += "0"; michael@0: } michael@0: } michael@0: michael@0: return h; michael@0: }