r71889 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r71888‎ | r71889 | r71890 >
Date:17:39, 29 August 2010
Author:siebrand
Status:deferred
Tags:
Comment:
Modified paths:
  • /trunk/extensions/Translate/spyc/spyc.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Translate/spyc/spyc.php
@@ -10,25 +10,25 @@
1111 * @package Spyc
1212 */
1313
14 -if ( !function_exists( 'spyc_load' ) ) {
 14+if (!function_exists('spyc_load')) {
1515 /**
1616 * Parses YAML to array.
1717 * @param string $string YAML string.
1818 * @return array
1919 */
20 - function spyc_load ( $string ) {
21 - return Spyc::YAMLLoadString( $string );
 20+ function spyc_load ($string) {
 21+ return Spyc::YAMLLoadString($string);
2222 }
2323 }
2424
25 -if ( !function_exists( 'spyc_load_file' ) ) {
 25+if (!function_exists('spyc_load_file')) {
2626 /**
2727 * Parses YAML to array.
2828 * @param string $file Path to YAML file.
2929 * @return array
3030 */
31 - function spyc_load_file ( $file ) {
32 - return Spyc::YAMLLoad( $file );
 31+ function spyc_load_file ($file) {
 32+ return Spyc::YAMLLoad($file);
3333 }
3434 }
3535
@@ -105,8 +105,8 @@
106106 * @param string $input
107107 * @return array
108108 */
109 - public function load ( $input ) {
110 - return $this->__loadString( $input );
 109+ public function load ($input) {
 110+ return $this->__loadString($input);
111111 }
112112
113113 /**
@@ -114,8 +114,8 @@
115115 * @param string $file
116116 * @return array
117117 */
118 - public function loadFile ( $file ) {
119 - return $this->__load( $file );
 118+ public function loadFile ($file) {
 119+ return $this->__load($file);
120120 }
121121
122122 /**
@@ -133,9 +133,9 @@
134134 * @return array
135135 * @param string $input Path of YAML file or string containing YAML
136136 */
137 - public static function YAMLLoad( $input ) {
 137+ public static function YAMLLoad($input) {
138138 $Spyc = new Spyc;
139 - return $Spyc->__load( $input );
 139+ return $Spyc->__load($input);
140140 }
141141
142142 /**
@@ -157,9 +157,9 @@
158158 * @return array
159159 * @param string $input String containing YAML
160160 */
161 - public static function YAMLLoadString( $input ) {
 161+ public static function YAMLLoadString($input) {
162162 $Spyc = new Spyc;
163 - return $Spyc->__loadString( $input );
 163+ return $Spyc->__loadString($input);
164164 }
165165
166166 /**
@@ -182,9 +182,9 @@
183183 * @param int $indent Pass in false to use the default, which is 2
184184 * @param int $wordwrap Pass in 0 for no wordwrap, false for default (40)
185185 */
186 - public static function YAMLDump( $array, $indent = false, $wordwrap = false ) {
 186+ public static function YAMLDump($array,$indent = false,$wordwrap = false) {
187187 $spyc = new Spyc;
188 - return $spyc->dump( $array, $indent, $wordwrap );
 188+ return $spyc->dump($array,$indent,$wordwrap);
189189 }
190190
191191
@@ -208,18 +208,18 @@
209209 * @param int $indent Pass in false to use the default, which is 2
210210 * @param int $wordwrap Pass in 0 for no wordwrap, false for default (40)
211211 */
212 - public function dump( $array, $indent = false, $wordwrap = false ) {
 212+ public function dump($array,$indent = false,$wordwrap = false) {
213213 // Dumps to some very clean YAML. We'll have to add some more features
214214 // and options soon. And better support for folding.
215215
216216 // New features and options.
217 - if ( $indent === false or !is_numeric( $indent ) ) {
 217+ if ($indent === false or !is_numeric($indent)) {
218218 $this->_dumpIndent = 2;
219219 } else {
220220 $this->_dumpIndent = $indent;
221221 }
222222
223 - if ( $wordwrap === false or !is_numeric( $wordwrap ) ) {
 223+ if ($wordwrap === false or !is_numeric($wordwrap)) {
224224 $this->_dumpWordWrap = 40;
225225 } else {
226226 $this->_dumpWordWrap = $wordwrap;
@@ -229,13 +229,13 @@
230230 $string = "---\n";
231231
232232 // Start at the base of the array and move through it.
233 - if ( $array ) {
 233+ if ($array) {
234234 $array = (array)$array;
235 - $first_key = key( $array );
 235+ $first_key = key($array);
236236
237237 $previous_key = -1;
238 - foreach ( $array as $key => $value ) {
239 - $string .= $this->_yamlize( $key, $value, 0, $previous_key, $first_key );
 238+ foreach ($array as $key => $value) {
 239+ $string .= $this->_yamlize($key,$value,0,$previous_key, $first_key, $array);
240240 $previous_key = $key;
241241 }
242242 }
@@ -250,20 +250,20 @@
251251 * @param $value The value of the item
252252 * @param $indent The indent of the current node
253253 */
254 - private function _yamlize( $key, $value, $indent, $previous_key = -1, $first_key = 0 ) {
255 - if ( is_array( $value ) ) {
256 - if ( empty ( $value ) )
257 - return $this->_dumpNode( $key, array(), $indent, $previous_key, $first_key );
 254+ private function _yamlize($key,$value,$indent, $previous_key = -1, $first_key = 0, $source_array = null) {
 255+ if (is_array($value)) {
 256+ if (empty ($value))
 257+ return $this->_dumpNode($key, array(), $indent, $previous_key, $first_key, $source_array);
258258 // It has children. What to do?
259259 // Make it the right kind of item
260 - $string = $this->_dumpNode( $key, null, $indent, $previous_key, $first_key );
 260+ $string = $this->_dumpNode($key, NULL, $indent, $previous_key, $first_key, $source_array);
261261 // Add the indent
262262 $indent += $this->_dumpIndent;
263263 // Yamlize the array
264 - $string .= $this->_yamlizeArray( $value, $indent );
265 - } elseif ( !is_array( $value ) ) {
 264+ $string .= $this->_yamlizeArray($value,$indent);
 265+ } elseif (!is_array($value)) {
266266 // It doesn't have children. Yip.
267 - $string = $this->_dumpNode( $key, $value, $indent, $previous_key, $first_key );
 267+ $string = $this->_dumpNode($key, $value, $indent, $previous_key, $first_key, $source_array);
268268 }
269269 return $string;
270270 }
@@ -275,13 +275,14 @@
276276 * @param $array The array you want to convert
277277 * @param $indent The indent of the current level
278278 */
279 - private function _yamlizeArray( $array, $indent ) {
280 - if ( is_array( $array ) ) {
 279+ private function _yamlizeArray($array,$indent) {
 280+ if (is_array($array)) {
281281 $string = '';
282282 $previous_key = -1;
283 - $first_key = key( $array );
284 - foreach ( $array as $key => $value ) {
285 - $string .= $this->_yamlize( $key, $value, $indent, $previous_key, $first_key );
 283+ $first_key = key($array);
 284+
 285+ foreach ($array as $key => $value) {
 286+ $string .= $this->_yamlize($key, $value, $indent, $previous_key, $first_key, $array);
286287 $previous_key = $key;
287288 }
288289 return $string;
@@ -298,38 +299,40 @@
299300 * @param $value The value of the item
300301 * @param $indent The indent of the current node
301302 */
302 - private function _dumpNode( $key, $value, $indent, $previous_key = -1, $first_key = 0 ) {
 303+ private function _dumpNode($key, $value, $indent, $previous_key = -1, $first_key = 0, $source_array = null) {
303304 // do some folding here, for blocks
304 - if ( is_string ( $value ) && ( ( strpos( $value, "\n" ) !== false || strpos( $value, ": " ) !== false || strpos( $value, "- " ) !== false ||
305 - strpos( $value, "*" ) !== false || strpos( $value, "#" ) !== false || strpos( $value, "<" ) !== false || strpos( $value, ">" ) !== false || strpos ( $value, ' ' ) !== false ||
306 - strpos( $value, "[" ) !== false || strpos( $value, "]" ) !== false || strpos( $value, "{" ) !== false || strpos( $value, "}" ) !== false ) || substr ( $value, -1, 1 ) == ':' )
 305+ if (is_string ($value) && ((strpos($value,"\n") !== false || strpos($value,": ") !== false || strpos($value,"- ") !== false ||
 306+ strpos($value,"*") !== false || strpos($value,"#") !== false || strpos($value,"<") !== false || strpos($value,">") !== false || strpos ($value, ' ') !== false ||
 307+ strpos($value,"[") !== false || strpos($value,"]") !== false || strpos($value,"{") !== false || strpos($value,"}") !== false) || strpos($value,"&") !== false ||
 308+ substr ($value, -1, 1) == ':')
307309 ) {
308 - $value = $this->_doLiteralBlock( $value, $indent );
 310+ $value = $this->_doLiteralBlock($value,$indent);
309311 } else {
310 - $value = $this->_doFolding( $value, $indent );
 312+ $value = $this->_doFolding($value,$indent);
311313 }
312314
313 - if ( $value === array() ) $value = '[ ]';
314 - if ( in_array ( $value, array ( 'true', 'TRUE', 'false', 'FALSE', 'y', 'Y', 'n', 'N', 'null', 'NULL' ), true ) ) {
315 - $value = $this->_doLiteralBlock( $value, $indent );
 315+ if ($value === array()) $value = '[ ]';
 316+ if (in_array ($value, array ('true', 'TRUE', 'false', 'FALSE', 'y', 'Y', 'n', 'N', 'null', 'NULL'), true)) {
 317+ $value = $this->_doLiteralBlock($value,$indent);
316318 }
317 - if ( trim ( $value ) != $value )
318 - $value = $this->_doLiteralBlock( $value, $indent );
 319+ if (trim ($value) != $value)
 320+ $value = $this->_doLiteralBlock($value,$indent);
319321
320 - if ( is_bool( $value ) ) {
321 - $value = ( $value ) ? "true" : "false";
 322+ if (is_bool($value)) {
 323+ $value = ($value) ? "true" : "false";
322324 }
323325
324 - $spaces = str_repeat( ' ', $indent );
 326+ $spaces = str_repeat(' ',$indent);
325327
326 - if ( is_int( $key ) && $key - 1 == $previous_key && $first_key === 0 ) {
 328+ //if (is_int($key) && $key - 1 == $previous_key && $first_key===0) {
 329+ if (is_array ($source_array) && array_keys($source_array) === range(0, count($source_array) - 1)) {
327330 // It's a sequence
328 - $string = $spaces . '- ' . $value . "\n";
 331+ $string = $spaces.'- '.$value."\n";
329332 } else {
330 - if ( $first_key === 0 ) throw new Exception( 'Keys are all screwy. The first one was zero, now it\'s "' . $key . '"' );
 333+ // if ($first_key===0) throw new Exception('Keys are all screwy. The first one was zero, now it\'s "'. $key .'"');
331334 // It's mapped
332 - if ( strpos( $key, ":" ) !== false ) { $key = '"' . $key . '"'; }
333 - $string = $spaces . $key . ': ' . $value . "\n";
 335+ if (strpos($key, ":") !== false || strpos($key, "#") !== false) { $key = '"' . $key . '"'; }
 336+ $string = rtrim ($spaces.$key.': '.$value)."\n";
334337 }
335338 return $string;
336339 }
@@ -341,20 +344,20 @@
342345 * @param $value
343346 * @param $indent int The value of the indent
344347 */
345 - private function _doLiteralBlock( $value, $indent ) {
346 - if ( $value === "\n" ) return '\n';
347 - if ( strpos( $value, "\n" ) === false && strpos( $value, "'" ) === false ) {
348 - return sprintf ( "'%s'", $value );
 348+ private function _doLiteralBlock($value,$indent) {
 349+ if ($value === "\n") return '\n';
 350+ if (strpos($value, "\n") === false && strpos($value, "'") === false) {
 351+ return sprintf ("'%s'", $value);
349352 }
350 - if ( strpos( $value, "\n" ) === false && strpos( $value, '"' ) === false ) {
351 - return sprintf ( '"%s"', $value );
 353+ if (strpos($value, "\n") === false && strpos($value, '"') === false) {
 354+ return sprintf ('"%s"', $value);
352355 }
353 - $exploded = explode( "\n", $value );
 356+ $exploded = explode("\n",$value);
354357 $newValue = '|';
355358 $indent += $this->_dumpIndent;
356 - $spaces = str_repeat( ' ', $indent );
357 - foreach ( $exploded as $line ) {
358 - $newValue .= "\n" . $spaces . ( $line );
 359+ $spaces = str_repeat(' ',$indent);
 360+ foreach ($exploded as $line) {
 361+ $newValue .= "\n" . $spaces . ($line);
359362 }
360363 return $newValue;
361364 }
@@ -365,16 +368,16 @@
366369 * @return string
367370 * @param $value The string you wish to fold
368371 */
369 - private function _doFolding( $value, $indent ) {
 372+ private function _doFolding($value,$indent) {
370373 // Don't do anything if wordwrap is set to 0
371374
372 - if ( $this->_dumpWordWrap !== 0 && is_string ( $value ) && strlen( $value ) > $this->_dumpWordWrap ) {
 375+ if ($this->_dumpWordWrap !== 0 && is_string ($value) && strlen($value) > $this->_dumpWordWrap) {
373376 $indent += $this->_dumpIndent;
374 - $indent = str_repeat( ' ', $indent );
375 - $wrapped = wordwrap( $value, $this->_dumpWordWrap, "\n$indent" );
376 - $value = ">\n" . $indent . $wrapped;
 377+ $indent = str_repeat(' ',$indent);
 378+ $wrapped = wordwrap($value,$this->_dumpWordWrap,"\n$indent");
 379+ $value = ">\n".$indent.$wrapped;
377380 } else {
378 - if ( $this->setting_dump_force_quotes && is_string ( $value ) )
 381+ if ($this->setting_dump_force_quotes && is_string ($value))
379382 $value = '"' . $value . '"';
380383 }
381384
@@ -384,69 +387,69 @@
385388
386389 // LOADING FUNCTIONS
387390
388 - private function __load( $input ) {
389 - $Source = $this->loadFromSource( $input );
390 - return $this->loadWithSource( $Source );
 391+ private function __load($input) {
 392+ $Source = $this->loadFromSource($input);
 393+ return $this->loadWithSource($Source);
391394 }
392395
393 - private function __loadString( $input ) {
394 - $Source = $this->loadFromString( $input );
395 - return $this->loadWithSource( $Source );
 396+ private function __loadString($input) {
 397+ $Source = $this->loadFromString($input);
 398+ return $this->loadWithSource($Source);
396399 }
397400
398 - private function loadWithSource( $Source ) {
399 - if ( empty ( $Source ) ) return array();
400 - if ( $this->setting_use_syck_is_possible && function_exists ( 'syck_load' ) ) {
401 - $array = syck_load ( implode ( '', $Source ) );
402 - return is_array( $array ) ? $array : array();
 401+ private function loadWithSource($Source) {
 402+ if (empty ($Source)) return array();
 403+ if ($this->setting_use_syck_is_possible && function_exists ('syck_load')) {
 404+ $array = syck_load (implode ('', $Source));
 405+ return is_array($array) ? $array : array();
403406 }
404407
405408 $this->path = array();
406409 $this->result = array();
407410
408 - $cnt = count( $Source );
409 - for ( $i = 0; $i < $cnt; $i++ ) {
 411+ $cnt = count($Source);
 412+ for ($i = 0; $i < $cnt; $i++) {
410413 $line = $Source[$i];
411414
412 - $this->indent = strlen( $line ) - strlen( ltrim( $line ) );
413 - $tempPath = $this->getParentPathByIndent( $this->indent );
414 - $line = self::stripIndent( $line, $this->indent );
415 - if ( self::isComment( $line ) ) continue;
416 - if ( self::isEmpty( $line ) ) continue;
 415+ $this->indent = strlen($line) - strlen(ltrim($line));
 416+ $tempPath = $this->getParentPathByIndent($this->indent);
 417+ $line = self::stripIndent($line, $this->indent);
 418+ if (self::isComment($line)) continue;
 419+ if (self::isEmpty($line)) continue;
417420 $this->path = $tempPath;
418421
419 - $literalBlockStyle = self::startsLiteralBlock( $line );
420 - if ( $literalBlockStyle ) {
421 - $line = rtrim ( $line, $literalBlockStyle . " \n" );
 422+ $literalBlockStyle = self::startsLiteralBlock($line);
 423+ if ($literalBlockStyle) {
 424+ $line = rtrim ($line, $literalBlockStyle . " \n");
422425 $literalBlock = '';
423426 $line .= $this->LiteralPlaceHolder;
424427
425 - while ( ++$i < $cnt && $this->literalBlockContinues( $Source[$i], $this->indent ) ) {
426 - $literalBlock = $this->addLiteralLine( $literalBlock, $Source[$i], $literalBlockStyle );
 428+ while (++$i < $cnt && $this->literalBlockContinues($Source[$i], $this->indent)) {
 429+ $literalBlock = $this->addLiteralLine($literalBlock, $Source[$i], $literalBlockStyle);
427430 }
428431 $i--;
429432 }
430433
431 - while ( ++$i < $cnt && self::greedilyNeedNextLine( $line ) ) {
432 - $line = rtrim ( $line, " \n\t\r" ) . ' ' . ltrim ( $Source[$i], " \t" );
 434+ while (++$i < $cnt && self::greedilyNeedNextLine($line)) {
 435+ $line = rtrim ($line, " \n\t\r") . ' ' . ltrim ($Source[$i], " \t");
433436 }
434437 $i--;
435438
436439
437440
438 - if ( strpos ( $line, '#' ) ) {
439 - if ( strpos ( $line, '"' ) === false && strpos ( $line, "'" ) === false )
440 - $line = preg_replace( '/\s+#(.+)$/', '', $line );
 441+ if (strpos ($line, '#')) {
 442+ if (strpos ($line, '"') === false && strpos ($line, "'") === false)
 443+ $line = preg_replace('/\s+#(.+)$/','',$line);
441444 }
442445
443 - $lineArray = $this->_parseLine( $line );
 446+ $lineArray = $this->_parseLine($line);
444447
445 - if ( $literalBlockStyle )
446 - $lineArray = $this->revertLiteralPlaceHolder ( $lineArray, $literalBlock );
 448+ if ($literalBlockStyle)
 449+ $lineArray = $this->revertLiteralPlaceHolder ($lineArray, $literalBlock);
447450
448 - $this->addArray( $lineArray, $this->indent );
 451+ $this->addArray($lineArray, $this->indent);
449452
450 - foreach ( $this->delayedPath as $indent => $delayedPath )
 453+ foreach ($this->delayedPath as $indent => $delayedPath)
451454 $this->path[$indent] = $delayedPath;
452455
453456 $this->delayedPath = array();
@@ -455,17 +458,17 @@
456459 return $this->result;
457460 }
458461
459 - private function loadFromSource ( $input ) {
460 - if ( !empty( $input ) && strpos( $input, "\n" ) === false && file_exists( $input ) )
461 - return file( $input );
 462+ private function loadFromSource ($input) {
 463+ if (!empty($input) && strpos($input, "\n") === false && file_exists($input))
 464+ return file($input);
462465
463 - return $this->loadFromString( $input );
 466+ return $this->loadFromString($input);
464467 }
465468
466 - private function loadFromString ( $input ) {
467 - $lines = explode( "\n", $input );
468 - foreach ( $lines as $k => $_ ) {
469 - $lines[$k] = rtrim ( $_, "\r" );
 469+ private function loadFromString ($input) {
 470+ $lines = explode("\n",$input);
 471+ foreach ($lines as $k => $_) {
 472+ $lines[$k] = rtrim ($_, "\r");
470473 }
471474 return $lines;
472475 }
@@ -476,31 +479,33 @@
477480 * @return array
478481 * @param string $line A line from the YAML file
479482 */
480 - private function _parseLine( $line ) {
481 - if ( !$line ) return array();
482 - $line = trim( $line );
483 - if ( !$line ) return array();
 483+ private function _parseLine($line) {
 484+ if (!$line) return array();
 485+ $line = trim($line);
 486+ if (!$line) return array();
484487
485 - $group = $this->nodeContainsGroup( $line );
486 - if ( $group ) {
487 - $this->addGroup( $line, $group );
488 - $line = $this->stripGroup ( $line, $group );
 488+ $array = array();
 489+
 490+ $group = $this->nodeContainsGroup($line);
 491+ if ($group) {
 492+ $this->addGroup($line, $group);
 493+ $line = $this->stripGroup ($line, $group);
489494 }
490495
491 - if ( $this->startsMappedSequence( $line ) )
492 - return $this->returnMappedSequence( $line );
 496+ if ($this->startsMappedSequence($line))
 497+ return $this->returnMappedSequence($line);
493498
494 - if ( $this->startsMappedValue( $line ) )
495 - return $this->returnMappedValue( $line );
 499+ if ($this->startsMappedValue($line))
 500+ return $this->returnMappedValue($line);
496501
497 - if ( $this->isArrayElement( $line ) )
498 - return $this->returnArrayElement( $line );
 502+ if ($this->isArrayElement($line))
 503+ return $this->returnArrayElement($line);
499504
500 - if ( $this->isPlainArray( $line ) )
501 - return $this->returnPlainArray( $line );
 505+ if ($this->isPlainArray($line))
 506+ return $this->returnPlainArray($line);
502507
503508
504 - return $this->returnKeyValuePair( $line );
 509+ return $this->returnKeyValuePair($line);
505510
506511 }
507512
@@ -510,92 +515,92 @@
511516 * @param string $value
512517 * @return mixed
513518 */
514 - private function _toType( $value ) {
515 - if ( $value === '' ) return null;
 519+ private function _toType($value) {
 520+ if ($value === '') return null;
516521 $first_character = $value[0];
517 - $last_character = substr( $value, -1, 1 );
 522+ $last_character = substr($value, -1, 1);
518523
519524 $is_quoted = false;
520525 do {
521 - if ( !$value ) break;
522 - if ( $first_character != '"' && $first_character != "'" ) break;
523 - if ( $last_character != '"' && $last_character != "'" ) break;
 526+ if (!$value) break;
 527+ if ($first_character != '"' && $first_character != "'") break;
 528+ if ($last_character != '"' && $last_character != "'") break;
524529 $is_quoted = true;
525 - } while ( 0 );
 530+ } while (0);
526531
527 - if ( $is_quoted )
528 - return strtr( substr ( $value, 1, -1 ), array ( '\\"' => '"', '\'\'' => '\'', '\\\'' => '\'' ) );
 532+ if ($is_quoted)
 533+ return strtr(substr ($value, 1, -1), array ('\\"' => '"', '\'\'' => '\'', '\\\'' => '\''));
529534
530 - if ( strpos( $value, ' #' ) !== false && !$is_quoted )
531 - $value = preg_replace( '/\s+#(.+)$/', '', $value );
 535+ if (strpos($value, ' #') !== false && !$is_quoted)
 536+ $value = preg_replace('/\s+#(.+)$/','',$value);
532537
533 - if ( !$is_quoted ) $value = str_replace( '\n', "\n", $value );
 538+ if (!$is_quoted) $value = str_replace('\n', "\n", $value);
534539
535 - if ( $first_character == '[' && $last_character == ']' ) {
 540+ if ($first_character == '[' && $last_character == ']') {
536541 // Take out strings sequences and mappings
537 - $innerValue = trim( substr ( $value, 1, -1 ) );
538 - if ( $innerValue === '' ) return array();
539 - $explode = $this->_inlineEscape( $innerValue );
 542+ $innerValue = trim(substr ($value, 1, -1));
 543+ if ($innerValue === '') return array();
 544+ $explode = $this->_inlineEscape($innerValue);
540545 // Propagate value array
541546 $value = array();
542 - foreach ( $explode as $v ) {
543 - $value[] = $this->_toType( $v );
 547+ foreach ($explode as $v) {
 548+ $value[] = $this->_toType($v);
544549 }
545550 return $value;
546551 }
547552
548 - if ( strpos( $value, ': ' ) !== false && $first_character != '{' ) {
549 - $array = explode( ': ', $value );
550 - $key = trim( $array[0] );
551 - array_shift( $array );
552 - $value = trim( implode( ': ', $array ) );
553 - $value = $this->_toType( $value );
554 - return array( $key => $value );
 553+ if (strpos($value,': ')!==false && $first_character != '{') {
 554+ $array = explode(': ',$value);
 555+ $key = trim($array[0]);
 556+ array_shift($array);
 557+ $value = trim(implode(': ',$array));
 558+ $value = $this->_toType($value);
 559+ return array($key => $value);
555560 }
556561
557 - if ( $first_character == '{' && $last_character == '}' ) {
558 - $innerValue = trim( substr ( $value, 1, -1 ) );
559 - if ( $innerValue === '' ) return array();
 562+ if ($first_character == '{' && $last_character == '}') {
 563+ $innerValue = trim(substr ($value, 1, -1));
 564+ if ($innerValue === '') return array();
560565 // Inline Mapping
561566 // Take out strings sequences and mappings
562 - $explode = $this->_inlineEscape( $innerValue );
 567+ $explode = $this->_inlineEscape($innerValue);
563568 // Propagate value array
564569 $array = array();
565 - foreach ( $explode as $v ) {
566 - $SubArr = $this->_toType( $v );
567 - if ( empty( $SubArr ) ) continue;
568 - if ( is_array ( $SubArr ) ) {
569 - $array[key( $SubArr )] = $SubArr[key( $SubArr )]; continue;
 570+ foreach ($explode as $v) {
 571+ $SubArr = $this->_toType($v);
 572+ if (empty($SubArr)) continue;
 573+ if (is_array ($SubArr)) {
 574+ $array[key($SubArr)] = $SubArr[key($SubArr)]; continue;
570575 }
571576 $array[] = $SubArr;
572577 }
573578 return $array;
574579 }
575580
576 - if ( $value == 'null' || $value == 'NULL' || $value == 'Null' || $value == '' || $value == '~' ) {
 581+ if ($value == 'null' || $value == 'NULL' || $value == 'Null' || $value == '' || $value == '~') {
577582 return null;
578583 }
579584
580 - if ( intval( $first_character ) > 0 && preg_match ( '/^[1-9]+[0-9]*$/', $value ) ) {
 585+ if (intval($first_character) > 0 && preg_match ('/^[1-9]+[0-9]*$/', $value)) {
581586 $intvalue = (int)$value;
582 - if ( $intvalue != PHP_INT_MAX )
 587+ if ($intvalue != PHP_INT_MAX)
583588 $value = $intvalue;
584589 return $value;
585590 }
586591
587 - if ( in_array( $value,
588 - array( 'true', 'on', '+', 'yes', 'y', 'True', 'TRUE', 'On', 'ON', 'YES', 'Yes', 'Y' ) ) ) {
 592+ if (in_array($value,
 593+ array('true', 'on', '+', 'yes', 'y', 'True', 'TRUE', 'On', 'ON', 'YES', 'Yes', 'Y'))) {
589594 return true;
590595 }
591596
592 - if ( in_array( strtolower( $value ),
593 - array( 'false', 'off', '-', 'no', 'n' ) ) ) {
 597+ if (in_array(strtolower($value),
 598+ array('false', 'off', '-', 'no', 'n'))) {
594599 return false;
595600 }
596601
597 - if ( is_numeric( $value ) ) {
598 - if ( $value === '0' ) return 0;
599 - if ( trim ( $value, 0 ) === $value )
 602+ if (is_numeric($value)) {
 603+ if ($value === '0') return 0;
 604+ if (trim ($value, 0) === $value)
600605 $value = (float)$value;
601606 return $value;
602607 }
@@ -608,7 +613,7 @@
609614 * @access private
610615 * @return array
611616 */
612 - private function _inlineEscape( $inline ) {
 617+ private function _inlineEscape($inline) {
613618 // There's gotta be a cleaner way to do this...
614619 // While pure sequences seem to be nesting just fine,
615620 // pure mappings and mappings with sequences inside can't go very
@@ -620,42 +625,42 @@
621626
622627 // Check for strings
623628 $regex = '/(?:(")|(?:\'))((?(1)[^"]+|[^\']+))(?(1)"|\')/';
624 - if ( preg_match_all( $regex, $inline, $strings ) ) {
 629+ if (preg_match_all($regex,$inline,$strings)) {
625630 $saved_strings = $strings[0];
626 - $inline = preg_replace( $regex, 'YAMLString', $inline );
 631+ $inline = preg_replace($regex,'YAMLString',$inline);
627632 }
628 - unset( $regex );
 633+ unset($regex);
629634
630635 $i = 0;
631636 do {
632637
633638 // Check for sequences
634 - while ( preg_match( '/\[([^{}\[\]]+)\]/U', $inline, $matchseqs ) ) {
 639+ while (preg_match('/\[([^{}\[\]]+)\]/U',$inline,$matchseqs)) {
635640 $seqs[] = $matchseqs[0];
636 - $inline = preg_replace( '/\[([^{}\[\]]+)\]/U', ( 'YAMLSeq' . ( count( $seqs ) - 1 ) . 's' ), $inline, 1 );
 641+ $inline = preg_replace('/\[([^{}\[\]]+)\]/U', ('YAMLSeq' . (count($seqs) - 1) . 's'), $inline, 1);
637642 }
638643
639644 // Check for mappings
640 - while ( preg_match( '/{([^\[\]{}]+)}/U', $inline, $matchmaps ) ) {
 645+ while (preg_match('/{([^\[\]{}]+)}/U',$inline,$matchmaps)) {
641646 $maps[] = $matchmaps[0];
642 - $inline = preg_replace( '/{([^\[\]{}]+)}/U', ( 'YAMLMap' . ( count( $maps ) - 1 ) . 's' ), $inline, 1 );
 647+ $inline = preg_replace('/{([^\[\]{}]+)}/U', ('YAMLMap' . (count($maps) - 1) . 's'), $inline, 1);
643648 }
644649
645 - if ( $i++ >= 10 ) break;
 650+ if ($i++ >= 10) break;
646651
647 - } while ( strpos ( $inline, '[' ) !== false || strpos ( $inline, '{' ) !== false );
 652+ } while (strpos ($inline, '[') !== false || strpos ($inline, '{') !== false);
648653
649 - $explode = explode( ', ', $inline );
 654+ $explode = explode(', ',$inline);
650655 $stringi = 0; $i = 0;
651656
652 - while ( 1 ) {
 657+ while (1) {
653658
654659 // Re-add the sequences
655 - if ( !empty( $seqs ) ) {
656 - foreach ( $explode as $key => $value ) {
657 - if ( strpos( $value, 'YAMLSeq' ) !== false ) {
658 - foreach ( $seqs as $seqk => $seq ) {
659 - $explode[$key] = str_replace( ( 'YAMLSeq' . $seqk . 's' ), $seq, $value );
 660+ if (!empty($seqs)) {
 661+ foreach ($explode as $key => $value) {
 662+ if (strpos($value,'YAMLSeq') !== false) {
 663+ foreach ($seqs as $seqk => $seq) {
 664+ $explode[$key] = str_replace(('YAMLSeq'.$seqk.'s'),$seq,$value);
660665 $value = $explode[$key];
661666 }
662667 }
@@ -663,11 +668,11 @@
664669 }
665670
666671 // Re-add the mappings
667 - if ( !empty( $maps ) ) {
668 - foreach ( $explode as $key => $value ) {
669 - if ( strpos( $value, 'YAMLMap' ) !== false ) {
670 - foreach ( $maps as $mapk => $map ) {
671 - $explode[$key] = str_replace( ( 'YAMLMap' . $mapk . 's' ), $map, $value );
 672+ if (!empty($maps)) {
 673+ foreach ($explode as $key => $value) {
 674+ if (strpos($value,'YAMLMap') !== false) {
 675+ foreach ($maps as $mapk => $map) {
 676+ $explode[$key] = str_replace(('YAMLMap'.$mapk.'s'), $map, $value);
672677 $value = $explode[$key];
673678 }
674679 }
@@ -676,11 +681,11 @@
677682
678683
679684 // Re-add the strings
680 - if ( !empty( $saved_strings ) ) {
681 - foreach ( $explode as $key => $value ) {
682 - while ( strpos( $value, 'YAMLString' ) !== false ) {
683 - $explode[$key] = preg_replace( '/YAMLString/', $saved_strings[$stringi], $value, 1 );
684 - unset( $saved_strings[$stringi] );
 685+ if (!empty($saved_strings)) {
 686+ foreach ($explode as $key => $value) {
 687+ while (strpos($value,'YAMLString') !== false) {
 688+ $explode[$key] = preg_replace('/YAMLString/',$saved_strings[$stringi],$value, 1);
 689+ unset($saved_strings[$stringi]);
685690 ++$stringi;
686691 $value = $explode[$key];
687692 }
@@ -688,72 +693,72 @@
689694 }
690695
691696 $finished = true;
692 - foreach ( $explode as $key => $value ) {
693 - if ( strpos( $value, 'YAMLSeq' ) !== false ) {
 697+ foreach ($explode as $key => $value) {
 698+ if (strpos($value,'YAMLSeq') !== false) {
694699 $finished = false; break;
695700 }
696 - if ( strpos( $value, 'YAMLMap' ) !== false ) {
 701+ if (strpos($value,'YAMLMap') !== false) {
697702 $finished = false; break;
698703 }
699 - if ( strpos( $value, 'YAMLString' ) !== false ) {
 704+ if (strpos($value,'YAMLString') !== false) {
700705 $finished = false; break;
701706 }
702707 }
703 - if ( $finished ) break;
 708+ if ($finished) break;
704709
705710 $i++;
706 - if ( $i > 10 )
 711+ if ($i > 10)
707712 break; // Prevent infinite loops.
708713 }
709714
710715 return $explode;
711716 }
712717
713 - private function literalBlockContinues ( $line, $lineIndent ) {
714 - if ( !trim( $line ) ) return true;
715 - if ( strlen( $line ) - strlen( ltrim( $line ) ) > $lineIndent ) return true;
 718+ private function literalBlockContinues ($line, $lineIndent) {
 719+ if (!trim($line)) return true;
 720+ if (strlen($line) - strlen(ltrim($line)) > $lineIndent) return true;
716721 return false;
717722 }
718723
719 - private function referenceContentsByAlias ( $alias ) {
 724+ private function referenceContentsByAlias ($alias) {
720725 do {
721 - if ( !isset( $this->SavedGroups[$alias] ) ) { echo "Bad group name: $alias."; break; }
 726+ if (!isset($this->SavedGroups[$alias])) { echo "Bad group name: $alias."; break; }
722727 $groupPath = $this->SavedGroups[$alias];
723728 $value = $this->result;
724 - foreach ( $groupPath as $k ) {
 729+ foreach ($groupPath as $k) {
725730 $value = $value[$k];
726731 }
727 - } while ( false );
 732+ } while (false);
728733 return $value;
729734 }
730735
731 - private function addArrayInline ( $array, $indent ) {
 736+ private function addArrayInline ($array, $indent) {
732737 $CommonGroupPath = $this->path;
733 - if ( empty ( $array ) ) return false;
 738+ if (empty ($array)) return false;
734739
735 - foreach ( $array as $k => $_ ) {
736 - $this->addArray( array( $k => $_ ), $indent );
 740+ foreach ($array as $k => $_) {
 741+ $this->addArray(array($k => $_), $indent);
737742 $this->path = $CommonGroupPath;
738743 }
739744 return true;
740745 }
741746
742 - private function addArray ( $incoming_data, $incoming_indent ) {
 747+ private function addArray ($incoming_data, $incoming_indent) {
743748
744749 // print_r ($incoming_data);
745750
746 - if ( count ( $incoming_data ) > 1 )
747 - return $this->addArrayInline ( $incoming_data, $incoming_indent );
 751+ if (count ($incoming_data) > 1)
 752+ return $this->addArrayInline ($incoming_data, $incoming_indent);
748753
749 - $key = key ( $incoming_data );
750 - $value = isset( $incoming_data[$key] ) ? $incoming_data[$key] : null;
751 - if ( $key === '__!YAMLZero' ) $key = '0';
 754+ $key = key ($incoming_data);
 755+ $value = isset($incoming_data[$key]) ? $incoming_data[$key] : null;
 756+ if ($key === '__!YAMLZero') $key = '0';
752757
753 - if ( $incoming_indent == 0 && !$this->_containsGroupAlias && !$this->_containsGroupAnchor ) { // Shortcut for root-level values.
754 - if ( $key || $key === '' || $key === '0' ) {
 758+ if ($incoming_indent == 0 && !$this->_containsGroupAlias && !$this->_containsGroupAnchor) { // Shortcut for root-level values.
 759+ if ($key || $key === '' || $key === '0') {
755760 $this->result[$key] = $value;
756761 } else {
757 - $this->result[] = $value; end ( $this->result ); $key = key ( $this->result );
 762+ $this->result[] = $value; end ($this->result); $key = key ($this->result);
758763 }
759764 $this->path[$incoming_indent] = $key;
760765 return;
@@ -764,44 +769,47 @@
765770 $history = array();
766771 // Unfolding inner array tree.
767772 $history[] = $_arr = $this->result;
768 - foreach ( $this->path as $k ) {
 773+ foreach ($this->path as $k) {
769774 $history[] = $_arr = $_arr[$k];
770775 }
771776
772 - if ( $this->_containsGroupAlias ) {
773 - $value = $this->referenceContentsByAlias( $this->_containsGroupAlias );
 777+ if ($this->_containsGroupAlias) {
 778+ $value = $this->referenceContentsByAlias($this->_containsGroupAlias);
774779 $this->_containsGroupAlias = false;
775780 }
776781
777782
778783 // Adding string or numeric key to the innermost level or $this->arr.
779 - if ( is_string( $key ) && $key == '<<' ) {
780 - if ( !is_array ( $_arr ) ) { $_arr = array (); }
 784+ if (is_string($key) && $key == '<<') {
 785+ if (!is_array ($_arr)) { $_arr = array (); }
781786
782 - $_arr = array_merge ( $_arr, $value );
783 - } else if ( $key || $key === '' || $key === '0' ) {
784 - $_arr[$key] = $value;
 787+ $_arr = array_merge ($_arr, $value);
 788+ } else if ($key || $key === '' || $key === '0') {
 789+ if (!is_array ($_arr))
 790+ $_arr = array ($key=>$value);
 791+ else
 792+ $_arr[$key] = $value;
785793 } else {
786 - if ( !is_array ( $_arr ) ) { $_arr = array ( $value ); $key = 0; }
787 - else { $_arr[] = $value; end ( $_arr ); $key = key ( $_arr ); }
 794+ if (!is_array ($_arr)) { $_arr = array ($value); $key = 0; }
 795+ else { $_arr[] = $value; end ($_arr); $key = key ($_arr); }
788796 }
789797
790 - $reverse_path = array_reverse( $this->path );
791 - $reverse_history = array_reverse ( $history );
 798+ $reverse_path = array_reverse($this->path);
 799+ $reverse_history = array_reverse ($history);
792800 $reverse_history[0] = $_arr;
793 - $cnt = count( $reverse_history ) - 1;
794 - for ( $i = 0; $i < $cnt; $i++ ) {
795 - $reverse_history[$i + 1][$reverse_path[$i]] = $reverse_history[$i];
 801+ $cnt = count($reverse_history) - 1;
 802+ for ($i = 0; $i < $cnt; $i++) {
 803+ $reverse_history[$i+1][$reverse_path[$i]] = $reverse_history[$i];
796804 }
797805 $this->result = $reverse_history[$cnt];
798806
799807 $this->path[$incoming_indent] = $key;
800808
801 - if ( $this->_containsGroupAnchor ) {
 809+ if ($this->_containsGroupAnchor) {
802810 $this->SavedGroups[$this->_containsGroupAnchor] = $this->path;
803 - if ( is_array ( $value ) ) {
804 - $k = key ( $value );
805 - if ( !is_int ( $k ) ) {
 811+ if (is_array ($value)) {
 812+ $k = key ($value);
 813+ if (!is_int ($k)) {
806814 $this->SavedGroups[$this->_containsGroupAnchor][$incoming_indent + 2] = $k;
807815 }
808816 }
@@ -810,209 +818,209 @@
811819
812820 }
813821
814 - private static function startsLiteralBlock ( $line ) {
815 - $lastChar = substr ( trim( $line ), -1 );
816 - if ( $lastChar != '>' && $lastChar != '|' ) return false;
817 - if ( $lastChar == '|' ) return $lastChar;
 822+ private static function startsLiteralBlock ($line) {
 823+ $lastChar = substr (trim($line), -1);
 824+ if ($lastChar != '>' && $lastChar != '|') return false;
 825+ if ($lastChar == '|') return $lastChar;
818826 // HTML tags should not be counted as literal blocks.
819 - if ( preg_match ( '#<.*?>$#', $line ) ) return false;
 827+ if (preg_match ('#<.*?>$#', $line)) return false;
820828 return $lastChar;
821829 }
822830
823 - private static function greedilyNeedNextLine( $line ) {
824 - $line = trim ( $line );
825 - if ( !strlen( $line ) ) return false;
826 - if ( substr ( $line, -1, 1 ) == ']' ) return false;
827 - if ( $line[0] == '[' ) return true;
828 - if ( preg_match ( '#^[^:]+?:\s*\[#', $line ) ) return true;
 831+ private static function greedilyNeedNextLine($line) {
 832+ $line = trim ($line);
 833+ if (!strlen($line)) return false;
 834+ if (substr ($line, -1, 1) == ']') return false;
 835+ if ($line[0] == '[') return true;
 836+ if (preg_match ('#^[^:]+?:\s*\[#', $line)) return true;
829837 return false;
830838 }
831839
832 - private function addLiteralLine ( $literalBlock, $line, $literalBlockStyle ) {
833 - $line = self::stripIndent( $line );
834 - $line = rtrim ( $line, "\r\n\t " ) . "\n";
835 - if ( $literalBlockStyle == '|' ) {
 840+ private function addLiteralLine ($literalBlock, $line, $literalBlockStyle) {
 841+ $line = self::stripIndent($line);
 842+ $line = rtrim ($line, "\r\n\t ") . "\n";
 843+ if ($literalBlockStyle == '|') {
836844 return $literalBlock . $line;
837845 }
838 - if ( strlen( $line ) == 0 )
839 - return rtrim( $literalBlock, ' ' ) . "\n";
840 - if ( $line == "\n" && $literalBlockStyle == '>' ) {
841 - return rtrim ( $literalBlock, " \t" ) . "\n";
 846+ if (strlen($line) == 0)
 847+ return rtrim($literalBlock, ' ') . "\n";
 848+ if ($line == "\n" && $literalBlockStyle == '>') {
 849+ return rtrim ($literalBlock, " \t") . "\n";
842850 }
843 - if ( $line != "\n" )
844 - $line = trim ( $line, "\r\n " ) . " ";
 851+ if ($line != "\n")
 852+ $line = trim ($line, "\r\n ") . " ";
845853 return $literalBlock . $line;
846854 }
847855
848 - function revertLiteralPlaceHolder ( $lineArray, $literalBlock ) {
849 - foreach ( $lineArray as $k => $_ ) {
850 - if ( is_array( $_ ) )
851 - $lineArray[$k] = $this->revertLiteralPlaceHolder ( $_, $literalBlock );
852 - else if ( substr( $_, -1 * strlen ( $this->LiteralPlaceHolder ) ) == $this->LiteralPlaceHolder )
853 - $lineArray[$k] = rtrim ( $literalBlock, " \r\n" );
 856+ function revertLiteralPlaceHolder ($lineArray, $literalBlock) {
 857+ foreach ($lineArray as $k => $_) {
 858+ if (is_array($_))
 859+ $lineArray[$k] = $this->revertLiteralPlaceHolder ($_, $literalBlock);
 860+ else if (substr($_, -1 * strlen ($this->LiteralPlaceHolder)) == $this->LiteralPlaceHolder)
 861+ $lineArray[$k] = rtrim ($literalBlock, " \r\n");
854862 }
855863 return $lineArray;
856864 }
857865
858 - private static function stripIndent ( $line, $indent = -1 ) {
859 - if ( $indent == -1 ) $indent = strlen( $line ) - strlen( ltrim( $line ) );
860 - return substr ( $line, $indent );
 866+ private static function stripIndent ($line, $indent = -1) {
 867+ if ($indent == -1) $indent = strlen($line) - strlen(ltrim($line));
 868+ return substr ($line, $indent);
861869 }
862870
863 - private function getParentPathByIndent ( $indent ) {
864 - if ( $indent == 0 ) return array();
 871+ private function getParentPathByIndent ($indent) {
 872+ if ($indent == 0) return array();
865873 $linePath = $this->path;
866874 do {
867 - end( $linePath ); $lastIndentInParentPath = key( $linePath );
868 - if ( $indent <= $lastIndentInParentPath ) array_pop ( $linePath );
869 - } while ( $indent <= $lastIndentInParentPath );
 875+ end($linePath); $lastIndentInParentPath = key($linePath);
 876+ if ($indent <= $lastIndentInParentPath) array_pop ($linePath);
 877+ } while ($indent <= $lastIndentInParentPath);
870878 return $linePath;
871879 }
872880
873881
874 - private function clearBiggerPathValues ( $indent ) {
 882+ private function clearBiggerPathValues ($indent) {
875883
876884
877 - if ( $indent == 0 ) $this->path = array();
878 - if ( empty ( $this->path ) ) return true;
 885+ if ($indent == 0) $this->path = array();
 886+ if (empty ($this->path)) return true;
879887
880 - foreach ( $this->path as $k => $_ ) {
881 - if ( $k > $indent ) unset ( $this->path[$k] );
 888+ foreach ($this->path as $k => $_) {
 889+ if ($k > $indent) unset ($this->path[$k]);
882890 }
883891
884892 return true;
885893 }
886894
887895
888 - private static function isComment ( $line ) {
889 - if ( !$line ) return false;
890 - if ( $line[0] == '#' ) return true;
891 - if ( trim( $line, " \r\n\t" ) == '---' ) return true;
 896+ private static function isComment ($line) {
 897+ if (!$line) return false;
 898+ if ($line[0] == '#') return true;
 899+ if (trim($line, " \r\n\t") == '---') return true;
892900 return false;
893901 }
894902
895 - private static function isEmpty ( $line ) {
896 - return ( trim ( $line ) === '' );
 903+ private static function isEmpty ($line) {
 904+ return (trim ($line) === '');
897905 }
898906
899907
900 - private function isArrayElement ( $line ) {
901 - if ( !$line ) return false;
902 - if ( $line[0] != '-' ) return false;
903 - if ( strlen ( $line ) > 3 )
904 - if ( substr( $line, 0, 3 ) == '---' ) return false;
 908+ private function isArrayElement ($line) {
 909+ if (!$line) return false;
 910+ if ($line[0] != '-') return false;
 911+ if (strlen ($line) > 3)
 912+ if (substr($line,0,3) == '---') return false;
905913
906914 return true;
907915 }
908916
909 - private function isHashElement ( $line ) {
910 - return strpos( $line, ':' );
 917+ private function isHashElement ($line) {
 918+ return strpos($line, ':');
911919 }
912920
913 - private function isLiteral ( $line ) {
914 - if ( $this->isArrayElement( $line ) ) return false;
915 - if ( $this->isHashElement( $line ) ) return false;
 921+ private function isLiteral ($line) {
 922+ if ($this->isArrayElement($line)) return false;
 923+ if ($this->isHashElement($line)) return false;
916924 return true;
917925 }
918926
919927
920 - private static function unquote ( $value ) {
921 - if ( !$value ) return $value;
922 - if ( !is_string( $value ) ) return $value;
923 - if ( $value[0] == '\'' ) return trim ( $value, '\'' );
924 - if ( $value[0] == '"' ) return trim ( $value, '"' );
 928+ private static function unquote ($value) {
 929+ if (!$value) return $value;
 930+ if (!is_string($value)) return $value;
 931+ if ($value[0] == '\'') return trim ($value, '\'');
 932+ if ($value[0] == '"') return trim ($value, '"');
925933 return $value;
926934 }
927935
928 - private function startsMappedSequence ( $line ) {
929 - return ( $line[0] == '-' && substr ( $line, -1, 1 ) == ':' );
 936+ private function startsMappedSequence ($line) {
 937+ return ($line[0] == '-' && substr ($line, -1, 1) == ':');
930938 }
931939
932 - private function returnMappedSequence ( $line ) {
 940+ private function returnMappedSequence ($line) {
933941 $array = array();
934 - $key = self::unquote( trim( substr( $line, 1, -1 ) ) );
 942+ $key = self::unquote(trim(substr($line,1,-1)));
935943 $array[$key] = array();
936 - $this->delayedPath = array( strpos ( $line, $key ) + $this->indent => $key );
937 - return array( $array );
 944+ $this->delayedPath = array(strpos ($line, $key) + $this->indent => $key);
 945+ return array($array);
938946 }
939947
940 - private function returnMappedValue ( $line ) {
 948+ private function returnMappedValue ($line) {
941949 $array = array();
942 - $key = self::unquote ( trim( substr( $line, 0, -1 ) ) );
 950+ $key = self::unquote (trim(substr($line,0,-1)));
943951 $array[$key] = '';
944952 return $array;
945953 }
946954
947 - private function startsMappedValue ( $line ) {
948 - return ( substr ( $line, -1, 1 ) == ':' );
 955+ private function startsMappedValue ($line) {
 956+ return (substr ($line, -1, 1) == ':');
949957 }
950958
951 - private function isPlainArray ( $line ) {
952 - return ( $line[0] == '[' && substr ( $line, -1, 1 ) == ']' );
 959+ private function isPlainArray ($line) {
 960+ return ($line[0] == '[' && substr ($line, -1, 1) == ']');
953961 }
954962
955 - private function returnPlainArray ( $line ) {
956 - return $this->_toType( $line );
957 - }
 963+ private function returnPlainArray ($line) {
 964+ return $this->_toType($line);
 965+ }
958966
959 - private function returnKeyValuePair ( $line ) {
 967+ private function returnKeyValuePair ($line) {
960968 $array = array();
961969 $key = '';
962 - if ( strpos ( $line, ':' ) ) {
 970+ if (strpos ($line, ':')) {
963971 // It's a key/value pair most likely
964972 // If the key is in double quotes pull it out
965 - if ( ( $line[0] == '"' || $line[0] == "'" ) && preg_match( '/^(["\'](.*)["\'](\s)*:)/', $line, $matches ) ) {
966 - $value = trim( str_replace( $matches[1], '', $line ) );
 973+ if (($line[0] == '"' || $line[0] == "'") && preg_match('/^(["\'](.*)["\'](\s)*:)/',$line,$matches)) {
 974+ $value = trim(str_replace($matches[1],'',$line));
967975 $key = $matches[2];
968976 } else {
969977 // Do some guesswork as to the key and the value
970 - $explode = explode( ':', $line );
971 - $key = trim( $explode[0] );
972 - array_shift( $explode );
973 - $value = trim( implode( ':', $explode ) );
 978+ $explode = explode(':',$line);
 979+ $key = trim($explode[0]);
 980+ array_shift($explode);
 981+ $value = trim(implode(':',$explode));
974982 }
975983 // Set the type of the value. Int, string, etc
976 - $value = $this->_toType( $value );
977 - if ( $key === '0' ) $key = '__!YAMLZero';
 984+ $value = $this->_toType($value);
 985+ if ($key === '0') $key = '__!YAMLZero';
978986 $array[$key] = $value;
979987 } else {
980 - $array = array ( $line );
 988+ $array = array ($line);
981989 }
982990 return $array;
983991
984992 }
985993
986994
987 - private function returnArrayElement ( $line ) {
988 - if ( strlen( $line ) <= 1 ) return array( array() ); // Weird %)
 995+ private function returnArrayElement ($line) {
 996+ if (strlen($line) <= 1) return array(array()); // Weird %)
989997 $array = array();
990 - $value = trim( substr( $line, 1 ) );
991 - $value = $this->_toType( $value );
 998+ $value = trim(substr($line,1));
 999+ $value = $this->_toType($value);
9921000 $array[] = $value;
9931001 return $array;
9941002 }
9951003
9961004
997 - private function nodeContainsGroup ( $line ) {
 1005+ private function nodeContainsGroup ($line) {
9981006 $symbolsForReference = 'A-z0-9_\-';
999 - if ( strpos( $line, '&' ) === false && strpos( $line, '*' ) === false ) return false; // Please die fast ;-)
1000 - if ( $line[0] == '&' && preg_match( '/^(&[' . $symbolsForReference . ']+)/', $line, $matches ) ) return $matches[1];
1001 - if ( $line[0] == '*' && preg_match( '/^(\*[' . $symbolsForReference . ']+)/', $line, $matches ) ) return $matches[1];
1002 - if ( preg_match( '/(&[' . $symbolsForReference . ']+)$/', $line, $matches ) ) return $matches[1];
1003 - if ( preg_match( '/(\*[' . $symbolsForReference . ']+$)/', $line, $matches ) ) return $matches[1];
1004 - if ( preg_match ( '#^\s*<<\s*:\s*(\*[^\s]+).*$#', $line, $matches ) ) return $matches[1];
 1007+ if (strpos($line, '&') === false && strpos($line, '*') === false) return false; // Please die fast ;-)
 1008+ if ($line[0] == '&' && preg_match('/^(&['.$symbolsForReference.']+)/', $line, $matches)) return $matches[1];
 1009+ if ($line[0] == '*' && preg_match('/^(\*['.$symbolsForReference.']+)/', $line, $matches)) return $matches[1];
 1010+ if (preg_match('/(&['.$symbolsForReference.']+)$/', $line, $matches)) return $matches[1];
 1011+ if (preg_match('/(\*['.$symbolsForReference.']+$)/', $line, $matches)) return $matches[1];
 1012+ if (preg_match ('#^\s*<<\s*:\s*(\*[^\s]+).*$#', $line, $matches)) return $matches[1];
10051013 return false;
10061014
10071015 }
10081016
1009 - private function addGroup ( $line, $group ) {
1010 - if ( $group[0] == '&' ) $this->_containsGroupAnchor = substr ( $group, 1 );
1011 - if ( $group[0] == '*' ) $this->_containsGroupAlias = substr ( $group, 1 );
1012 - // print_r ($this->path);
 1017+ private function addGroup ($line, $group) {
 1018+ if ($group[0] == '&') $this->_containsGroupAnchor = substr ($group, 1);
 1019+ if ($group[0] == '*') $this->_containsGroupAlias = substr ($group, 1);
 1020+ //print_r ($this->path);
10131021 }
10141022
1015 - private function stripGroup ( $line, $group ) {
1016 - $line = trim( str_replace( $group, '', $line ) );
 1023+ private function stripGroup ($line, $group) {
 1024+ $line = trim(str_replace($group, '', $line));
10171025 return $line;
10181026 }
10191027 }
@@ -1020,13 +1028,13 @@
10211029 // Enable use of Spyc from command line
10221030 // The syntax is the following: php spyc.php spyc.yaml
10231031
1024 -define ( 'SPYC_FROM_COMMAND_LINE', false );
 1032+define ('SPYC_FROM_COMMAND_LINE', false);
10251033
10261034 do {
1027 - if ( !SPYC_FROM_COMMAND_LINE ) break;
1028 - if ( empty ( $_SERVER['argc'] ) || $_SERVER['argc'] < 2 ) break;
1029 - if ( empty ( $_SERVER['PHP_SELF'] ) || $_SERVER['PHP_SELF'] != 'spyc.php' ) break;
 1035+ if (!SPYC_FROM_COMMAND_LINE) break;
 1036+ if (empty ($_SERVER['argc']) || $_SERVER['argc'] < 2) break;
 1037+ if (empty ($_SERVER['PHP_SELF']) || $_SERVER['PHP_SELF'] != 'spyc.php') break;
10301038 $file = $argv[1];
1031 - printf ( "Spyc loading file: %s\n", $file );
1032 - print_r ( spyc_load_file ( $file ) );
1033 -} while ( 0 );
\ No newline at end of file
 1039+ printf ("Spyc loading file: %s\n", $file);
 1040+ print_r (spyc_load_file ($file));
 1041+} while (0);
\ No newline at end of file

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r91Prevent diff pages from being cached; paranoid HTML escaping on hoversvibber03:51, 8 February 2002

Status & tagging log