summaryrefslogtreecommitdiff
path: root/js/string.js
diff options
context:
space:
mode:
authorPatrick Seeger <pseeger@ccwn.org>2012-05-20 16:58:26 +0200
committerPatrick Seeger <pseeger@ccwn.org>2012-05-20 16:58:26 +0200
commit4f959ffc80e64dc9ee8383826a546723d97305d9 (patch)
tree3a0704c0e3a9f44746739ccffa0d64acc5ab172d /js/string.js
parentacec2b5dc35302147f9a9c73d837dce2f3f9958e (diff)
parent9aad228e1af661b9b39df83700d27e71697dc66f (diff)
Merge branch 'master' of ssh://proxy.ccwn.org:9044/home/ccwn/git-repos/admin.astaf.de
Diffstat (limited to 'js/string.js')
-rw-r--r--js/string.js24
1 files changed, 24 insertions, 0 deletions
diff --git a/js/string.js b/js/string.js
new file mode 100644
index 0000000..fa25527
--- /dev/null
+++ b/js/string.js
@@ -0,0 +1,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; \ No newline at end of file