| | |
| | | 'use strict'; |
| | | var apply = require('../internals/function-apply'); |
| | | var call = require('../internals/function-call'); |
| | | var uncurryThis = require('../internals/function-uncurry-this'); |
| | | var fixRegExpWellKnownSymbolLogic = require('../internals/fix-regexp-well-known-symbol-logic'); |
| | | var isRegExp = require('../internals/is-regexp'); |
| | | var anObject = require('../internals/an-object'); |
| | |
| | | var toLength = require('../internals/to-length'); |
| | | var toString = require('../internals/to-string'); |
| | | var getMethod = require('../internals/get-method'); |
| | | var arraySlice = require('../internals/array-slice-simple'); |
| | | var callRegExpExec = require('../internals/regexp-exec-abstract'); |
| | | var regexpExec = require('../internals/regexp-exec'); |
| | | var stickyHelpers = require('../internals/regexp-sticky-helpers'); |
| | | var fails = require('../internals/fails'); |
| | | |
| | | var UNSUPPORTED_Y = stickyHelpers.UNSUPPORTED_Y; |
| | | var arrayPush = [].push; |
| | | var min = Math.min; |
| | | var MAX_UINT32 = 0xFFFFFFFF; |
| | | var min = Math.min; |
| | | var $push = [].push; |
| | | var exec = uncurryThis(/./.exec); |
| | | var push = uncurryThis($push); |
| | | var stringSlice = uncurryThis(''.slice); |
| | | |
| | | // Chrome 51 has a buggy "split" implementation when RegExp#exec !== nativeExec |
| | | // Weex JS has frozen built-in prototypes, so use try / catch wrapper |
| | |
| | | if (separator === undefined) return [string]; |
| | | // If `separator` is not a regex, use native split |
| | | if (!isRegExp(separator)) { |
| | | return nativeSplit.call(string, separator, lim); |
| | | return call(nativeSplit, string, separator, lim); |
| | | } |
| | | var output = []; |
| | | var flags = (separator.ignoreCase ? 'i' : '') + |
| | |
| | | // Make `global` and avoid `lastIndex` issues by working with a copy |
| | | var separatorCopy = new RegExp(separator.source, flags + 'g'); |
| | | var match, lastIndex, lastLength; |
| | | while (match = regexpExec.call(separatorCopy, string)) { |
| | | while (match = call(regexpExec, separatorCopy, string)) { |
| | | lastIndex = separatorCopy.lastIndex; |
| | | if (lastIndex > lastLastIndex) { |
| | | output.push(string.slice(lastLastIndex, match.index)); |
| | | if (match.length > 1 && match.index < string.length) arrayPush.apply(output, match.slice(1)); |
| | | push(output, stringSlice(string, lastLastIndex, match.index)); |
| | | if (match.length > 1 && match.index < string.length) apply($push, output, arraySlice(match, 1)); |
| | | lastLength = match[0].length; |
| | | lastLastIndex = lastIndex; |
| | | if (output.length >= lim) break; |
| | |
| | | if (separatorCopy.lastIndex === match.index) separatorCopy.lastIndex++; // Avoid an infinite loop |
| | | } |
| | | if (lastLastIndex === string.length) { |
| | | if (lastLength || !separatorCopy.test('')) output.push(''); |
| | | } else output.push(string.slice(lastLastIndex)); |
| | | return output.length > lim ? output.slice(0, lim) : output; |
| | | if (lastLength || !exec(separatorCopy, '')) push(output, ''); |
| | | } else push(output, stringSlice(string, lastLastIndex)); |
| | | return output.length > lim ? arraySlice(output, 0, lim) : output; |
| | | }; |
| | | // Chakra, V8 |
| | | } else if ('0'.split(undefined, 0).length) { |
| | | internalSplit = function (separator, limit) { |
| | | return separator === undefined && limit === 0 ? [] : nativeSplit.call(this, separator, limit); |
| | | return separator === undefined && limit === 0 ? [] : call(nativeSplit, this, separator, limit); |
| | | }; |
| | | } else internalSplit = nativeSplit; |
| | | |
| | |
| | | var O = requireObjectCoercible(this); |
| | | var splitter = separator == undefined ? undefined : getMethod(separator, SPLIT); |
| | | return splitter |
| | | ? splitter.call(separator, O, limit) |
| | | : internalSplit.call(toString(O), separator, limit); |
| | | ? call(splitter, separator, O, limit) |
| | | : call(internalSplit, toString(O), separator, limit); |
| | | }, |
| | | // `RegExp.prototype[@@split]` method |
| | | // https://tc39.es/ecma262/#sec-regexp.prototype-@@split |
| | |
| | | var A = []; |
| | | while (q < S.length) { |
| | | splitter.lastIndex = UNSUPPORTED_Y ? 0 : q; |
| | | var z = callRegExpExec(splitter, UNSUPPORTED_Y ? S.slice(q) : S); |
| | | var z = callRegExpExec(splitter, UNSUPPORTED_Y ? stringSlice(S, q) : S); |
| | | var e; |
| | | if ( |
| | | z === null || |
| | |
| | | ) { |
| | | q = advanceStringIndex(S, q, unicodeMatching); |
| | | } else { |
| | | A.push(S.slice(p, q)); |
| | | push(A, stringSlice(S, p, q)); |
| | | if (A.length === lim) return A; |
| | | for (var i = 1; i <= z.length - 1; i++) { |
| | | A.push(z[i]); |
| | | push(A, z[i]); |
| | | if (A.length === lim) return A; |
| | | } |
| | | q = p = e; |
| | | } |
| | | } |
| | | A.push(S.slice(p)); |
| | | push(A, stringSlice(S, p)); |
| | | return A; |
| | | } |
| | | ]; |