Subversion Repositories Applications.papyrus

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1318 alexandre_ 1
/*
2
	Copyright (c) 2004-2006, The Dojo Foundation
3
	All Rights Reserved.
4
 
5
	Licensed under the Academic Free License version 2.1 or above OR the
6
	modified BSD license. For more information on Dojo licensing, see:
7
 
8
		http://dojotoolkit.org/community/licensing.shtml
9
*/
10
 
1422 alexandre_ 11
 
12
 
1318 alexandre_ 13
dojo.provide("dojo.string.common");
14
dojo.string.trim = function (str, wh) {
15
	if (!str.replace) {
16
		return str;
17
	}
18
	if (!str.length) {
19
		return str;
20
	}
21
	var re = (wh > 0) ? (/^\s+/) : (wh < 0) ? (/\s+$/) : (/^\s+|\s+$/g);
22
	return str.replace(re, "");
23
};
24
dojo.string.trimStart = function (str) {
25
	return dojo.string.trim(str, 1);
26
};
27
dojo.string.trimEnd = function (str) {
28
	return dojo.string.trim(str, -1);
29
};
30
dojo.string.repeat = function (str, count, separator) {
31
	var out = "";
32
	for (var i = 0; i < count; i++) {
33
		out += str;
34
		if (separator && i < count - 1) {
35
			out += separator;
36
		}
37
	}
38
	return out;
39
};
40
dojo.string.pad = function (str, len, c, dir) {
41
	var out = String(str);
42
	if (!c) {
43
		c = "0";
44
	}
45
	if (!dir) {
46
		dir = 1;
47
	}
48
	while (out.length < len) {
49
		if (dir > 0) {
50
			out = c + out;
51
		} else {
52
			out += c;
53
		}
54
	}
55
	return out;
56
};
57
dojo.string.padLeft = function (str, len, c) {
58
	return dojo.string.pad(str, len, c, 1);
59
};
60
dojo.string.padRight = function (str, len, c) {
61
	return dojo.string.pad(str, len, c, -1);
62
};
63