Add a trim function to CPString.

This commit is contained in:
Ross Boucher
2009-07-27 22:41:47 -07:00
parent 028be939f9
commit b50067e39e
+9 -1
View File
@@ -62,7 +62,8 @@ var CPStringRegexSpecialCharacters = [
'/', '.', '*', '+', '?', '|', '$', '^',
'(', ')', '[', ']', '{', '}', '\\'
],
CPStringRegexEscapeExpression = new RegExp("(\\" + CPStringRegexSpecialCharacters.join("|\\") + ")", 'g');
CPStringRegexEscapeExpression = new RegExp("(\\" + CPStringRegexSpecialCharacters.join("|\\") + ")", 'g'),
CPStringRegexTrimWhitespace = new RegExp("(^\\s+|\\s+$)", 'g');
/*!
@class CPString
@@ -421,6 +422,13 @@ var CPStringRegexSpecialCharacters = [
return '' + substring(0, range.location) + replacement + substring(range.location + range.length, self.length);
}
/*!
Returns a new string with leading and trailing whitespace trimmed
*/
- (CPString)stringByTrimmingWhitespace
{
return self.replace(CPStringRegexTrimWhitespace, "");
}
// Identifying and comparing strings