Subversion Repositories JSX

Compare Revisions

Last modification

Ignore whitespace Rev 423 → Rev 424

/trunk/test/unicode.js
25,7 → 25,7
}
},
{
feature: 'new jsx.string.unicode.WideString(WideString)',
feature: 'new WideString(wideString)',
description: 'Clone instance',
code: function () {
var chars = new WideString(new WideString(("x"))).getChars();
33,7 → 33,7
}
},
{
feature: 'new jsx.string.unicode.WideString("")',
feature: 'new WideString("")',
description: 'Return new empty instance',
code: function () {
assertArrayEquals([], new WideString("").getChars());
40,7 → 40,7
}
},
{
feature: 'new jsx.string.unicode.WideString("x")',
feature: 'new WideString("x")',
description: 'Convert to <code>WideString("x")</code>',
code: function () {
assertArrayEquals(["x"], new WideString("x").getChars());
47,7 → 47,7
}
},
{
feature: 'new jsx.string.unicode.WideString(42)',
feature: 'new WideString(42)',
description: 'Convert to <code>WideString("42")</code>',
code: function () {
assertArrayEquals(["4", "2"], new WideString(42).getChars());
55,7 → 55,7
},
 
{
feature: 'new jsx.string.unicode.WideString(string).getChars()',
feature: 'wideString.getChars()',
description: 'Return the correct value',
code: function () {
assertArrayEquals([], new WideString().getChars());
66,7 → 66,7
}
},
{
feature: 'new jsx.string.unicode.WideString(string).chars',
feature: 'wideString.chars',
description: 'Getter works',
code: function () {
assertArrayEquals(["x"], new WideString("x").chars);
74,7 → 74,7
},
 
{
feature: 'new jsx.string.unicode.WideString(string).getLength()',
feature: 'wideString.getLength()',
description: 'Return the correct value',
code: function () {
assert(new WideString().getLength() === 0);
85,7 → 85,7
}
},
{
feature: 'new jsx.string.unicode.WideString(string).length',
feature: 'wideString.length',
description: 'Inherited getter works',
code: function () {
assert(new WideString("x").length === 1);
93,7 → 93,7
},
 
{
feature: 'jsx.string.unicode.WideString.fromCharCode(0x110000)',
feature: 'WideString.fromCharCode(0x110000)',
description: 'throw <code>jsx.InvalidArgumentError</code>',
code: function () {
var error = false;
114,8 → 114,8
}
},
{
feature: 'jsx.string.unicode.WideString.fromCharCode(0x1D11E)',
description: 'Return <code>"\\uD834\\uDD1E"</code>',
feature: 'WideString.fromCharCode(0x1D11E)',
description: 'Return <code>WideString("\\uD834\\uDD1E")</code>',
code: function () {
var chars = WideString.fromCharCode(0x1D11E).getChars();
assertArrayEquals(["\uD834\uDD1E"], chars);
122,8 → 122,8
}
},
{
feature: 'jsx.string.unicode.WideString.fromCharCode(0x20AC)',
description: 'Return <code>"\\u20AC"</code>',
feature: 'WideString.fromCharCode(0x20AC)',
description: 'Return <code>WideString("\\u20AC")</code>',
code: function () {
var chars = WideString.fromCharCode(0x20AC).getChars();
assertArrayEquals(["\u20AC"], chars);
131,7 → 131,7
},
 
{
feature: 'new jsx.string.unicode.WideString("…").charAt(…)',
feature: 'wideString.charAt(…)',
description: 'Return the correct value',
code: function () {
assert(new WideString("x\uD834\uDD1E").charAt(1) === "\uD834\uDD1E");
145,7 → 145,7
},
 
{
feature: 'new jsx.string.unicode.WideString("…").charCodeAt(…)',
feature: 'wideString.charCodeAt(…)',
description: 'Return the correct value',
code: function () {
assert(new WideString("x\uD834\uDD1E").charCodeAt(1) === 0x1D11E);
163,7 → 163,7
},
 
{
feature: 'new jsx.string.unicode.WideString("…").concat(…)',
feature: 'wideString.concat(…)',
description: 'Return the correct value',
code: function () {
var s = new WideString("x").concat(new WideString("\uD834\uDD1E"));
193,7 → 193,7
},
 
{
feature: 'new jsx.string.unicode.WideString("…").indexOf(…)',
feature: 'wideString.indexOf(…)',
description: 'Return the correct value',
code: function () {
assert(new WideString("x\uD834\uDD1Ez").indexOf(
216,7 → 216,7
},
 
{
feature: 'new jsx.string.unicode.WideString("…").lastIndexOf(…)',
feature: 'wideString.lastIndexOf(…)',
description: 'Return the correct value',
code: function () {
assert(new WideString("x\uD834\uDD1E").lastIndexOf(
236,7 → 236,7
},
 
{
feature: 'new jsx.string.unicode.WideString("…").localeCompare("…")',
feature: 'wideString.localeCompare("…")',
description: 'Return the correct value (inherited generic method)',
code: function () {
assert(new WideString("x").localeCompare("y") === "x".localeCompare("y"));
244,7 → 244,7
},
 
{
feature: 'new jsx.string.unicode.WideString("…").match("…")',
feature: 'wideString.match("…")',
description: 'Return the correct value (inherited generic method)',
code: function () {
assertArrayEquals("x".match("x"), new WideString("x").match("x"));
253,7 → 253,7
},
 
{
feature: 'new jsx.string.unicode.WideString("…").replace("…")',
feature: 'wideString.replace("…")',
description: 'Return the correct value (inherited generic method)',
code: function () {
assert(new WideString("x").replace("x", "y").toString() === "x".replace("x", "y"));
262,7 → 262,7
},
 
{
feature: 'new jsx.string.unicode.WideString("…").search("…")',
feature: 'wideString.search("…")',
description: 'Return the correct value (inherited generic method)',
code: function () {
assert(new WideString("x").search(/y/) === "x".search(/y/));
271,7 → 271,7
},
 
{
feature: 'new jsx.string.unicode.WideString("…").slice(…)',
feature: 'wideString.slice(…)',
description: 'Return the correct value',
code: function () {
var s = new WideString("x\uD834\uDD1Ey").slice(1);
292,7 → 292,7
},
 
{
feature: 'new jsx.string.unicode.WideString("…").substr(…)',
feature: 'wideString("…").substr(…)',
description: 'Return the correct value',
code: function () {
var s = new WideString("x\uD834\uDD1Ey").substr(1);
313,7 → 313,7
},
 
{
feature: 'new jsx.string.unicode.WideString("…").substring(…)',
feature: 'wideString.substring(…)',
description: 'Return the correct value',
code: function () {
var s = new WideString("x\uD834\uDD1Ey").substring(1);
337,7 → 337,7
},
 
{
feature: 'new jsx.string.unicode.WideString("…").toString(…)',
feature: 'wideString.toString(…)',
description: 'Return the correct value',
code: function () {
var s = new WideString("x\uD834\uDD1Ey").toString();
346,12 → 346,28
},
 
{
feature: 'new jsx.string.unicode.WideString("…").valueOf(…)',
feature: 'wideString.valueOf(…)',
description: 'Return the correct value',
code: function () {
var s = new WideString("x\uD834\uDD1Ey").valueOf();
assert(s === "x\uD834\uDD1Ey");
}
},
 
{
feature: 'String.fromCharCode(0x1D11E)',
description: 'Return <code>"\\uD834\\uDD1E"</code>',
code: function () {
assert(String.fromCharCode(0x1D11E) === "\uD834\uDD1E");
}
},
 
{
feature: 'string.getLength()',
description: 'Return the correct value (augmented prototype)',
code: function () {
assert("x\uD834\uDD1Ey".getLength() === 3);
}
}
]
});
/trunk/string/unicode.js
44,16 → 44,18
* Unicode characters from both inside and beyond the BMP, from
* code points U+0000 to U+10FFFF inclusive.
*
* A future revision might also allow to replace the values of
* certain built-in properties of the <code>String</code>
* constructor and <code>String</code> prototype object such
* as the ones mentioned above, and to add others to the prototype
* object, so as to support non-BMP characters in implementations
* of those ECMAScript Editions as well almost seamlessly.
* However, non-callable built-in own and inherited properties
* of <code>String</code> values, like <code>length</code>,
* could <em>not</em> be modified. (In case of <code>length</code>,
* you would need to use <code>getLength()</code> instead.)
* It also replaces by default the values of certain built-in
* properties of the <code>String</code> constructor and
* <code>String</code> prototype object such as the ones mentioned
* above, and add others to the prototype object, so as to
* support non-BMP characters as well in implementations of those
* ECMAScript Editions almost seamlessly. However, non-callable
* built-in own and inherited properties of <code>String</code>
* values, like <code>length</code>, <em>cannot</em> be modified.
* (In case of <code>length</code>, you would need to use
* <code>getLength()</code> instead.) Whether and to what extent
* built-in objects are modified, can be controlled with
* {@link jsx#options}. (See {@link "object.js"} for details.)
*
* Your feedback is appreciated.
*
123,12 → 125,13
* <p>
* A <code>WideString</code> supports all operations and methods
* supported on <code>String</code> values also for Unicode
* characters outside the Basic Multilingual Plane (BMP:
* U+10000 to U+10FFFF). Because strings of characters are
* stored as an {@link Array} of <code>String</code>s,
* operations where such characters are more common are faster
* than with the <code>String</code> prototype augmentation.
* In other cases you should use the augmentation instead.
* characters outside the Basic Multilingual Plane (BMP), that
* is, code points from U+0000 to U+10FFFF inclusive. Because
* strings of characters are stored as an {@link Array} of
* <code>String</code>s, operations where such characters are
* more common are faster than with the <code>String</code>
* prototype augmentation. In other cases you should use
* the augmentation instead.
* </p><p>
* You may call a <code>WideString</code>'s
* {@link WideString#prototype.toString toString()} method
524,6 → 527,47
return _fromCharCode;
}());
 
if (jsx.options.augmentBuiltins)
{
if (jsx.options.augmentPrototypes)
{
jsx.object.setProperties(String.prototype, {
/**
* Returns the number of Unicode characters in this string.
*
* Differs from the built-in {@link string#length length}
* property in that it considers characters with code points
* beyond U+FFFF that require several UTF-16 code units.
*
* @memberOf String.prototype
* @return {number}
*/
getLength: function () {
return (new _WideString(this)).getLength();
}
});
}
}
 
if (jsx.options.replaceBuiltins)
{
jsx.object.setProperties(String, {
/**
* Returns a {@link String} containing the Unicode characters
* specified by the code point arguments.
*
* @memberOf String
* @params {Number}
* Code points of the characters from <code>0</code> to
* <code>0x10FFFF</code> inclusive.
* @return {string}
*/
fromCharCode: function () {
return _WideString.fromCharCode.apply(this, arguments).toString();
}
}, jsx.object.ADD_OVERWRITE);
}
 
return {
/**
* @memberOf jsx.string.unicode