summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTristan Zur <tzur@ccwn.org>2012-05-18 19:00:31 +0200
committerTristan Zur <tzur@ccwn.org>2012-05-18 19:00:31 +0200
commit586e35130d97d2829620e03167797b06d7fe07f2 (patch)
treebd396b96a556542e43d2f4ec6b513c7e5aa7dd09
parente657fe8d8c848ad5f24ff46ee4f2438e116468fd (diff)
Javascript String Funktionalität hinzugefügt
-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