@@ -29,9 +29,9 @@ public static String mk(String str, String regex, String replacement) {
29
29
StringBuffer sb = new StringBuffer ();
30
30
do {
31
31
if (matcher .group (10 ) != null ) {
32
- matcher .appendReplacement (sb , "$10 $11 " );
32
+ matcher .appendReplacement (sb , "$11 $12 " );
33
33
} else if (matcher .group (13 ) != null ) {
34
- matcher .appendReplacement (sb , "$13 $14 " );
34
+ matcher .appendReplacement (sb , "$14 $15 " );
35
35
} else {
36
36
matcher .appendReplacement (sb , replacement );
37
37
}
@@ -43,34 +43,78 @@ public static String mk(String str, String regex, String replacement) {
43
43
return str ;
44
44
}
45
45
public static String regexCompress (String str ) {
46
+ str = str .replaceAll ("(\r ([^\n ]))|(([^\r ])\n )" , "$4\r \n $2" ); // fix line terminators
47
+ boolean ignoreCSS = false ;
48
+ String cssCodes = null ;
49
+ int idx1 = str .indexOf ("$WTC$$.registerCSS" );
50
+ int idx2 = -1 ;
51
+ String specialFunKey = "@324@();\r \n " ;
52
+ if (idx1 != -1 ) {
53
+ idx2 = str .indexOf ("\" );\r \n " , idx1 );
54
+ if (idx2 != -1 ) {
55
+ ignoreCSS = true ;
56
+ cssCodes = str .substring (idx1 , idx2 + 5 );
57
+ str = str .substring (0 , idx1 ) + specialFunKey + str .substring (idx2 + 5 );
58
+ }
59
+ }
46
60
String regEx = "('[^\\ n\\ r]*[^\\ \\ ]')|" + // 1:1
47
- "(\" [^\\ n\\ r] *[^\\ \\ ]\" )|" + // 1:2
48
- "(\\ /\\ /[^\\ n\\ r]*$ )|" + // 1:3 // line comments
49
- "(\\ /\\ *[^*]*\\ *+([^\\ /][^*]*\\ *+)*\\ /)|" + // 2:4,5 // block comments
50
- "(\\ s+(\\ /[^\\ /\\ n\\ r\\ *][^\\ /\\ n\\ r]*\\ /[gim]*))|" + // 2:6,7 // regular expression
51
- "([^\\ w\\ x24\\ /'\" *)\\ ?:]\\ /[^\\ /\\ n\\ r\\ *][^\\ /\\ n\\ r]*\\ /[gim]*)" ; // 1:8 // regular expression
61
+ "(\" ( [^\\ n\\ r\\ \" ]| \\ \\ \\ \" ) *[^\\ \\ ]\" )|" + // 1:3
62
+ "(\\ /\\ /[^\\ n\\ r]*[ \\ n \\ r] )|" + // 1:4
63
+ "(\\ /\\ *[^*]*\\ *+([^\\ /][^*]*\\ *+)*\\ /)|" + // 2:5,6
64
+ "(\\ s+(\\ /[^\\ /\\ n\\ r\\ *][^\\ /\\ n\\ r]*\\ /[gim]*))|" + // 2:7,8
65
+ "([^\\ w\\ x24\\ /'\" *)\\ ?:]\\ /[^\\ /\\ n\\ r\\ *][^\\ /\\ n\\ r]*\\ /[gim]*)" ; // 1:9
52
66
//str = str.replaceAll(regEx, "$1$2$7$8");
53
67
str = mk (str , regEx +
54
- "|((\\ b|\\ x24)\\ s+(\\ b|\\ x24))|" + // 3:9, 10,11
55
- "(([+\\ -])\\ s+([+\\ -]))|" + // 3:12, 13,14
68
+ "|((\\ b|\\ x24)\\ s+(\\ b|\\ x24))|" + // 3:10,11,12
69
+ "(([+\\ -])\\ s+([+\\ -]))|" + // 3:13,14,15
56
70
"(\\ s+)" ,
57
- "$1$2$7$8" );
71
+ "$1$2$8$9" );
72
+ if (ignoreCSS ) {
73
+ int idx = str .indexOf (specialFunKey );
74
+ if (idx != -1 ) {
75
+ str = str .substring (0 , idx ) + cssCodes + str .substring (idx + specialFunKey .length ());
76
+ } else {
77
+ System .err .println ("Error! Fail to ignore CSS codes!" );
78
+ }
79
+ }
58
80
return str ;
59
81
}
60
82
public static String regexCompress2 (String str ) {
83
+ str = str .replaceAll ("(\r ([^\n ]))|(([^\r ])\n )" , "$4\r \n $2" ); // fix line terminators
84
+ boolean ignoreCSS = false ;
85
+ String cssCodes = null ;
86
+ int idx1 = str .indexOf ("$WTC$$.registerCSS" );
87
+ int idx2 = -1 ;
88
+ String specialFunKey = "@324@();\r \n " ;
89
+ if (idx1 != -1 ) {
90
+ idx2 = str .indexOf ("\" );\r \n " , idx1 );
91
+ if (idx2 != -1 ) {
92
+ ignoreCSS = true ;
93
+ cssCodes = str .substring (idx1 , idx2 + 5 );
94
+ str = str .substring (0 , idx1 ) + specialFunKey + str .substring (idx2 + 5 );
95
+ }
96
+ }
61
97
String whiteSpace = "[ \\ f\\ t\\ v]" ;
62
98
String regEx = "('[^\\ n\\ r]*[^\\ \\ ]')|" + // 1:1
63
- "(\" [^\\ n\\ r] *[^\\ \\ ]\" )|" + // 1:2
64
- "(\\ /\\ /[^\\ n\\ r]*$ )|" + // 1:3 // line comments
65
- "(\\ /\\ *[^*]*\\ *+([^\\ /][^*]*\\ *+)*\\ /)|" + // 2:4,5 // block comments
66
- "(" + whiteSpace + "+(\\ /[^\\ /\\ n\\ r\\ *][^\\ /\\ n\\ r]*\\ /[gim]*))|" + // 2:6,7 // regular expression
67
- "([^\\ w\\ x24\\ /'\" *)\\ ?:]\\ /[^\\ /\\ n\\ r\\ *][^\\ /\\ n\\ r]*\\ /[gim]*)" ; // 1:8 // regular expression
99
+ "(\" ( [^\\ n\\ r\\ \" ]| \\ \\ \\ \" ) *[^\\ \\ ]\" )|" + // 2:2,3
100
+ "(\\ /\\ /[^\\ n\\ r]*[ \\ n \\ r] )|" + // 1:4 // line comments
101
+ "(\\ /\\ *[^*]*\\ *+([^\\ /][^*]*\\ *+)*\\ /)|" + // 2:5,6 // block comments
102
+ "(" + whiteSpace + "+(\\ /[^\\ /\\ n\\ r\\ *][^\\ /\\ n\\ r]*\\ /[gim]*))|" + // 2:7,8 // regular expression
103
+ "([^\\ w\\ x24\\ /'\" *)\\ ?:]\\ /[^\\ /\\ n\\ r\\ *][^\\ /\\ n\\ r]*\\ /[gim]*)" ; // 1:9 // regular expression
68
104
//str = str.replaceAll(regEx, "$1$2$7$8");
69
105
str = mk (str , regEx +
70
- "|((\\ b|\\ x24)" + whiteSpace + "+(\\ b|\\ x24))|" + // 3:9, 10,11
71
- "(([+\\ -])" + whiteSpace + "+([+\\ -]))|" + // 3:12, 13,14
106
+ "|((\\ b|\\ x24)" + whiteSpace + "+(\\ b|\\ x24))|" + // 3:10,11,12
107
+ "(([+\\ -])" + whiteSpace + "+([+\\ -]))|" + // 3:13,14,15
72
108
"(" + whiteSpace + "+)" ,
73
- "$1$2$7$8" );
109
+ "$1$2$8$9" );
110
+ if (ignoreCSS ) {
111
+ int idx = str .indexOf (specialFunKey );
112
+ if (idx != -1 ) {
113
+ str = str .substring (0 , idx ) + cssCodes + str .substring (idx + specialFunKey .length ());
114
+ } else {
115
+ System .err .println ("Error! Fail to ignore CSS codes!" );
116
+ }
117
+ }
74
118
return str ;
75
119
}
76
120
0 commit comments