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