mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-06 17:47:49 +00:00
Optimize trim.
This commit is contained in:
24
lodash.js
24
lodash.js
@@ -71,9 +71,6 @@
|
||||
/** Used to detect hexadecimal string values */
|
||||
var reHexPrefix = /^0[xX]/;
|
||||
|
||||
/** Used to match leading whitespace in strings */
|
||||
var reLeadingWhitespace = RegExp('^[' + whitespace + ']+');
|
||||
|
||||
/** Used to ensure capturing order of template delimiters */
|
||||
var reNoMatch = /($^)/;
|
||||
|
||||
@@ -443,6 +440,23 @@
|
||||
return typeof value.toString != 'function' && typeof (value + '') == 'string';
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks the given string to determine if the character at the specified
|
||||
* index is whitespace.
|
||||
*
|
||||
* @private
|
||||
* @param {string} string The string to inspect.
|
||||
* @param {number} index The character index.
|
||||
* @returns {boolean} Returns `true` if specifed character is whitespace, else `false`.
|
||||
*/
|
||||
function isWhitespaceAt(string, index) {
|
||||
var c = string.charCodeAt(index);
|
||||
return (
|
||||
(c <= 160 && (c >= 9 && c <= 13) || c == 32 || c == 160) || c == 5760 || c == 6158 ||
|
||||
(c >= 8192 && (c <= 8202 || c == 8232 || c == 8233 || c == 8239 || c == 8287 || c == 12288 || c == 65279))
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Releases the given array back to the array pool.
|
||||
*
|
||||
@@ -1935,8 +1949,8 @@
|
||||
return '';
|
||||
}
|
||||
string = String(string);
|
||||
while (whitespace.indexOf(string.charAt(++start)) > -1) { }
|
||||
while (whitespace.indexOf(string.charAt(--end)) > -1) { }
|
||||
while (++start < end && isWhitespaceAt(string, start)) { }
|
||||
while (end-- && isWhitespaceAt(string, end)) { }
|
||||
return string.slice(start, end + 1);
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user