-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathformatedString.js
More file actions
77 lines (69 loc) · 1.6 KB
/
formatedString.js
File metadata and controls
77 lines (69 loc) · 1.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/**
* formatedString - String Formatierung
*
* @version 1.0
*
* @author m13p4
* @copyright Pavel Meliantchenkov
*/
var formatedString = function(string)
{
var orgString = string;
var options = {};
var encode = function(txt)
{
return txt.replace(/[\x26\x0A\x3c\x3e\x22\x27]/g, function(txt)
{
return "&#" + txt.charCodeAt(0) + ";";
});
},
parse = function(encodeString)
{
var lastPos = 0, formString = "";
for(var pos in options)
{
if(!!encodeString)
{
formString += encode(orgString.substr(lastPos, (pos - lastPos)));
}
else
{
formString += orgString.substr(lastPos, (pos - lastPos));
}
for(var i = 0; i < options[pos].length; i++)
{
formString += options[pos][i];
}
lastPos = pos;
}
if(!!encodeString)
{
formString += encode(orgString.substr(lastPos));
}
else
{
formString += orgString.substr(lastPos);
}
return formString;
};
this.addOpt = function(pos, opt)
{
if(!options[pos])
{
options[pos] = [];
}
options[pos].push(opt);
};
this.getOpts = function()
{
return options;
};
this.getOrgText = function()
{
return orgString;
};
this.getFormText = function(encodeString)
{
return parse(encodeString);
};
};