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:
803 bytes
|
Rev | Line | |
---|
[d565449] | 1 | 'use strict';
|
---|
| 2 |
|
---|
[79a0317] | 3 | var callBound = require('call-bound');
|
---|
[d565449] | 4 |
|
---|
| 5 | var $TypeError = require('es-errors/type');
|
---|
[79a0317] | 6 | var isInteger = require('math-intrinsics/isInteger');
|
---|
[d565449] | 7 |
|
---|
| 8 | var $charAt = callBound('String.prototype.charAt');
|
---|
| 9 |
|
---|
| 10 | // https://262.ecma-international.org/6.0/#sec-splitmatch
|
---|
| 11 |
|
---|
| 12 | module.exports = function SplitMatch(S, q, R) {
|
---|
| 13 | if (typeof S !== 'string') {
|
---|
| 14 | throw new $TypeError('Assertion failed: `S` must be a String');
|
---|
| 15 | }
|
---|
| 16 | if (!isInteger(q)) {
|
---|
| 17 | throw new $TypeError('Assertion failed: `q` must be an integer');
|
---|
| 18 | }
|
---|
| 19 | if (typeof R !== 'string') {
|
---|
| 20 | throw new $TypeError('Assertion failed: `R` must be a String');
|
---|
| 21 | }
|
---|
| 22 | var r = R.length;
|
---|
| 23 | var s = S.length;
|
---|
| 24 | if (q + r > s) {
|
---|
| 25 | return false;
|
---|
| 26 | }
|
---|
| 27 |
|
---|
| 28 | for (var i = 0; i < r; i += 1) {
|
---|
| 29 | if ($charAt(S, q + i) !== $charAt(R, i)) {
|
---|
| 30 | return false;
|
---|
| 31 | }
|
---|
| 32 | }
|
---|
| 33 |
|
---|
| 34 | return q + r;
|
---|
| 35 | };
|
---|
Note:
See
TracBrowser
for help on using the repository browser.