-
Notifications
You must be signed in to change notification settings - Fork 2
/
tagExplodr.js
63 lines (52 loc) · 1.3 KB
/
tagExplodr.js
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
function tagsExplode(tag_string) {
var tag,
tags,
new_string;
//
// run the tag string from the input through a function to replace commas and whitespace in double quotes
//
new_string = tag_string.replace(/"(.*?)"/g, function(str, p1) {
//
// convert the whitespace and commas into something we can replace easily later
//
p1 = p1.replace(/(,)/g, function(str, p1) {
p1 = '{COMMA}';
return p1;
});
p1 = p1.replace(/(\s+)/g, function(str, p1) {
p1 = '{WHITESPACE' + p1.charCodeAt(0) + '}';
return p1;
});
return p1;
});
//
// split the new string based on comma, if one exists, else whitespace
//
if (new_string.indexOf(',') > -1) {
tags = new_string.split(/,/);
}
else {
tags = new_string.split(/\s+/);
}
//
// replace the whitespace and comma codes converted, with actual whitespace and commas
//
for (tag in tags) {
tags[tag] = tags[tag].replace(/\{WHITESPACE([0-9]+)\}/g, function(str, p1) {
p1 = String.fromCharCode(p1);
return p1;
});
tags[tag] = tags[tag].replace(/\{COMMA\}/g, function(str, p1) {
p1 = ',';
return p1;
});
}
Y.Array.each(tags, function(tag, index) {
tag = Y.Lang.trim(tag);
tags[index] = tag;
});
tags = Y.Array.filter(tags, function(tag, index) {
return tag.length > 0;
});
return tags;
}