JezK
Edit File: page-split_js.ri
U:RDoc::TopLevel[ i I"lib/split.js:ETcRDoc::Parser::Simpleo:RDoc::Markup::Document:@parts[o:RDoc::Markup::Verbatim;[ I"! ;TI" Cross-Browser Split 1.1.1 ;TI"? Copyright 2007-2012 Steven Levithan <stevenlevithan.com> ;TI"& Available under the MIT License ;TI"? ECMAScript compliant, uniform cross-browser split method ;T:@format0o:RDoc::Markup::Paragraph;[I"/**;To; ;[I"a Splits a string into an array of strings using a regex or string separator. Matches of the ;TI"g separator are not included in the result array. However, if `separator` is a regex that contains ;TI"e capturing groups, backreferences are spliced into the result each time `separator` is matched. ;TI"b Fixes browser bugs compared to the native `String.prototype.split` and can be used reliably ;TI" cross-browser. ;TI"+ @param {String} str String to split. ;TI"Y @param {RegExp|String} separator Regex or string to use for separating the string. ;TI"V @param {Number} [limit] Maximum number of items to include in the result array. ;TI", @returns {Array} Array of substrings. ;TI" @example ;TI" ;TI" // Basic use ;TI" split('a b c d', ' '); ;TI"! // -> ['a', 'b', 'c', 'd'] ;TI" ;TI" // With limit ;TI" split('a b c d', ' ', 2); ;TI" // -> ['a', 'b'] ;TI" ;TI"( // Backreferences in result array ;TI"2 split('..word1 word2..', /([a-z]+)(\d+)/i); ;TI"8 // -> ['..', 'word', '1', ' ', 'word', '2', '..'] ;TI"/ ;T; 0o;;[I"var split;;To:RDoc::Markup::BlankLine o;;[I"J// Avoid running twice; that would break the `nativeSplit` reference ;TI"(split = split || function (undef) {;T@1o; ;[TI"/var nativeSplit = String.prototype.split, ;TI"e compliantExecNpcg = /()??/.exec("")[1] === undef, // NPCG: nonparticipating capturing group ;TI" self; ;TI" ;TI"/self = function (str, separator, limit) { ;TI"= // If `separator` is not a regex, use `nativeSplit` ;TI"P if (Object.prototype.toString.call(separator) !== "[object RegExp]") { ;TI"= return nativeSplit.call(str, separator, limit); ;TI" } ;TI" var output = [], ;TI"9 flags = (separator.ignoreCase ? "i" : "") + ;TI"9 (separator.multiline ? "m" : "") + ;TI"M (separator.extended ? "x" : "") + // Proposed for ES6 ;TI"F (separator.sticky ? "y" : ""), // Firefox 3+ ;TI" lastLastIndex = 0, ;TI"R // Make `global` and avoid `lastIndex` issues by working with a copy ;TI"D separator = new RegExp(separator.source, flags + "g"), ;TI"7 separator2, match, lastIndex, lastLength; ;TI"$ str += ""; // Type-convert ;TI"# if (!compliantExecNpcg) { ;TI"; // Doesn't need flags gy, but they don't hurt ;TI"R separator2 = new RegExp("^" + separator.source + "$(?!\\s)", flags); ;TI" } ;TI". /* Values for `limit`, per the spec: ;TI"< If undefined: 4294967295 // Math.pow(2, 32) - 1 ;TI"& If 0, Infinity, or NaN: 0 ;TI"h If positive number: limit = Math.floor(limit); if (limit > 4294967295) limit -= 4294967296; ;TI"I If negative number: 4294967296 - Math.floor(Math.abs(limit)) ;TI"= If other: Type-convert, then use the above rules ;TI" / ;TI"# limit = limit === undef ? ;TI"/ -1 >>> 0 : // Math.pow(2, 32) - 1 ;TI"- limit >>> 0; // ToUint32(limit) ;TI"/ while (match = separator.exec(str)) { ;TI"D // `separator.lastIndex` is not reliable cross-browser ;TI"8 lastIndex = match.index + match[0].length; ;TI". if (lastIndex > lastLastIndex) { ;TI"E output.push(str.slice(lastLastIndex, match.index)); ;TI"` // Fix browsers whose `exec` methods don't consistently return `undefined` for ;TI"6 // nonparticipating capturing groups ;TI"? if (!compliantExecNpcg && match.length > 1) { ;TI"@ match[0].replace(separator2, function () { ;TI"J for (var i = 1; i < arguments.length - 2; i++) { ;TI"; if (arguments[i] === undef) { ;TI"3 match[i] = undef; ;TI" } ;TI" } ;TI" }); ;TI" } ;TI"E if (match.length > 1 && match.index < str.length) { ;TI"I Array.prototype.push.apply(output, match.slice(1)); ;TI" } ;TI"/ lastLength = match[0].length; ;TI", lastLastIndex = lastIndex; ;TI"/ if (output.length >= limit) { ;TI" break; ;TI" } ;TI" } ;TI"8 if (separator.lastIndex === match.index) { ;TI"B separator.lastIndex++; // Avoid an infinite loop ;TI" } ;TI" } ;TI"- if (lastLastIndex === str.length) { ;TI"6 if (lastLength || !separator.test("")) { ;TI"" output.push(""); ;TI" } ;TI" } else { ;TI"4 output.push(str.slice(lastLastIndex)); ;TI" } ;TI"I return output.length > limit ? output.slice(0, limit) : output; ;TI"}; ;TI" ;TI")if ("\n".split(/\n/).length == 0) { ;TI"@ String.prototype.split = function (separator, limit) { ;TI"2 return self(this, separator, limit); ;TI" }; ;TI"} ;TI" ;TI"return self; ;T; 0o;;[I" }();;T: @file@:0@omit_headings_from_table_of_contents_below0