Re: [whatwg/encoding] Consider adding TextEncoder.containsLoneSurrogates() static (#174)

With lookbehind support in JavaScript regular expressions, this functionality can trivially be implemented in userland:

```js
function isWellFormed(string) {
  const reLoneSurrogate = /[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?<![\uD800-\uDBFF])[\uDC00-\uDFFF]/;
  return !reLoneSurrogate.test(string);
}
```

That might explain why it hadn't been considered for standardization before. Still, if this comes up often enough in standards discussions, that might be sufficient motivation to add something like a static `String.isWellFormed` method to the language.

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/whatwg/encoding/issues/174#issuecomment-480735701

Received on Monday, 8 April 2019 08:29:22 UTC