main
Last change
on this file since 79a0317 was 79a0317, checked in by stefan toskovski <stefantoska84@…>, 3 days ago |
F4 Finalna Verzija
|
-
Property mode
set to
100644
|
File size:
1.2 KB
|
Rev | Line | |
---|
[d565449] | 1 | 'use strict';
|
---|
| 2 |
|
---|
[79a0317] | 3 | var isInteger = require('math-intrinsics/isInteger');
|
---|
| 4 | var MAX_SAFE_INTEGER = require('math-intrinsics/constants/maxSafeInteger');
|
---|
| 5 |
|
---|
[d565449] | 6 | var isLeadingSurrogate = require('../helpers/isLeadingSurrogate');
|
---|
| 7 | var isTrailingSurrogate = require('../helpers/isTrailingSurrogate');
|
---|
| 8 |
|
---|
| 9 | var $TypeError = require('es-errors/type');
|
---|
| 10 |
|
---|
[79a0317] | 11 | var $charCodeAt = require('call-bound')('String.prototype.charCodeAt');
|
---|
[d565449] | 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.