}
/**
+ * @return {number}
+ */
+String.prototype.lineCount = function()
+{
+ var lineEndings = this.lineEndings();
+ return lineEndings.length;
+}
+
+/**
+ * @return {string}
+ */
+String.prototype.lineAt = function(lineNumber)
+{
+ var lineEndings = this.lineEndings();
+ var lineStart = lineNumber > 0 ? lineEndings[lineNumber - 1] + 1 : 0;
+ var lineEnd = lineEndings[lineNumber];
+ var lineContent = this.substring(lineStart, lineEnd);
+ if (lineContent.length > 0 && lineContent.charAt(lineContent.length - 1) === "\r")
+ lineContent = lineContent.substring(0, lineContent.length - 1);
+ return lineContent;
+}
+
+/**
* @param {string} chars
* @return {string}
*/
}
/**
- * @param {string} name
- * @param {number=} arrayLength
- * @return {boolean}
- */
-String.isArrayIndexPropertyName = function(name, arrayLength)
-{
- // Array index check according to the ES5-15.4.
- var index = name >>> 0;
- return String(index) === name && index !== 0xffffffff && (typeof arrayLength === "undefined" || index < arrayLength);
-}
-
-/**
* @param {number} num
* @param {number} min
* @param {number} max
/**
* Return index of the leftmost element that is equal or greater
* than the specimen object. If there's no such element (i.e. all
- * elements are smaller than the specimen) returns array.length.
+ * elements are smaller than the specimen) returns right bound.
* The function works for sorted array.
+ * When specified, |left| (inclusive) and |right| (exclusive) indices
+ * define the search window.
*
* @param {!T} object
* @param {function(!T,!S):number=} comparator
+ * @param {number=} left
+ * @param {number=} right
* @return {number}
* @this {Array.<!S>}
* @template T,S
*/
- value: function(object, comparator)
+ value: function(object, comparator, left, right)
{
function defaultComparator(a, b)
{
return a < b ? -1 : (a > b ? 1 : 0);
}
comparator = comparator || defaultComparator;
- var l = 0;
- var r = this.length;
+ var l = left || 0;
+ var r = right !== undefined ? right : this.length;
while (l < r) {
var m = (l + r) >> 1;
if (comparator(object, this[m]) > 0)
/**
* Return index of the leftmost element that is greater
* than the specimen object. If there's no such element (i.e. all
- * elements are smaller than the specimen) returns array.length.
+ * elements are smaller or equal to the specimen) returns right bound.
* The function works for sorted array.
+ * When specified, |left| (inclusive) and |right| (exclusive) indices
+ * define the search window.
*
* @param {!T} object
* @param {function(!T,!S):number=} comparator
+ * @param {number=} left
+ * @param {number=} right
* @return {number}
* @this {Array.<!S>}
* @template T,S
*/
- value: function(object, comparator)
+ value: function(object, comparator, left, right)
{
function defaultComparator(a, b)
{
return a < b ? -1 : (a > b ? 1 : 0);
}
comparator = comparator || defaultComparator;
- var l = 0;
- var r = this.length;
+ var l = left || 0;
+ var r = right !== undefined ? right : this.length;
while (l < r) {
var m = (l + r) >> 1;
if (comparator(object, this[m]) >= 0)
var result = [];
var i = 0;
var j = 0;
- while (i < array1.length || j < array2.length) {
- if (i === array1.length) {
- result = result.concat(array2.slice(j));
- j = array2.length;
- } else if (j === array2.length) {
- result = result.concat(array1.slice(i));
- i = array1.length;
- } else {
- var compareValue = comparator(array1[i], array2[j])
- if (compareValue < 0) {
- if (mergeNotIntersect)
- result.push(array1[i]);
- ++i;
- } else if (compareValue > 0) {
- if (mergeNotIntersect)
- result.push(array2[j]);
- ++j;
- } else {
- result.push(array1[i]);
- ++i;
- ++j;
- }
- }
+ while (i < array1.length && j < array2.length) {
+ var compareValue = comparator(array1[i], array2[j]);
+ if (mergeNotIntersect || !compareValue)
+ result.push(compareValue <= 0 ? array1[i] : array2[j]);
+ if (compareValue <= 0)
+ i++;
+ if (compareValue >= 0)
+ j++;
+ }
+ if (mergeNotIntersect) {
+ while (i < array1.length)
+ result.push(array1[i++]);
+ while (j < array2.length)
+ result.push(array2[j++]);
}
return result;
}
* @param {function(?string)=} callback
* @return {?string}
*/
-function loadXHR(url, async, callback)
+function loadXHR(url, async, callback)
{
- function onReadyStateChanged()
+ function onReadyStateChanged()
{
if (xhr.readyState !== XMLHttpRequest.DONE)
return;
return;
}
- callback(null);
+ callback(null);
}
var xhr = new XMLHttpRequest();
xhr.send(null);
if (!async) {
- if (xhr.status === 200)
+ if (xhr.status === 200)
return xhr.responseText;
return null;
}
var baseUrl = location.origin + location.pathname;
baseUrl = baseUrl.substring(0, baseUrl.lastIndexOf("/"));
var sourceURL = baseUrl + "/" + scriptName;
- eval(xhr.responseText + "\n//# sourceURL=" + sourceURL);
+ self.eval(xhr.responseText + "\n//# sourceURL=" + sourceURL);
}
var loadScript = importScript;
this._outgoingCallback();
}
}
+
+/**
+ * @param {*} value
+ */
+function suppressUnused(value)
+{
+}