forked from cfexpert/ColdFusion-ElasticSearch-Client
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOutputUtils.cfc
More file actions
53 lines (46 loc) · 2.2 KB
/
OutputUtils.cfc
File metadata and controls
53 lines (46 loc) · 2.2 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
component{
public OutputUtils function init(){
return this;
}
public string function compress(required string string, numeric level="3"){
var stringToCompress = ARGUMENTS.string;
var compressionLevel = ARGUMENTS.level;
//TRIM OFF ANY EXTRA SPACES FROM STRING TO BE FILTERED
stringToCompress = trim(stringToCompress);
// RUN FILTER BASED ON SPECIFIED COMPRESSION LEVELs
switch(compressionLevel){
case "4":
stringToCompress = reReplace(stringToCompress, "[[:space:]]{2,}", " ", "all");
stringToCompress = replace(stringToCompress, "> <", "><", "all");
stringToCompress = reReplace(stringToCompress, "<!--[^>]+>", "", "all");
break;
case "3":
stringToCompress = reReplace(stringToCompress, "[[:space:]]{2,}", " ", "all");
stringToCompress = replace(stringToCompress, "> <", "><", "all");
stringToCompress = reReplace(stringToCompress, "<!--[^>]+>", "", "all");
stringToCompress = replace(stringToCompress, '" : "', '":"', "ALL");
stringToCompress = replace(stringToCompress, '} , {', '},{', "ALL");
stringToCompress = replace(stringToCompress, ', "', ',"', "ALL");
stringToCompress = replace(stringToCompress, '} }', '}}', "ALL");
stringToCompress = replace(stringToCompress, '} ]', '}]', "ALL");
stringToCompress = replace(stringToCompress, '[ {', '[{', "ALL");
stringToCompress = replace(stringToCompress, ' }', '}', "ALL");
stringToCompress = replace(stringToCompress, '{ ', '{', "ALL");
stringToCompress = replace(stringToCompress, ' :', ':', "ALL");
stringToCompress = replace(stringToCompress, ': ', ':', "ALL");
stringToCompress = replace(stringToCompress, ', ', ',', "ALL");
stringToCompress = replace(stringToCompress, ' ,', ',', "ALL");
break;
case "2":
stringToCompress = reReplace(stringToCompress, "[[:space:]]{2,}", chr( 13 ), "all");
break;
default:
stringToCompress = reReplace(stringToCompress, "(" & chr( 10 ) & "|" & chr( 13 ) & ")+[[:space:]]{2,}", chr( 13 ), "all");
break;
}
stringToCompress = Replace(stringToCompress, "\r", "", "all");
stringToCompress = Replace(stringToCompress, "\n", "", "all");
stringToCompress = Replace(stringToCompress, "\t", "", "all");
return stringToCompress;
}
}