blob: 8ab05355ed97751f298607f6d58caf378f9e6766 [file] [log] [blame]
Leo Repp58b9f112021-11-22 11:57:47 +01001'use strict';
2
3var GetIntrinsic = require('get-intrinsic');
4var callBound = require('call-bind/callBound');
5
6var $TypeError = GetIntrinsic('%TypeError%');
7
8var IsInteger = require('./IsInteger');
9var Type = require('./Type');
10
11var $charAt = callBound('String.prototype.charAt');
12
13// https://262.ecma-international.org/6.0/#sec-splitmatch
14
15module.exports = function SplitMatch(S, q, R) {
16 if (Type(S) !== 'String') {
17 throw new $TypeError('Assertion failed: `S` must be a String');
18 }
19 if (!IsInteger(q)) {
20 throw new $TypeError('Assertion failed: `q` must be an integer');
21 }
22 if (Type(R) !== 'String') {
23 throw new $TypeError('Assertion failed: `R` must be a String');
24 }
25 var r = R.length;
26 var s = S.length;
27 if (q + r > s) {
28 return false;
29 }
30
31 for (var i = 0; i < r; i += 1) {
32 if ($charAt(S, q + i) !== $charAt(R, i)) {
33 return false;
34 }
35 }
36
37 return q + r;
38};