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,7 +262,7 @@ class FilesMgr extends AmdaObjectMgr
262 while (!feof($handler) && !$StartTime) { 262 while (!feof($handler) && !$StartTime) {
263 $oneLine = trim(preg_replace('/\s+/', ' ', fgets($handler))); 263 $oneLine = trim(preg_replace('/\s+/', ' ', fgets($handler)));
264 $elems = explode(' ', $oneLine); 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 $i++; 266 $i++;
267 continue; 267 continue;
268 } 268 }
@@ -275,8 +275,8 @@ class FilesMgr extends AmdaObjectMgr @@ -275,8 +275,8 @@ class FilesMgr extends AmdaObjectMgr
275 if (feof($handler)) return -10; 275 if (feof($handler)) return -10;
276 276
277 $oneLine = trim(preg_replace('/\s+/', ' ', fgets($handler))); 277 $oneLine = trim(preg_replace('/\s+/', ' ', fgets($handler)));
  278 + $elems = explode(' ',$oneLine);
278 279
279 - $elems = explode(" ",$oneLine);  
280 if (count($elems) < 2) return -10; 280 if (count($elems) < 2) return -10;
281 281
282 // dT else Array 282 // dT else Array
@@ -297,8 +297,8 @@ class FilesMgr extends AmdaObjectMgr @@ -297,8 +297,8 @@ class FilesMgr extends AmdaObjectMgr
297 if ($handler) { 297 if ($handler) {
298 $i = 0; 298 $i = 0;
299 while (!feof($handler) && !$StartTime) { 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 if (strlen($elems[0]) < 16 || !($time = strtotime($elems[0]))) { 302 if (strlen($elems[0]) < 16 || !($time = strtotime($elems[0]))) {
303 $i++; 303 $i++;
304 continue; 304 continue;
@@ -311,8 +311,8 @@ class FilesMgr extends AmdaObjectMgr @@ -311,8 +311,8 @@ class FilesMgr extends AmdaObjectMgr
311 } 311 }
312 312
313 if (feof($handle)) return array(-10); 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 if (count($elems) < 2) return array (-1); 316 if (count($elems) < 2) return array (-1);
317 // dT else Array 317 // dT else Array
318 if (!($time = strtotime($elems[0]))) 318 if (!($time = strtotime($elems[0])))
@@ -324,8 +324,9 @@ class FilesMgr extends AmdaObjectMgr @@ -324,8 +324,9 @@ class FilesMgr extends AmdaObjectMgr
324 324
325 while (!feof($handler)) 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 if (count($elems) < 2) continue; 330 if (count($elems) < 2) continue;
330 $StartTime = $time; 331 $StartTime = $time;
331 if (!($time = strtotime($elems[0]))) return array(-1); 332 if (!($time = strtotime($elems[0]))) return array(-1);
@@ -358,8 +359,9 @@ class FilesMgr extends AmdaObjectMgr @@ -358,8 +359,9 @@ class FilesMgr extends AmdaObjectMgr
358 $i = 0; 359 $i = 0;
359 while (!$StartTime && !feof($handler)) 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 if (!($time = strtotime($elems[0]))) 365 if (!($time = strtotime($elems[0])))
364 { 366 {
365 $offset = ftell($handler); 367 $offset = ftell($handler);
@@ -372,9 +374,10 @@ class FilesMgr extends AmdaObjectMgr @@ -372,9 +374,10 @@ class FilesMgr extends AmdaObjectMgr
372 } 374 }
373 375
374 $newfile = fopen(USERDATADIR."temp", "w"); 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 // dT 381 // dT
379 if (!($time = strtotime($elems[0]))) 382 if (!($time = strtotime($elems[0])))
380 { 383 {
@@ -384,8 +387,8 @@ class FilesMgr extends AmdaObjectMgr @@ -384,8 +387,8 @@ class FilesMgr extends AmdaObjectMgr
384 $newtime += $dt; 387 $newtime += $dt;
385 388
386 while (!feof($handler)) 389 while (!feof($handler))
387 - {  
388 - $oneLine = trim(fgets($handler)); 390 + {
  391 + $oneLine = trim(preg_replace('/\s+/', ' ', fgets($handler)));
389 if ($oneLine != PHP_EOL && count($elems) > 0) fwrite($newfile, $newtime." ".$oneLine.PHP_EOL); 392 if ($oneLine != PHP_EOL && count($elems) > 0) fwrite($newfile, $newtime." ".$oneLine.PHP_EOL);
390 $newtime += $dt; 393 $newtime += $dt;
391 } 394 }
@@ -395,9 +398,9 @@ class FilesMgr extends AmdaObjectMgr @@ -395,9 +398,9 @@ class FilesMgr extends AmdaObjectMgr
395 { 398 {
396 fseek($handler, $offset); 399 fseek($handler, $offset);
397 while (!feof($handler)) 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 // empty lines 404 // empty lines
402 if (count($elems) < 2) continue; 405 if (count($elems) < 2) continue;
403 $newtime = strtotime($elems[0]); 406 $newtime = strtotime($elems[0]);
@@ -445,18 +448,18 @@ class FilesMgr extends AmdaObjectMgr @@ -445,18 +448,18 @@ class FilesMgr extends AmdaObjectMgr
445 $newfile = fopen(USERDATADIR."temp", "w"); 448 $newfile = fopen(USERDATADIR."temp", "w");
446 while (!feof($handle)) 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 try 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 if (!$date) 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 else 464 else
462 { 465 {
@@ -464,7 +467,7 @@ class FilesMgr extends AmdaObjectMgr @@ -464,7 +467,7 @@ class FilesMgr extends AmdaObjectMgr
464 if ($doy) { 467 if ($doy) {
465 $date->modify('-1 day'); 468 $date->modify('-1 day');
466 } 469 }
467 - $suffix = preg_replace('/\s+/', ' ',substr($line, $formatLength)); 470 + $suffix = preg_replace('/\s+/', ' ',substr($oneLine, $formatLength));
468 fwrite($newfile,$date->format('Y-m-d')."T".$date->format('H:i:s').$suffix.PHP_EOL); 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,7 +477,7 @@ class FilesMgr extends AmdaObjectMgr
474 } 477 }
475 } 478 }
476 else 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,7 +488,7 @@ class FilesMgr extends AmdaObjectMgr
485 fclose($handle); 488 fclose($handle);
486 unlink($this->fileName); 489 unlink($this->fileName);
487 } 490 }
488 - return $false; 491 + return false;
489 } 492 }
490 493
491 fclose($newfile); 494 fclose($newfile);