@@ -177,7 +177,8 @@ protected function formatLines($lines)
177
177
$ lines = array_map (array ($ this , 'ExpandTabs ' ), $ lines );
178
178
$ lines = array_map (array ($ this , 'HtmlSafe ' ), $ lines );
179
179
foreach ($ lines as &$ line ) {
180
- $ line = preg_replace ('# ( +)|^ #e ' , "\$this->fixSpaces(' \\1') " , $ line );
180
+ $ line = str_replace (' ' , ' ' , $ line );
181
+ // $line = preg_replace_callback('# ( +)|^ #', array($this, 'fixSpaces'), $line);
181
182
}
182
183
return $ lines ;
183
184
}
@@ -188,16 +189,19 @@ protected function formatLines($lines)
188
189
* @param string $spaces The string of spaces.
189
190
* @return string The HTML representation of the string.
190
191
*/
191
- function fixSpaces ($ spaces = '' )
192
+ function fixSpaces ($ matches )
192
193
{
193
- $ count = strlen ($ spaces );
194
- if ($ count == 0 ) {
195
- return '' ;
194
+ $ buffer = '' ;
195
+ foreach ($ matches as $ spaces ){
196
+ $ count = strlen ($ spaces );
197
+ if ($ count == 0 ) {
198
+ continue ;
199
+ }
200
+ $ div = floor ($ count / 2 );
201
+ $ mod = $ count % 2 ;
202
+ $ buffer .= str_repeat (' ' , $ div ).str_repeat (' ' , $ mod );
196
203
}
197
-
198
- $ div = floor ($ count / 2 );
199
- $ mod = $ count % 2 ;
200
- return str_repeat (' ' , $ div ).str_repeat (' ' , $ mod );
204
+ return $ buffer ;
201
205
}
202
206
203
207
/**
@@ -208,7 +212,16 @@ function fixSpaces($spaces='')
208
212
*/
209
213
private function expandTabs ($ line )
210
214
{
211
- return str_replace ("\t" , str_repeat (' ' , $ this ->options ['tabSize ' ]), $ line );
215
+ $ tabSize = $ this ->options ['tabSize ' ];
216
+ while (($ pos = strpos ($ line , "\t" )) !== FALSE ){
217
+ $ left = substr ($ line , 0 , $ pos );
218
+ $ right = substr ($ line , $ pos + 1 );
219
+ $ length = $ tabSize - ($ pos % $ tabSize );
220
+ $ spaces = str_repeat (' ' , $ length );
221
+ $ line = $ left .$ spaces .$ right ;
222
+ }
223
+ return $ line ;
224
+ // return str_replace("\t", str_repeat(' ', $this->options['tabSize']), $line);
212
225
}
213
226
214
227
/**
0 commit comments