|
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:
1.2 KB
|
| Line | |
|---|
| 1 | 'use strict';
|
|---|
| 2 |
|
|---|
| 3 | var isInteger = require('math-intrinsics/isInteger');
|
|---|
| 4 | var MAX_SAFE_INTEGER = require('math-intrinsics/constants/maxSafeInteger');
|
|---|
| 5 |
|
|---|
| 6 | var isLeadingSurrogate = require('../helpers/isLeadingSurrogate');
|
|---|
| 7 | var isTrailingSurrogate = require('../helpers/isTrailingSurrogate');
|
|---|
| 8 |
|
|---|
| 9 | var $TypeError = require('es-errors/type');
|
|---|
| 10 |
|
|---|
| 11 | var $charCodeAt = require('call-bound')('String.prototype.charCodeAt');
|
|---|
| 12 |
|
|---|
| 13 | // https://262.ecma-international.org/6.0/#sec-advancestringindex
|
|---|
| 14 |
|
|---|
| 15 | module.exports = function AdvanceStringIndex(S, index, unicode) {
|
|---|
| 16 | if (typeof S !== 'string') {
|
|---|
| 17 | throw new $TypeError('Assertion failed: `S` must be a String');
|
|---|
| 18 | }
|
|---|
| 19 | if (!isInteger(index) || index < 0 || index > MAX_SAFE_INTEGER) {
|
|---|
| 20 | throw new $TypeError('Assertion failed: `length` must be an integer >= 0 and <= 2**53');
|
|---|
| 21 | }
|
|---|
| 22 | if (typeof unicode !== 'boolean') {
|
|---|
| 23 | throw new $TypeError('Assertion failed: `unicode` must be a Boolean');
|
|---|
| 24 | }
|
|---|
| 25 | if (!unicode) {
|
|---|
| 26 | return index + 1;
|
|---|
| 27 | }
|
|---|
| 28 | var length = S.length;
|
|---|
| 29 | if ((index + 1) >= length) {
|
|---|
| 30 | return index + 1;
|
|---|
| 31 | }
|
|---|
| 32 |
|
|---|
| 33 | var first = $charCodeAt(S, index);
|
|---|
| 34 | if (!isLeadingSurrogate(first)) {
|
|---|
| 35 | return index + 1;
|
|---|
| 36 | }
|
|---|
| 37 |
|
|---|
| 38 | var second = $charCodeAt(S, index + 1);
|
|---|
| 39 | if (!isTrailingSurrogate(second)) {
|
|---|
| 40 | return index + 1;
|
|---|
| 41 | }
|
|---|
| 42 |
|
|---|
| 43 | return index + 2;
|
|---|
| 44 | };
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.