r61650 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r61649‎ | r61650 | r61651 >
Date:00:02, 29 January 2010
Author:simetrical
Status:ok
Tags:
Comment:
stylize.php and fix whitespace for JSMin.php

Two spaces were being used for indentation instead of a tab, and for
some reason stylize.php didn't fix that, but repeated
s/^\(\( \)*\) /\1\t/ worked.
Modified paths:
  • /trunk/phase3/includes/JSMin.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/JSMin.php
@@ -46,246 +46,246 @@
4747 */
4848
4949 class JSMin {
50 - const ORD_LF = 10;
51 - const ORD_SPACE = 32;
 50+ const ORD_LF = 10;
 51+ const ORD_SPACE = 32;
5252
53 - protected $a = '';
54 - protected $b = '';
55 - protected $input = '';
56 - protected $inputIndex = 0;
57 - protected $inputLength = 0;
58 - protected $lookAhead = null;
59 - protected $output = '';
 53+ protected $a = '';
 54+ protected $b = '';
 55+ protected $input = '';
 56+ protected $inputIndex = 0;
 57+ protected $inputLength = 0;
 58+ protected $lookAhead = null;
 59+ protected $output = '';
6060
61 - // -- Public Static Methods --------------------------------------------------
 61+ // -- Public Static Methods --------------------------------------------------
6262
63 - public static function minify($js) {
64 - $jsmin = new JSMin($js);
65 - return $jsmin->min();
66 - }
 63+ public static function minify( $js ) {
 64+ $jsmin = new JSMin( $js );
 65+ return $jsmin->min();
 66+ }
6767
68 - // -- Public Instance Methods ------------------------------------------------
 68+ // -- Public Instance Methods ------------------------------------------------
6969
70 - public function __construct($input) {
71 - $this->input = str_replace("\r\n", "\n", $input);
72 - $this->inputLength = strlen($this->input);
73 - }
 70+ public function __construct( $input ) {
 71+ $this->input = str_replace( "\r\n", "\n", $input );
 72+ $this->inputLength = strlen( $this->input );
 73+ }
7474
75 - // -- Protected Instance Methods ---------------------------------------------
 75+ // -- Protected Instance Methods ---------------------------------------------
7676
77 - protected function action($d) {
78 - switch($d) {
79 - case 1:
80 - $this->output .= $this->a;
 77+ protected function action( $d ) {
 78+ switch( $d ) {
 79+ case 1:
 80+ $this->output .= $this->a;
8181
82 - case 2:
83 - $this->a = $this->b;
 82+ case 2:
 83+ $this->a = $this->b;
8484
85 - if ($this->a === "'" || $this->a === '"') {
86 - for (;;) {
87 - $this->output .= $this->a;
88 - $this->a = $this->get();
 85+ if ( $this->a === "'" || $this->a === '"' ) {
 86+ for ( ; ; ) {
 87+ $this->output .= $this->a;
 88+ $this->a = $this->get();
8989
90 - if ($this->a === $this->b) {
91 - break;
92 - }
 90+ if ( $this->a === $this->b ) {
 91+ break;
 92+ }
9393
94 - if (ord($this->a) <= self::ORD_LF) {
95 - throw new JSMinException('Unterminated string literal.');
96 - }
 94+ if ( ord( $this->a ) <= self::ORD_LF ) {
 95+ throw new JSMinException( 'Unterminated string literal.' );
 96+ }
9797
98 - if ($this->a === '\\') {
99 - $this->output .= $this->a;
100 - $this->a = $this->get();
101 - }
102 - }
103 - }
 98+ if ( $this->a === '\\' ) {
 99+ $this->output .= $this->a;
 100+ $this->a = $this->get();
 101+ }
 102+ }
 103+ }
104104
105 - case 3:
106 - $this->b = $this->next();
 105+ case 3:
 106+ $this->b = $this->next();
107107
108 - if ($this->b === '/' && (
109 - $this->a === '(' || $this->a === ',' || $this->a === '=' ||
110 - $this->a === ':' || $this->a === '[' || $this->a === '!' ||
111 - $this->a === '&' || $this->a === '|' || $this->a === '?')) {
 108+ if ( $this->b === '/' && (
 109+ $this->a === '(' || $this->a === ',' || $this->a === '=' ||
 110+ $this->a === ':' || $this->a === '[' || $this->a === '!' ||
 111+ $this->a === '&' || $this->a === '|' || $this->a === '?' ) ) {
112112
113 - $this->output .= $this->a . $this->b;
 113+ $this->output .= $this->a . $this->b;
114114
115 - for (;;) {
116 - $this->a = $this->get();
 115+ for ( ; ; ) {
 116+ $this->a = $this->get();
117117
118 - if ($this->a === '/') {
119 - break;
120 - } elseif ($this->a === '\\') {
121 - $this->output .= $this->a;
122 - $this->a = $this->get();
123 - } elseif (ord($this->a) <= self::ORD_LF) {
124 - throw new JSMinException('Unterminated regular expression '.
125 - 'literal.');
126 - }
 118+ if ( $this->a === '/' ) {
 119+ break;
 120+ } elseif ( $this->a === '\\' ) {
 121+ $this->output .= $this->a;
 122+ $this->a = $this->get();
 123+ } elseif ( ord( $this->a ) <= self::ORD_LF ) {
 124+ throw new JSMinException( 'Unterminated regular expression ' .
 125+ 'literal.' );
 126+ }
127127
128 - $this->output .= $this->a;
129 - }
 128+ $this->output .= $this->a;
 129+ }
130130
131 - $this->b = $this->next();
132 - }
133 - }
134 - }
 131+ $this->b = $this->next();
 132+ }
 133+ }
 134+ }
135135
136 - protected function get() {
137 - $c = $this->lookAhead;
138 - $this->lookAhead = null;
 136+ protected function get() {
 137+ $c = $this->lookAhead;
 138+ $this->lookAhead = null;
139139
140 - if ($c === null) {
141 - if ($this->inputIndex < $this->inputLength) {
142 - $c = substr($this->input, $this->inputIndex, 1);
143 - $this->inputIndex += 1;
144 - } else {
145 - $c = null;
146 - }
147 - }
 140+ if ( $c === null ) {
 141+ if ( $this->inputIndex < $this->inputLength ) {
 142+ $c = substr( $this->input, $this->inputIndex, 1 );
 143+ $this->inputIndex += 1;
 144+ } else {
 145+ $c = null;
 146+ }
 147+ }
148148
149 - if ($c === "\r") {
150 - return "\n";
151 - }
 149+ if ( $c === "\r" ) {
 150+ return "\n";
 151+ }
152152
153 - if ($c === null || $c === "\n" || ord($c) >= self::ORD_SPACE) {
154 - return $c;
155 - }
 153+ if ( $c === null || $c === "\n" || ord( $c ) >= self::ORD_SPACE ) {
 154+ return $c;
 155+ }
156156
157 - return ' ';
158 - }
 157+ return ' ';
 158+ }
159159
160 - protected function isAlphaNum($c) {
161 - return ord($c) > 126 || $c === '\\' || preg_match('/^[\w\$]$/', $c) === 1;
162 - }
 160+ protected function isAlphaNum( $c ) {
 161+ return ord( $c ) > 126 || $c === '\\' || preg_match( '/^[\w\$]$/', $c ) === 1;
 162+ }
163163
164 - protected function min() {
165 - $this->a = "\n";
166 - $this->action(3);
 164+ protected function min() {
 165+ $this->a = "\n";
 166+ $this->action( 3 );
167167
168 - while ($this->a !== null) {
169 - switch ($this->a) {
170 - case ' ':
171 - if ($this->isAlphaNum($this->b)) {
172 - $this->action(1);
173 - } else {
174 - $this->action(2);
175 - }
176 - break;
 168+ while ( $this->a !== null ) {
 169+ switch ( $this->a ) {
 170+ case ' ':
 171+ if ( $this->isAlphaNum( $this->b ) ) {
 172+ $this->action( 1 );
 173+ } else {
 174+ $this->action( 2 );
 175+ }
 176+ break;
177177
178 - case "\n":
179 - switch ($this->b) {
180 - case '{':
181 - case '[':
182 - case '(':
183 - case '+':
184 - case '-':
185 - $this->action(1);
186 - break;
 178+ case "\n":
 179+ switch ( $this->b ) {
 180+ case '{':
 181+ case '[':
 182+ case '(':
 183+ case '+':
 184+ case '-':
 185+ $this->action( 1 );
 186+ break;
187187
188 - case ' ':
189 - $this->action(3);
190 - break;
 188+ case ' ':
 189+ $this->action( 3 );
 190+ break;
191191
192 - default:
193 - if ($this->isAlphaNum($this->b)) {
194 - $this->action(1);
195 - }
196 - else {
197 - $this->action(2);
198 - }
199 - }
200 - break;
 192+ default:
 193+ if ( $this->isAlphaNum( $this->b ) ) {
 194+ $this->action( 1 );
 195+ }
 196+ else {
 197+ $this->action( 2 );
 198+ }
 199+ }
 200+ break;
201201
202 - default:
203 - switch ($this->b) {
204 - case ' ':
205 - if ($this->isAlphaNum($this->a)) {
206 - $this->action(1);
207 - break;
208 - }
 202+ default:
 203+ switch ( $this->b ) {
 204+ case ' ':
 205+ if ( $this->isAlphaNum( $this->a ) ) {
 206+ $this->action( 1 );
 207+ break;
 208+ }
209209
210 - $this->action(3);
211 - break;
 210+ $this->action( 3 );
 211+ break;
212212
213 - case "\n":
214 - switch ($this->a) {
215 - case '}':
216 - case ']':
217 - case ')':
218 - case '+':
219 - case '-':
220 - case '"':
221 - case "'":
222 - $this->action(1);
223 - break;
 213+ case "\n":
 214+ switch ( $this->a ) {
 215+ case '}':
 216+ case ']':
 217+ case ')':
 218+ case '+':
 219+ case '-':
 220+ case '"':
 221+ case "'":
 222+ $this->action( 1 );
 223+ break;
224224
225 - default:
226 - if ($this->isAlphaNum($this->a)) {
227 - $this->action(1);
228 - }
229 - else {
230 - $this->action(3);
231 - }
232 - }
233 - break;
 225+ default:
 226+ if ( $this->isAlphaNum( $this->a ) ) {
 227+ $this->action( 1 );
 228+ }
 229+ else {
 230+ $this->action( 3 );
 231+ }
 232+ }
 233+ break;
234234
235 - default:
236 - $this->action(1);
237 - break;
238 - }
239 - }
240 - }
 235+ default:
 236+ $this->action( 1 );
 237+ break;
 238+ }
 239+ }
 240+ }
241241
242 - return $this->output;
243 - }
 242+ return $this->output;
 243+ }
244244
245 - protected function next() {
246 - $c = $this->get();
 245+ protected function next() {
 246+ $c = $this->get();
247247
248 - if ($c === '/') {
249 - switch($this->peek()) {
250 - case '/':
251 - for (;;) {
252 - $c = $this->get();
 248+ if ( $c === '/' ) {
 249+ switch( $this->peek() ) {
 250+ case '/':
 251+ for ( ; ; ) {
 252+ $c = $this->get();
253253
254 - if (ord($c) <= self::ORD_LF) {
255 - return $c;
256 - }
257 - }
 254+ if ( ord( $c ) <= self::ORD_LF ) {
 255+ return $c;
 256+ }
 257+ }
258258
259 - case '*':
260 - $this->get();
 259+ case '*':
 260+ $this->get();
261261
262 - for (;;) {
263 - switch($this->get()) {
264 - case '*':
265 - if ($this->peek() === '/') {
266 - $this->get();
267 - return ' ';
268 - }
269 - break;
 262+ for ( ; ; ) {
 263+ switch( $this->get() ) {
 264+ case '*':
 265+ if ( $this->peek() === '/' ) {
 266+ $this->get();
 267+ return ' ';
 268+ }
 269+ break;
270270
271 - case null:
272 - throw new JSMinException('Unterminated comment.');
273 - }
274 - }
 271+ case null:
 272+ throw new JSMinException( 'Unterminated comment.' );
 273+ }
 274+ }
275275
276 - default:
277 - return $c;
278 - }
279 - }
 276+ default:
 277+ return $c;
 278+ }
 279+ }
280280
281 - return $c;
282 - }
 281+ return $c;
 282+ }
283283
284 - protected function peek() {
285 - $this->lookAhead = $this->get();
286 - return $this->lookAhead;
287 - }
 284+ protected function peek() {
 285+ $this->lookAhead = $this->get();
 286+ return $this->lookAhead;
 287+ }
288288 }
289289
290290 // -- Exceptions ---------------------------------------------------------------
291291 class JSMinException extends Exception {}
292 -?>
\ No newline at end of file
 292+?>

Status & tagging log