Simplification
authorx2003bruneau <x2003bruneau@839d8a87-29fc-0310-9880-83ba4fa771e5>
Sat, 12 Aug 2006 23:03:36 +0000 (23:03 +0000)
committerx2003bruneau <x2003bruneau@839d8a87-29fc-0310-9880-83ba4fa771e5>
Sat, 12 Aug 2006 23:03:36 +0000 (23:03 +0000)
git-svn-id: svn+ssh://murphy/home/svn/platal/trunk@809 839d8a87-29fc-0310-9880-83ba4fa771e5

classes/XDB.php

index 5e07bc2..edcbed6 100644 (file)
@@ -38,20 +38,19 @@ class XDB
     {
         $query  = preg_split("/\n\\s*/", $query);
         $length = 0;
-        foreach ($query as $line) {
-            if (preg_match('/^([A-Z]+(?: +(?:JOIN|BY))?) /', $line, $matches)
+        foreach ($query as $key=>$line) {
+            $local = -2;
+            if (preg_match('/^([A-Z]+(?:\s+(?:JOIN|BY))?)\s+(.*)/', $line, $matches)
                 && $matches[1] != 'AND' && $matches[1] != 'OR') {
-                $length = max($length, strlen($matches[1]));
+                $local  = strlen($matches[1]);
+                $line   = $matches[1] . '  ' . $matches[2];
+                $length = max($length, $local);
             }
+            $query[$key] = array($line, $local);
         }
         $res = '';
-        foreach ($query as $line) {
-            $local = -2;
-            if (preg_match('/^([A-Z]+(?: +(?:JOIN|BY))?) +(.*)/', $line, $matches)
-                && $matches[1] != 'AND' && $matches[1] != 'OR') {
-                $local = strlen($matches[1]);
-                $line  = $matches[1] . '  ' . $matches[2];
-            }
+        foreach ($query as $array) {
+            list($line, $local) = $array;
             $local   = $length - $local;
             $res    .= str_repeat(' ', $local) . $line . "\n";
             $length += 2 * (substr_count($line, '(') - substr_count($line, ')'));