Commit ed15f51c7bfb79b3d089c7d23878b42a0eacd80f

Authored by Nathanaël Jourdane
1 parent e43d3d59

import file: remove tabs in all text parsing functions.

Showing 1 changed file with 30 additions and 27 deletions   Show diff stats
php/classes/FilesMgr.php
... ... @@ -262,7 +262,7 @@ class FilesMgr extends AmdaObjectMgr
262 262 while (!feof($handler) && !$StartTime) {
263 263 $oneLine = trim(preg_replace('/\s+/', ' ', fgets($handler)));
264 264 $elems = explode(' ', $oneLine);
265   - if ((strlen($elems[0]) < 16) || !($time = strtotime($elems[0]))) {
  265 + if ((strlen($elems[0]) < 16) || !($time = strtotime($elems[0]))) {
266 266 $i++;
267 267 continue;
268 268 }
... ... @@ -275,8 +275,8 @@ class FilesMgr extends AmdaObjectMgr
275 275 if (feof($handler)) return -10;
276 276  
277 277 $oneLine = trim(preg_replace('/\s+/', ' ', fgets($handler)));
  278 + $elems = explode(' ',$oneLine);
278 279  
279   - $elems = explode(" ",$oneLine);
280 280 if (count($elems) < 2) return -10;
281 281  
282 282 // dT else Array
... ... @@ -297,8 +297,8 @@ class FilesMgr extends AmdaObjectMgr
297 297 if ($handler) {
298 298 $i = 0;
299 299 while (!feof($handler) && !$StartTime) {
300   - $oneLine = trim(fgets($handler));
301   - $elems = explode(" ", preg_replace('/\s+/', ' ', $oneLine));
  300 + $oneLine = trim(preg_replace('/\s+/', ' ', fgets($handler)));
  301 + $elems = explode(' ',$oneLine);
302 302 if (strlen($elems[0]) < 16 || !($time = strtotime($elems[0]))) {
303 303 $i++;
304 304 continue;
... ... @@ -311,8 +311,8 @@ class FilesMgr extends AmdaObjectMgr
311 311 }
312 312  
313 313 if (feof($handle)) return array(-10);
314   - $oneLine = trim(fgets($handler));
315   - $elems = explode(" ",$oneLine);
  314 + $oneLine = trim(preg_replace('/\s+/', ' ', fgets($handler)));
  315 + $elems = explode(' ',$oneLine);
316 316 if (count($elems) < 2) return array (-1);
317 317 // dT else Array
318 318 if (!($time = strtotime($elems[0])))
... ... @@ -324,8 +324,9 @@ class FilesMgr extends AmdaObjectMgr
324 324  
325 325 while (!feof($handler))
326 326 {
327   - $oneLine = trim(fgets($handler));
328   - $elems = explode(" ",$oneLine);
  327 + $oneLine = trim(preg_replace('/\s+/', ' ', fgets($handler)));
  328 + $elems = explode(' ',$oneLine);
  329 +
329 330 if (count($elems) < 2) continue;
330 331 $StartTime = $time;
331 332 if (!($time = strtotime($elems[0]))) return array(-1);
... ... @@ -358,8 +359,9 @@ class FilesMgr extends AmdaObjectMgr
358 359 $i = 0;
359 360 while (!$StartTime && !feof($handler))
360 361 {
361   - $oneLine = trim(fgets($handler));
362   - $elems = explode(" ", preg_replace('/\s+/', ' ', $oneLine));
  362 + $oneLine = trim(preg_replace('/\s+/', ' ', fgets($handler)));
  363 + $elems = explode(' ',$oneLine);
  364 +
363 365 if (!($time = strtotime($elems[0])))
364 366 {
365 367 $offset = ftell($handler);
... ... @@ -372,9 +374,10 @@ class FilesMgr extends AmdaObjectMgr
372 374 }
373 375  
374 376 $newfile = fopen(USERDATADIR."temp", "w");
375   -
376   - $oneLine = trim(fgets($handler));
377   - $elems = explode(" " , $oneLine);
  377 +
  378 + $oneLine = trim(preg_replace('/\s+/', ' ', fgets($handler)));
  379 + $elems = explode(' ',$oneLine);
  380 +
378 381 // dT
379 382 if (!($time = strtotime($elems[0])))
380 383 {
... ... @@ -384,8 +387,8 @@ class FilesMgr extends AmdaObjectMgr
384 387 $newtime += $dt;
385 388  
386 389 while (!feof($handler))
387   - {
388   - $oneLine = trim(fgets($handler));
  390 + {
  391 + $oneLine = trim(preg_replace('/\s+/', ' ', fgets($handler)));
389 392 if ($oneLine != PHP_EOL && count($elems) > 0) fwrite($newfile, $newtime." ".$oneLine.PHP_EOL);
390 393 $newtime += $dt;
391 394 }
... ... @@ -395,9 +398,9 @@ class FilesMgr extends AmdaObjectMgr
395 398 {
396 399 fseek($handler, $offset);
397 400 while (!feof($handler))
398   - {
399   - $oneLine = trim(fgets($handler));
400   - $elems = explode(" " ,$oneLine);
  401 + {
  402 + $oneLine = trim(preg_replace('/\s+/', ' ', fgets($handler)));
  403 + $elems = explode(' ',$oneLine);
401 404 // empty lines
402 405 if (count($elems) < 2) continue;
403 406 $newtime = strtotime($elems[0]);
... ... @@ -445,18 +448,18 @@ class FilesMgr extends AmdaObjectMgr
445 448 $newfile = fopen(USERDATADIR."temp", "w");
446 449 while (!feof($handle))
447 450 {
448   - if (($oneLine = fgets($handle)) !== false)
  451 + $oneLine = trim(preg_replace('/\s+/', ' ', fgets($handle)));
  452 +
  453 + if ($oneLine !== false)
449 454 {
450   - $line = $timeLength == 'auto' ? $line = trim(preg_replace('/\s+/', ' ', $oneLine)) : trim($oneLine);
451   -
452   - if (strlen($line) > $formatLength)
  455 + if (strlen($oneLine) > $formatLength)
453 456 {
454 457 try
455 458 {
456   - $date = DateTime::createFromFormat($timeFormat, trim(substr($line,0,$formatLength)));
  459 + $date = DateTime::createFromFormat($timeFormat, trim(substr($oneLine,0,$formatLength)));
457 460 if (!$date)
458 461 {
459   - if (strpos($line,'#') === 0) fwrite($newfile, $line.PHP_EOL);
  462 + if (strpos($oneLine,'#') === 0) fwrite($newfile, $oneLine.PHP_EOL);
460 463 }
461 464 else
462 465 {
... ... @@ -464,7 +467,7 @@ class FilesMgr extends AmdaObjectMgr
464 467 if ($doy) {
465 468 $date->modify('-1 day');
466 469 }
467   - $suffix = preg_replace('/\s+/', ' ',substr($line, $formatLength));
  470 + $suffix = preg_replace('/\s+/', ' ',substr($oneLine, $formatLength));
468 471 fwrite($newfile,$date->format('Y-m-d')."T".$date->format('H:i:s').$suffix.PHP_EOL);
469 472 }
470 473 }
... ... @@ -474,7 +477,7 @@ class FilesMgr extends AmdaObjectMgr
474 477 }
475 478 }
476 479 else
477   - if (strpos($line,'#') === 0) fwrite($newfile,$line.PHP_EOL);
  480 + if (strpos($oneLine,'#') === 0) fwrite($newfile,$oneLine.PHP_EOL);
478 481 }
479 482 }
480 483 }
... ... @@ -485,7 +488,7 @@ class FilesMgr extends AmdaObjectMgr
485 488 fclose($handle);
486 489 unlink($this->fileName);
487 490 }
488   - return $false;
  491 + return false;
489 492 }
490 493  
491 494 fclose($newfile);
... ...