@@ -18,13 +18,13 @@ namespace ClientDependency.Core.CompositeFiles
18
18
{
19
19
public sealed class CssMinifier
20
20
{
21
- const int EOF = - 1 ;
21
+ private const int Eof = - 1 ;
22
22
23
- TextReader tr ;
24
- StringBuilder sb ;
25
- int theA ;
26
- int theB ;
27
- int theLookahead = EOF ;
23
+ private TextReader _tr ;
24
+ private StringBuilder _sb ;
25
+ int _theA ;
26
+ int _theB ;
27
+ int _theLookahead = Eof ;
28
28
29
29
30
30
/// <summary>
@@ -34,61 +34,61 @@ public sealed class CssMinifier
34
34
/// <returns></returns>
35
35
public string Minify ( TextReader reader )
36
36
{
37
- sb = new StringBuilder ( ) ;
38
- tr = reader ;
39
- theA = '\n ' ;
40
- theB = 0 ;
41
- theLookahead = EOF ;
42
- cssmin ( ) ;
43
- return sb . ToString ( ) ;
37
+ _sb = new StringBuilder ( ) ;
38
+ _tr = reader ;
39
+ _theA = '\n ' ;
40
+ _theB = 0 ;
41
+ _theLookahead = Eof ;
42
+ ExecuteCssMin ( ) ;
43
+ return _sb . ToString ( ) ;
44
44
}
45
45
46
46
/// <summary>
47
47
/// Excute the actual minify
48
48
/// </summary>
49
- void cssmin ( )
49
+ private void ExecuteCssMin ( )
50
50
{
51
- action ( 3 ) ;
52
- while ( theA != EOF )
51
+ Action ( 3 ) ;
52
+ while ( _theA != Eof )
53
53
{
54
- switch ( theA )
54
+ switch ( _theA )
55
55
{
56
56
case ' ' :
57
57
{
58
- switch ( theB )
58
+ switch ( _theB )
59
59
{
60
60
case ' ' : //body.Replace(" ", String.Empty);
61
61
case '{' : //body = body.Replace(" {", "{");
62
62
case ':' : //body = body.Replace(" {", "{");
63
63
case '\n ' : //body = body.Replace(" \n", "\n");
64
64
case '\r ' : //body = body.Replace(" \r", "\r");
65
65
case '\t ' : //body = body.Replace(" \t", "\t");
66
- action ( 2 ) ;
66
+ Action ( 2 ) ;
67
67
break ;
68
68
default :
69
- action ( 1 ) ;
69
+ Action ( 1 ) ;
70
70
break ;
71
71
}
72
72
break ;
73
- }
73
+ }
74
74
case '\t ' : //body = body.Replace("\t", "");
75
75
case '\r ' : //body = body.Replace("\r", "");
76
- action ( 2 ) ;
76
+ Action ( 2 ) ;
77
77
break ;
78
78
case '\n ' : //body = body.Replace("\n", "");
79
- if ( char . IsWhiteSpace ( ( char ) theB ) )
79
+ if ( char . IsWhiteSpace ( ( char ) _theB ) )
80
80
{
81
81
//skip over whitespace
82
- action ( 3 ) ;
82
+ Action ( 3 ) ;
83
83
}
84
84
else
85
85
{
86
86
//convert the line break to a space except when in the beginning
87
87
//TODO: this isn't the best place to put this logic since all puts are done
88
88
// in the action, but i don't see any other way to do this,
89
89
//we could set theA = ' ' and call action(1) ?
90
- if ( sb . Length > 0 ) put ( ' ' ) ;
91
- action ( 2 ) ;
90
+ if ( _sb . Length > 0 ) Put ( ' ' ) ;
91
+ Action ( 2 ) ;
92
92
}
93
93
break ;
94
94
case '}' :
@@ -97,10 +97,10 @@ void cssmin()
97
97
case ',' :
98
98
case ';' :
99
99
//skip over whitespace
100
- action ( char . IsWhiteSpace ( ( char ) theB ) ? 3 : 1 ) ;
100
+ Action ( char . IsWhiteSpace ( ( char ) _theB ) ? 3 : 1 ) ;
101
101
break ;
102
102
default :
103
- action ( 1 ) ;
103
+ Action ( 1 ) ;
104
104
break ;
105
105
}
106
106
}
@@ -110,97 +110,99 @@ 1 Output A. Copy B to A. Get the next B.
110
110
2 Copy B to A. Get the next B. (Delete A).
111
111
3 Get the next B. (Delete B).
112
112
*/
113
- void action ( int d )
113
+
114
+ private void Action ( int d )
114
115
{
115
116
if ( d <= 1 )
116
117
{
117
- put ( theA ) ;
118
+ Put ( _theA ) ;
118
119
}
119
120
if ( d <= 2 )
120
121
{
121
- theA = theB ;
122
- if ( theA == '\' ' || theA == '"' )
122
+ _theA = _theB ;
123
+ if ( _theA == '\' ' || _theA == '"' )
123
124
{
124
125
for ( ; ; )
125
126
{
126
- put ( theA ) ;
127
- theA = get ( ) ;
128
- if ( theA == theB )
127
+ Put ( _theA ) ;
128
+ _theA = Get ( ) ;
129
+ if ( _theA == _theB )
129
130
{
130
131
break ;
131
132
}
132
- if ( theA <= '\n ' )
133
+ if ( _theA <= '\n ' )
133
134
{
134
- throw new FormatException ( string . Format ( "Error: unterminated string literal: {0}\n " , theA ) ) ;
135
+ throw new FormatException ( string . Format ( "Error: unterminated string literal: {0}\n " , _theA ) ) ;
135
136
}
136
- if ( theA == '\\ ' )
137
+ if ( _theA == '\\ ' )
137
138
{
138
- put ( theA ) ;
139
- theA = get ( ) ;
139
+ Put ( _theA ) ;
140
+ _theA = Get ( ) ;
140
141
}
141
142
}
142
143
}
143
144
}
144
145
if ( d <= 3 )
145
146
{
146
- theB = next ( ) ;
147
- if ( theB == '/' && ( theA == '(' || theA == ',' || theA == '=' ||
148
- theA == '[' || theA == '!' || theA == ':' ||
149
- theA == '&' || theA == '|' || theA == '?' ||
150
- theA == '{' || theA == '}' || theA == ';' ||
151
- theA == '\n ' ) )
147
+ _theB = Next ( ) ;
148
+ if ( _theB == '/' && ( _theA == '(' || _theA == ',' || _theA == '=' ||
149
+ _theA == '[' || _theA == '!' || _theA == ':' ||
150
+ _theA == '&' || _theA == '|' || _theA == '?' ||
151
+ _theA == '{' || _theA == '}' || _theA == ';' ||
152
+ _theA == '\n ' ) )
152
153
{
153
- put ( theA ) ;
154
- put ( theB ) ;
154
+ Put ( _theA ) ;
155
+ Put ( _theB ) ;
155
156
for ( ; ; )
156
157
{
157
- theA = get ( ) ;
158
- if ( theA == '/' )
158
+ _theA = Get ( ) ;
159
+ if ( _theA == '/' )
159
160
{
160
161
break ;
161
162
}
162
- else if ( theA == '\\ ' )
163
+ else if ( _theA == '\\ ' )
163
164
{
164
- put ( theA ) ;
165
- theA = get ( ) ;
165
+ Put ( _theA ) ;
166
+ _theA = Get ( ) ;
166
167
}
167
- else if ( theA <= '\n ' )
168
+ else if ( _theA <= '\n ' )
168
169
{
169
- throw new FormatException ( string . Format ( "Error: unterminated Regular Expression literal : {0}.\n " , theA ) ) ;
170
+ throw new FormatException ( string . Format ( "Error: unterminated Regular Expression literal : {0}.\n " , _theA ) ) ;
170
171
}
171
- put ( theA ) ;
172
+ Put ( _theA ) ;
172
173
}
173
- theB = next ( ) ;
174
+ _theB = Next ( ) ;
174
175
}
175
176
}
176
177
}
177
178
/* next -- get the next character, excluding comments. peek() is used to see
178
179
if a '/' is followed by a '*'.
179
180
*/
180
- int next ( )
181
+
182
+ private int Next ( )
181
183
{
182
- int c = get ( ) ;
184
+ int c = Get ( ) ;
183
185
if ( c == '/' )
184
186
{
185
- switch ( peek ( ) )
186
- {
187
+ switch ( Peek ( ) )
188
+ {
187
189
case '*' :
188
190
{
189
- get ( ) ;
191
+ Get ( ) ;
190
192
for ( ; ; )
191
193
{
192
- switch ( get ( ) )
194
+ switch ( Get ( ) )
193
195
{
194
196
case '*' :
195
197
{
196
- if ( peek ( ) == '/' )
198
+ if ( Peek ( ) == '/' )
197
199
{
198
- get ( ) ;
200
+ Get ( ) ;
199
201
return ' ' ;
200
202
}
201
203
break ;
202
204
}
203
- case EOF :
205
+ case Eof :
204
206
{
205
207
throw new FormatException ( "Error: Unterminated comment.\n " ) ;
206
208
}
@@ -217,24 +219,26 @@ int next()
217
219
}
218
220
/* peek -- get the next character without getting it.
219
221
*/
220
- int peek ( )
222
+
223
+ private int Peek ( )
221
224
{
222
- theLookahead = get ( ) ;
223
- return theLookahead ;
225
+ _theLookahead = Get ( ) ;
226
+ return _theLookahead ;
224
227
}
225
228
/* get -- return the next character from stdin. Watch out for lookahead. If
226
229
the character is a control character, translate it to a space or
227
230
linefeed.
228
231
*/
229
- int get ( )
232
+
233
+ private int Get ( )
230
234
{
231
- int c = theLookahead ;
232
- theLookahead = EOF ;
233
- if ( c == EOF )
235
+ int c = _theLookahead ;
236
+ _theLookahead = Eof ;
237
+ if ( c == Eof )
234
238
{
235
- c = tr . Read ( ) ;
239
+ c = _tr . Read ( ) ;
236
240
}
237
- if ( c >= ' ' || c == '\n ' || c == EOF )
241
+ if ( c >= ' ' || c == '\n ' || c == Eof )
238
242
{
239
243
return c ;
240
244
}
@@ -244,9 +248,10 @@ int get()
244
248
}
245
249
return ' ' ;
246
250
}
247
- void put ( int c )
251
+
252
+ private void Put ( int c )
248
253
{
249
- sb . Append ( ( char ) c ) ;
254
+ _sb . Append ( ( char ) c ) ;
250
255
}
251
256
}
252
257
}
0 commit comments