r90698 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r90697‎ | r90698 | r90699 >
Date:09:27, 24 June 2011
Author:nikerabbit
Status:ok
Tags:
Comment:
Update spyc lib to latest version
Modified paths:
  • /trunk/extensions/Translate/spyc/spyc.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Translate/spyc/spyc.php
@@ -1,11 +1,11 @@
22 <?php
33 /**
44 * Spyc -- A Simple PHP YAML Class
5 - * @version 0.4.5-svn
 5+ * @version 0.5
66 * @author Vlad Andersen <vlad.andersen@gmail.com>
77 * @author Chris Wanstrath <chris@ozmm.org>
88 * @link http://code.google.com/p/spyc/
9 - * @copyright Copyright 2005-2006 Chris Wanstrath, 2006-2009 Vlad Andersen
 9+ * @copyright Copyright 2005-2006 Chris Wanstrath, 2006-2011 Vlad Andersen
1010 * @license http://www.opensource.org/licenses/mit-license.php MIT License
1111 * @package Spyc
1212 */
@@ -58,10 +58,12 @@
5959
6060 // SETTINGS
6161
 62+ const REMPTY = "\0\0\0\0\0";
 63+
6264 /**
6365 * Setting this to true will force YAMLDump to enclose any string value in
6466 * quotes. False by default.
65 - *
 67+ *
6668 * @var bool
6769 */
6870 public $setting_dump_force_quotes = false;
@@ -141,7 +143,7 @@
142144 /**
143145 * Load a string of YAML into a PHP array statically
144146 *
145 - * The load method, when supplied with a YAML string, will do its best
 147+ * The load method, when supplied with a YAML string, will do its best
146148 * to convert YAML in a string into a PHP array. Pretty simple.
147149 *
148150 * Note: use this function if you don't want files from the file system
@@ -230,7 +232,7 @@
231233
232234 // Start at the base of the array and move through it.
233235 if ($array) {
234 - $array = (array)$array;
 236+ $array = (array)$array;
235237 $previous_key = -1;
236238 foreach ($array as $key => $value) {
237239 if (!isset($first_key)) $first_key = $key;
@@ -255,7 +257,7 @@
256258 return $this->_dumpNode($key, array(), $indent, $previous_key, $first_key, $source_array);
257259 // It has children. What to do?
258260 // Make it the right kind of item
259 - $string = $this->_dumpNode($key, NULL, $indent, $previous_key, $first_key, $source_array);
 261+ $string = $this->_dumpNode($key, self::REMPTY, $indent, $previous_key, $first_key, $source_array);
260262 // Add the indent
261263 $indent += $this->_dumpIndent;
262264 // Yamlize the array
@@ -319,6 +321,9 @@
320322 if (is_bool($value)) {
321323 $value = ($value) ? "true" : "false";
322324 }
 325+
 326+ if ($value === null) $value = 'null';
 327+ if ($value === "'" . self::REMPTY . "'") $value = null;
323328
324329 $spaces = str_repeat(' ',$indent);
325330
@@ -375,7 +380,7 @@
376381 $wrapped = wordwrap($value,$this->_dumpWordWrap,"\n$indent");
377382 $value = ">\n".$indent.$wrapped;
378383 } else {
379 - if ($this->setting_dump_force_quotes && is_string ($value))
 384+ if ($this->setting_dump_force_quotes && is_string ($value) && $value !== self::REMPTY)
380385 $value = '"' . $value . '"';
381386 }
382387
@@ -408,7 +413,7 @@
409414 $cnt = count($Source);
410415 for ($i = 0; $i < $cnt; $i++) {
411416 $line = $Source[$i];
412 -
 417+
413418 $this->indent = strlen($line) - strlen(ltrim($line));
414419 $tempPath = $this->getParentPathByIndent($this->indent);
415420 $line = self::stripIndent($line, $this->indent);
@@ -421,9 +426,9 @@
422427 $line = rtrim ($line, $literalBlockStyle . " \n");
423428 $literalBlock = '';
424429 $line .= $this->LiteralPlaceHolder;
425 -
 430+ $literal_block_indent = strlen($Source[$i+1]) - strlen(ltrim($Source[$i+1]));
426431 while (++$i < $cnt && $this->literalBlockContinues($Source[$i], $this->indent)) {
427 - $literalBlock = $this->addLiteralLine($literalBlock, $Source[$i], $literalBlockStyle);
 432+ $literalBlock = $this->addLiteralLine($literalBlock, $Source[$i], $literalBlockStyle, $literal_block_indent);
428433 }
429434 $i--;
430435 }
@@ -500,9 +505,9 @@
501506 return $this->returnArrayElement($line);
502507
503508 if ($this->isPlainArray($line))
504 - return $this->returnPlainArray($line);
505 -
506 -
 509+ return $this->returnPlainArray($line);
 510+
 511+
507512 return $this->returnKeyValuePair($line);
508513
509514 }
@@ -528,7 +533,7 @@
529534
530535 if ($is_quoted)
531536 return strtr(substr ($value, 1, -1), array ('\\"' => '"', '\'\'' => '\'', '\\\'' => '\''));
532 -
 537+
533538 if (strpos($value, ' #') !== false && !$is_quoted)
534539 $value = preg_replace('/\s+#(.+)$/','',$value);
535540
@@ -555,7 +560,7 @@
556561 $value = $this->_toType($value);
557562 return array($key => $value);
558563 }
559 -
 564+
560565 if ($first_character == '{' && $last_character == '}') {
561566 $innerValue = trim(substr ($value, 1, -1));
562567 if ($innerValue === '') return array();
@@ -602,7 +607,7 @@
603608 $value = (float)$value;
604609 return $value;
605610 }
606 -
 611+
607612 return $value;
608613 }
609614
@@ -705,7 +710,7 @@
706711 if ($finished) break;
707712
708713 $i++;
709 - if ($i > 10)
 714+ if ($i > 10)
710715 break; // Prevent infinite loops.
711716 }
712717
@@ -733,7 +738,7 @@
734739 private function addArrayInline ($array, $indent) {
735740 $CommonGroupPath = $this->path;
736741 if (empty ($array)) return false;
737 -
 742+
738743 foreach ($array as $k => $_) {
739744 $this->addArray(array($k => $_), $indent);
740745 $this->path = $CommonGroupPath;
@@ -747,7 +752,7 @@
748753
749754 if (count ($incoming_data) > 1)
750755 return $this->addArrayInline ($incoming_data, $incoming_indent);
751 -
 756+
752757 $key = key ($incoming_data);
753758 $value = isset($incoming_data[$key]) ? $incoming_data[$key] : null;
754759 if ($key === '__!YAMLZero') $key = '0';
@@ -763,7 +768,7 @@
764769 }
765770
766771
767 -
 772+
768773 $history = array();
769774 // Unfolding inner array tree.
770775 $history[] = $_arr = $this->result;
@@ -782,7 +787,7 @@
783788 if (!is_array ($_arr)) { $_arr = array (); }
784789
785790 $_arr = array_merge ($_arr, $value);
786 - } elseif ($key || $key === '' || $key === '0') {
 791+ } else if ($key || $key === '' || $key === '0') {
787792 if (!is_array ($_arr))
788793 $_arr = array ($key=>$value);
789794 else
@@ -834,8 +839,11 @@
835840 return false;
836841 }
837842
838 - private function addLiteralLine ($literalBlock, $line, $literalBlockStyle) {
839 - $line = self::stripIndent($line);
 843+ private function addLiteralLine ($literalBlock, $line, $literalBlockStyle, $indent = -1) {
 844+ $line = self::stripIndent($line, $indent);
 845+ if ($literalBlockStyle !== '|') {
 846+ $line = self::stripIndent($line);
 847+ }
840848 $line = rtrim ($line, "\r\n\t ") . "\n";
841849 if ($literalBlockStyle == '|') {
842850 return $literalBlock . $line;
@@ -854,8 +862,8 @@
855863 foreach ($lineArray as $k => $_) {
856864 if (is_array($_))
857865 $lineArray[$k] = $this->revertLiteralPlaceHolder ($_, $literalBlock);
858 - elseif (substr($_, -1 * strlen ($this->LiteralPlaceHolder)) == $this->LiteralPlaceHolder)
859 - $lineArray[$k] = rtrim ($literalBlock, " \r\n");
 866+ else if (substr($_, -1 * strlen ($this->LiteralPlaceHolder)) == $this->LiteralPlaceHolder)
 867+ $lineArray[$k] = rtrim ($literalBlock, " \r\n");
860868 }
861869 return $lineArray;
862870 }
@@ -907,7 +915,7 @@
908916 if ($line[0] != '-') return false;
909917 if (strlen ($line) > 3)
910918 if (substr($line,0,3) == '---') return false;
911 -
 919+
912920 return true;
913921 }
914922
@@ -952,14 +960,14 @@
953961 private function startsMappedValue ($line) {
954962 return (substr ($line, -1, 1) == ':');
955963 }
956 -
 964+
957965 private function isPlainArray ($line) {
958966 return ($line[0] == '[' && substr ($line, -1, 1) == ']');
959967 }
960 -
 968+
961969 private function returnPlainArray ($line) {
962 - return $this->_toType($line);
963 - }
 970+ return $this->_toType($line);
 971+ }
964972
965973 private function returnKeyValuePair ($line) {
966974 $array = array();
@@ -999,7 +1007,7 @@
10001008 }
10011009
10021010
1003 - private function nodeContainsGroup ($line) {
 1011+ private function nodeContainsGroup ($line) {
10041012 $symbolsForReference = 'A-z0-9_\-';
10051013 if (strpos($line, '&') === false && strpos($line, '*') === false) return false; // Please die fast ;-)
10061014 if ($line[0] == '&' && preg_match('/^(&['.$symbolsForReference.']+)/', $line, $matches)) return $matches[1];

Status & tagging log