blob: fa25527db5c55e8bcd1ddfb49d0627a7a17f8c61 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
/**
* Strips all leading and ending whitespaces.
* @returns the trimmed string.
*/
function trim() {
var str = this.replace(/^\s+/, "");
var ws = /\s/;
var i = str.length;
while (ws.test(str.charAt(--i)));
return str.slice(0, i + 1);
}
/**
* Checks whether a string is empty or not.
* The string is trimmed before checking if the length is 0.
* @return <code>true</code> if the trimmed string has a length of 0.
*/
function isEmpty() {
var testString = this.trim();
return 0 == testString.length;
}
String.prototype.trim = trim;
String.prototype.isEmpty = isEmpty;
|