summaryrefslogtreecommitdiff
path: root/framework/Web/Javascripts/extended/string.js
diff options
context:
space:
mode:
authorxue <>2005-12-05 01:00:16 +0000
committerxue <>2005-12-05 01:00:16 +0000
commitccf76e430b7703db028966a845a966f50956f490 (patch)
tree9762b746f8b7d432dbe5e5cb8f38f90007e0e1b5 /framework/Web/Javascripts/extended/string.js
parent418baf36d477bcbdd6fb4eaf4037ea6a2d93f21c (diff)
Diffstat (limited to 'framework/Web/Javascripts/extended/string.js')
-rw-r--r--framework/Web/Javascripts/extended/string.js37
1 files changed, 37 insertions, 0 deletions
diff --git a/framework/Web/Javascripts/extended/string.js b/framework/Web/Javascripts/extended/string.js
new file mode 100644
index 00000000..f79072fb
--- /dev/null
+++ b/framework/Web/Javascripts/extended/string.js
@@ -0,0 +1,37 @@
+Object.extend(String.prototype, {
+ pad : function(side, len, chr) {
+ if (!chr) chr = ' ';
+ var s = this;
+ var left = side.toLowerCase()=='left';
+ while (s.length<len) s = left? chr + s : s + chr;
+ return s;
+ },
+
+ padLeft : function(len, chr) {
+ return this.pad('left',len,chr);
+ },
+
+ padRight : function(len, chr) {
+ return this.pad('right',len,chr);
+ },
+
+ zerofill : function(len) {
+ var s = this;
+ var ix = /^[+-]/.test(s) ? 1 : 0;
+ while (s.length<len) s = s.insert(ix, '0');
+ return s;
+ },
+
+ trim : function() {
+ return this.replace(/^\s+|\s+$/g,'');
+ },
+
+ trimLeft : function() {
+ return this.replace(/^\s+/,'');
+ },
+
+ trimRight : function() {
+ return this.replace(/\s+$/,'');
+ }
+
+});