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
 
11
dojo.provide("dojo.string.common");
12
dojo.string.trim = function (str, wh) {
13
	if (!str.replace) {
14
		return str;
15
	}
16
	if (!str.length) {
17
		return str;
18
	}
19
	var re = (wh > 0) ? (/^\s+/) : (wh < 0) ? (/\s+$/) : (/^\s+|\s+$/g);
20
	return str.replace(re, "");
21
};
22
dojo.string.trimStart = function (str) {
23
	return dojo.string.trim(str, 1);
24
};
25
dojo.string.trimEnd = function (str) {
26
	return dojo.string.trim(str, -1);
27
};
28
dojo.string.repeat = function (str, count, separator) {
29
	var out = "";
30
	for (var i = 0; i < count; i++) {
31
		out += str;
32
		if (separator && i < count - 1) {
33
			out += separator;
34
		}
35
	}
36
	return out;
37
};
38
dojo.string.pad = function (str, len, c, dir) {
39
	var out = String(str);
40
	if (!c) {
41
		c = "0";
42
	}
43
	if (!dir) {
44
		dir = 1;
45
	}
46
	while (out.length < len) {
47
		if (dir > 0) {
48
			out = c + out;
49
		} else {
50
			out += c;
51
		}
52
	}
53
	return out;
54
};
55
dojo.string.padLeft = function (str, len, c) {
56
	return dojo.string.pad(str, len, c, 1);
57
};
58
dojo.string.padRight = function (str, len, c) {
59
	return dojo.string.pad(str, len, c, -1);
60
};
61