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/. */
8
File Name: 15.5.4.11-2.js
9
ECMA Section: 15.5.4.11 String.prototype.toLowerCase()
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.
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.)
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.
24
Author: christine@netscape.com
25
Date: 12 november 1997
28
var SECTION = "15.5.4.11-2";
29
var VERSION = "ECMA_1";
31
var TITLE = "String.prototype.toLowerCase()";
33
writeHeaderToLog( SECTION + " "+ TITLE);
35
// Hiragana (no upper / lower case)
36
// Range: U+3040 to U+309F
38
for ( var i = 0x3040; i <= 0x309F; i++ ) {
39
var U = new Unicode( i );
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()") );
46
new TestCase( SECTION,
47
"var s = new String( String.fromCharCode("+i+") ); s.toLowerCase().charCodeAt(0)",
49
eval("var s = new String( String.fromCharCode(i) ); s.toLowerCase().charCodeAt(0)") );
54
function MyObject( value ) {
56
this.substring = String.prototype.substring;
57
this.toString = new Function ( "return this.value+''" );
59
function Unicode( c ) {
63
// upper case Basic Latin
65
if ( c >= 0x0041 && c <= 0x005A) {
71
// lower case Basic Latin
72
if ( c >= 0x0061 && c <= 0x007a ) {
78
// upper case Latin-1 Supplement
79
if ( (c >= 0x00C0 && c <= 0x00D6) || (c >= 0x00D8 && c<=0x00DE) ) {
85
// lower case Latin-1 Supplement
86
if ( (c >= 0x00E0 && c <= 0x00F6) || (c >= 0x00F8 && c <= 0x00FE) ) {
97
if ( (c >= 0x0100 && c < 0x0138) || (c > 0x0149 && c < 0x0178) ) {
98
// special case for capital I
111
// if it's even, it's a capital and the lower case is c +1
115
// if it's odd, it's a lower case and upper case is c-1
127
if ( (c >= 0x0139 && c < 0x0149) || (c > 0x0178 && c < 0x017F) ) {
129
// if it's odd, it's a capital and the lower case is c +1
133
// if it's even, it's a lower case and upper case is c-1
145
// need to improve this set
147
if ( c >= 0x0200 && c <= 0x0217 ) {
158
// Latin Extended Additional
159
// Range: U+1E00 to U+1EFF
160
// http://www.unicode.org/Unicode.charts/glyphless/U1E00.html
162
// Spacing Modifier Leters
163
// Range: U+02B0 to U+02FF
165
// Combining Diacritical Marks
166
// Range: U+0300 to U+036F
168
// skip Greek for now
170
// Range: U+0370 to U+03FF
173
// Range: U+0400 to U+04FF
175
if ( (c >= 0x0401 && c <= 0x040C) || ( c>= 0x040E && c <= 0x040F ) ) {
182
if ( c >= 0x0410 && c <= 0x042F ) {
188
if ( c >= 0x0430 && c<= 0x044F ) {
194
if ( (c >= 0x0451 && c <= 0x045C) || (c >=0x045E && c<= 0x045F) ) {
200
if ( c >= 0x0460 && c <= 0x047F ) {
212
// Range: U+0530 to U+058F
213
if ( c >= 0x0531 && c <= 0x0556 ) {
218
if ( c >= 0x0561 && c < 0x0587 ) {
225
// Range: U+0590 to U+05FF
229
// Range: U+0600 to U+06FF
232
// Range: U+0900 to U+097F
236
// Range: U+0980 to U+09FF
240
// Range: U+0A00 to U+0A7F
244
// Range: U+0A80 to U+0AFF
248
// Range: U+0B00 to U+0B7F
249
// no capital / lower case
253
// Range: U+0B80 to U+0BFF
254
// no capital / lower case
258
// Range: U+0C00 to U+0C7F
259
// no capital / lower case
263
// Range: U+0C80 to U+0CFF
264
// no capital / lower case
268
// Range: U+0D00 to U+0D7F
271
// Range: U+0E00 to U+0E7F
275
// Range: U+0E80 to U+0EFF
279
// Range: U+0F00 to U+0FBF
282
// Range: U+10A0 to U+10F0
283
if ( c >= 0x10A0 && c <= 0x10C5 ) {
288
if ( c >= 0x10D0 && c <= 0x10F5 ) {
295
// Range: U+1100 to U+11FF
298
// Range: U+1F00 to U+1FFF
302
// General Punctuation
303
// Range: U+2000 to U+206F
305
// Superscripts and Subscripts
306
// Range: U+2070 to U+209F
309
// Range: U+20A0 to U+20CF
312
// Combining Diacritical Marks for Symbols
313
// Range: U+20D0 to U+20FF
318
// Range: U+2150 to U+218F
323
// Range: U+2190 to U+21FF
325
// Mathematical Operators
326
// Range: U+2200 to U+22FF
328
// Miscellaneous Technical
329
// Range: U+2300 to U+23FF
332
// Range: U+2400 to U+243F
334
// Optical Character Recognition
335
// Range: U+2440 to U+245F
337
// Enclosed Alphanumerics
338
// Range: U+2460 to U+24FF
341
// Range: U+2500 to U+257F
344
// Range: U+2580 to U+259F
347
// Range: U+25A0 to U+25FF
349
// Miscellaneous Symbols
350
// Range: U+2600 to U+26FF
353
// Range: U+2700 to U+27BF
355
// CJK Symbols and Punctuation
356
// Range: U+3000 to U+303F
359
// Range: U+3040 to U+309F
362
// Range: U+30A0 to U+30FF
365
// Range: U+3100 to U+312F
367
// Hangul Compatibility Jamo
368
// Range: U+3130 to U+318F
371
// Range: U+3190 to U+319F
374
// Enclosed CJK Letters and Months
375
// Range: U+3200 to U+32FF
378
// Range: U+3300 to U+33FF
381
// Range: U+AC00 to U+D7A3
384
// Range: U+D800 to U+DB7F
386
// Private Use High Surrogates
387
// Range: U+DB80 to U+DBFF
390
// Range: U+DC00 to U+DFFF
393
// Range: U+E000 to U+F8FF
395
// CJK Compatibility Ideographs
396
// Range: U+F900 to U+FAFF
398
// Alphabetic Presentation Forms
399
// Range: U+FB00 to U+FB4F
401
// Arabic Presentation Forms-A
402
// Range: U+FB50 to U+FDFF
404
// Combining Half Marks
405
// Range: U+FE20 to U+FE2F
407
// CJK Compatibility Forms
408
// Range: U+FE30 to U+FE4F
410
// Small Form Variants
411
// Range: U+FE50 to U+FE6F
413
// Arabic Presentation Forms-B
414
// Range: U+FE70 to U+FEFF
416
// Halfwidth and Fullwidth Forms
417
// Range: U+FF00 to U+FFEF
419
if ( c >= 0xFF21 && c <= 0xFF3A ) {
425
if ( c >= 0xFF41 && c <= 0xFF5A ) {
432
// Range: U+FFF0 to U+FFFF
437
function DecimalToHexString( n ) {
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);