|
Last change
on this file was 9af201e, checked in by MBK <marija.karapandzova@…>, 12 days ago |
|
Fix frontend appearance
|
-
Property mode
set to
100644
|
|
File size:
558 bytes
|
| Line | |
|---|
| 1 | 'use strict';
|
|---|
| 2 |
|
|---|
| 3 | // https://mathiasbynens.be/notes/javascript-encoding
|
|---|
| 4 | // https://github.com/bestiejs/punycode.js - punycode.ucs2.decode
|
|---|
| 5 | module.exports = function ucs2length(str) {
|
|---|
| 6 | var length = 0
|
|---|
| 7 | , len = str.length
|
|---|
| 8 | , pos = 0
|
|---|
| 9 | , value;
|
|---|
| 10 | while (pos < len) {
|
|---|
| 11 | length++;
|
|---|
| 12 | value = str.charCodeAt(pos++);
|
|---|
| 13 | if (value >= 0xD800 && value <= 0xDBFF && pos < len) {
|
|---|
| 14 | // high surrogate, and there is a next character
|
|---|
| 15 | value = str.charCodeAt(pos);
|
|---|
| 16 | if ((value & 0xFC00) == 0xDC00) pos++; // low surrogate
|
|---|
| 17 | }
|
|---|
| 18 | }
|
|---|
| 19 | return length;
|
|---|
| 20 | };
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.