-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add well formed unicode strings proposal
- Loading branch information
Showing
16 changed files
with
126 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
var isPrototypeOf = require('../../internals/object-is-prototype-of'); | ||
var method = require('../string/virtual/is-well-formed'); | ||
|
||
var StringPrototype = String.prototype; | ||
|
||
module.exports = function (it) { | ||
var own = it.isWellFormed; | ||
return typeof it == 'string' || it === StringPrototype | ||
|| (isPrototypeOf(StringPrototype, it) && own === StringPrototype.isWellFormed) ? method : own; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
var isPrototypeOf = require('../../internals/object-is-prototype-of'); | ||
var method = require('../string/virtual/to-well-formed'); | ||
|
||
var StringPrototype = String.prototype; | ||
|
||
module.exports = function (it) { | ||
var own = it.toWellFormed; | ||
return typeof it == 'string' || it === StringPrototype | ||
|| (isPrototypeOf(StringPrototype, it) && own === StringPrototype.toWellFormed) ? method : own; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
require('../../modules/esnext.string.is-well-formed'); | ||
|
||
module.exports = require('../../internals/entry-unbind')('String', 'isWellFormed'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
require('../../modules/esnext.string.to-well-formed'); | ||
|
||
module.exports = require('../../internals/entry-unbind')('String', 'toWellFormed'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
require('../../../modules/esnext.string.is-well-formed'); | ||
|
||
module.exports = require('../../../internals/entry-virtual')('String').isWellFormed; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
require('../../../modules/esnext.string.to-well-formed'); | ||
|
||
module.exports = require('../../../internals/entry-virtual')('String').toWellFormed; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
'use strict'; | ||
var $ = require('../internals/export'); | ||
var uncurryThis = require('../internals/function-uncurry-this'); | ||
var requireObjectCoercible = require('../internals/require-object-coercible'); | ||
var toString = require('../internals/to-string'); | ||
|
||
var charCodeAt = uncurryThis(''.charCodeAt); | ||
|
||
// `String.prototype.isWellFormed` method | ||
// https://github.com/tc39/proposal-is-usv-string | ||
$({ target: 'String', proto: true, forced: true }, { | ||
isWellFormed: function isWellFormed() { | ||
var S = toString(requireObjectCoercible(this)); | ||
var length = S.length; | ||
for (var i = 0; i < length; i++) { | ||
var charCode = charCodeAt(S, i); | ||
// single UTF-16 code unit | ||
if ((charCode & 0xF800) != 0xD800) continue; | ||
// unpaired surrogate | ||
if (charCode >= 0xDC00 || ++i >= length || (charCodeAt(S, i) & 0xFC00) != 0xDC00) return false; | ||
} return true; | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
'use strict'; | ||
var $ = require('../internals/export'); | ||
var uncurryThis = require('../internals/function-uncurry-this'); | ||
var requireObjectCoercible = require('../internals/require-object-coercible'); | ||
var toString = require('../internals/to-string'); | ||
|
||
var $Array = Array; | ||
var charAt = uncurryThis(''.charAt); | ||
var charCodeAt = uncurryThis(''.charCodeAt); | ||
var join = uncurryThis([].join); | ||
var REPLACEMENT_CHARACTER = '\uFFFD'; | ||
|
||
// `String.prototype.toWellFormed` method | ||
// https://github.com/tc39/proposal-is-usv-string | ||
$({ target: 'String', proto: true, forced: true }, { | ||
toWellFormed: function toWellFormed() { | ||
var S = toString(requireObjectCoercible(this)); | ||
var length = S.length; | ||
var result = $Array(length); | ||
for (var i = 0; i < length; i++) { | ||
var charCode = charCodeAt(S, i); | ||
// single UTF-16 code unit | ||
if ((charCode & 0xF800) != 0xD800) result[i] = charAt(S, i); | ||
// unpaired surrogate | ||
else if (charCode >= 0xDC00 || i + 1 >= length || (charCodeAt(S, i + 1) & 0xFC00) != 0xDC00) result[i] = REPLACEMENT_CHARACTER; | ||
// surrogate pair | ||
else { | ||
result[i] = charAt(S, i); | ||
result[++i] = charAt(S, i); | ||
} | ||
} return join(result, ''); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
require('../modules/esnext.string.is-well-formed'); | ||
require('../modules/esnext.string.to-well-formed'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters