implement IDF_Scm_Monotone_BasicIO::compile()
This commit is contained in:
		| @@ -26,7 +26,7 @@ | |||||||
|  * |  * | ||||||
|  * @author Thomas Keller <me@thomaskeller.biz> |  * @author Thomas Keller <me@thomaskeller.biz> | ||||||
|  */ |  */ | ||||||
| class IDF_Scm_Monotone_BasicIO extends IDF_Scm | class IDF_Scm_Monotone_BasicIO | ||||||
| { | { | ||||||
|     /** |     /** | ||||||
|      * Parses monotone's basic_io format |      * Parses monotone's basic_io format | ||||||
| @@ -54,6 +54,7 @@ class IDF_Scm_Monotone_BasicIO extends IDF_Scm | |||||||
|                 } |                 } | ||||||
|  |  | ||||||
|                 if ($in[$pos] == '[') { |                 if ($in[$pos] == '[') { | ||||||
|  |                     unset($stanzaLine['values']); | ||||||
|                     ++$pos; // opening square bracket |                     ++$pos; // opening square bracket | ||||||
|                     $stanzaLine['hash'] = substr($in, $pos, 40); |                     $stanzaLine['hash'] = substr($in, $pos, 40); | ||||||
|                     $pos += 40; |                     $pos += 40; | ||||||
| @@ -61,6 +62,7 @@ class IDF_Scm_Monotone_BasicIO extends IDF_Scm | |||||||
|                 } |                 } | ||||||
|                 else |                 else | ||||||
|                 { |                 { | ||||||
|  |                     unset($stanzaLine['hash']); | ||||||
|                     $valCount = 0; |                     $valCount = 0; | ||||||
|                     while ($in[$pos] == '"') { |                     while ($in[$pos] == '"') { | ||||||
|                         ++$pos; // opening quote |                         ++$pos; // opening quote | ||||||
| @@ -105,7 +107,56 @@ class IDF_Scm_Monotone_BasicIO extends IDF_Scm | |||||||
|      */ |      */ | ||||||
|     public static function compile($in) |     public static function compile($in) | ||||||
|     { |     { | ||||||
|         throw new IDF_Scm_Exception("not yet implemented"); |         $out = ""; | ||||||
|  |         $first = true; | ||||||
|  |         foreach ((array)$in as $sx => $stanza) { | ||||||
|  |             if ($first) | ||||||
|  |                 $first = false; | ||||||
|  |             else | ||||||
|  |                 $out .= "\n"; | ||||||
|  |  | ||||||
|  |             $maxkeylength = 0; | ||||||
|  |             foreach ((array)$stanza as $lx => $line) { | ||||||
|  |                 if (!array_key_exists('key', $line)) { | ||||||
|  |                     throw new IDF_Scm_Exception( | ||||||
|  |                         '"key" not found in basicio stanza '.$sx.', line '.$lx | ||||||
|  |                     ); | ||||||
|  |                 } | ||||||
|  |                 $maxkeylength = max($maxkeylength, strlen($line['key'])); | ||||||
|  |             } | ||||||
|  |  | ||||||
|  |             foreach ((array)$stanza as $lx => $line) { | ||||||
|  |                 $out .= str_pad($line['key'], $maxkeylength, ' ', STR_PAD_LEFT); | ||||||
|  |  | ||||||
|  |                 if (array_key_exists('hash', $line)) { | ||||||
|  |                     $out .= ' ['.$line['hash'].']'; | ||||||
|  |                 } else | ||||||
|  |                 if (array_key_exists('values', $line)) { | ||||||
|  |                     if (!is_array($line['values']) || count($line['values']) == 0) { | ||||||
|  |                         throw new IDF_Scm_Exception( | ||||||
|  |                             '"values" must be an array of a size >= 1 '. | ||||||
|  |                             'in basicio stanza '.$sx.', line '.$lx | ||||||
|  |                         ); | ||||||
|  |                     } | ||||||
|  |                     foreach ($line['values'] as $value) { | ||||||
|  |                         $out .= ' "'.str_replace( | ||||||
|  |                              array("\\", "\""), | ||||||
|  |                              array("\\\\", "\\\""), | ||||||
|  |                              $value).'"'; | ||||||
|  |                     } | ||||||
|  |                 } | ||||||
|  |                 else | ||||||
|  |                 { | ||||||
|  |                     throw new IDF_Scm_Exception( | ||||||
|  |                         'neither "hash" nor "values" found in basicio '. | ||||||
|  |                         'stanza '.$sx.', line '.$lx | ||||||
|  |                     ); | ||||||
|  |                 } | ||||||
|  |  | ||||||
|  |                 $out .= "\n"; | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  |         return $out; | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user