Tweak the basicio parser so that it properly handles multi-value

lines with hashes (lines like symbol [hash] [hash] are still not
handled, but aren't outputted from any command either as of now).
This commit is contained in:
Thomas Keller 2010-10-04 15:20:53 +00:00
parent 0c575ccc74
commit 90edbf0d8b

View File

@ -68,17 +68,30 @@ class IDF_Scm_Monotone_BasicIO
{ {
unset($stanzaLine['hash']); unset($stanzaLine['hash']);
$valCount = 0; $valCount = 0;
while ($in[$pos] == '"') { // if hashs and plain values are encountered in the same
++$pos; // opening quote // value list, we add the hash values as simple values as well
while ($in[$pos] == '"' || $in[$pos] == '[') {
$isHashValue = $in[$pos] == '[';
++$pos; // opening quote / bracket
$stanzaLine['values'][$valCount] = ''; $stanzaLine['values'][$valCount] = '';
while ($pos < $length) { while ($pos < $length) {
$ch = $in[$pos]; $pr = $in[$pos-1]; $ch = $in[$pos]; $pr = $in[$pos-1];
if ($ch == '"' && $pr != '\\') break; if (($isHashValue && $ch == ']')
||(!$isHashValue && $ch == '"' && $pr != '\\'))
break;
++$pos; ++$pos;
$stanzaLine['values'][$valCount] .= $ch; $stanzaLine['values'][$valCount] .= $ch;
} }
++$pos; // closing quote ++$pos; // closing quote
if (!$isHashValue) {
$stanzaLine['values'][$valCount] = str_replace(
array("\\\\", "\\\""),
array("\\", "\""),
$stanzaLine['values'][$valCount]
);
}
if ($pos >= $length) if ($pos >= $length)
break; break;
@ -87,14 +100,6 @@ class IDF_Scm_Monotone_BasicIO
++$valCount; ++$valCount;
} }
} }
for ($i = 0; $i <= $valCount; $i++) {
$stanzaLine['values'][$i] = str_replace(
array("\\\\", "\\\""),
array("\\", "\""),
$stanzaLine['values'][$i]
);
}
} }
$stanza[] = $stanzaLine; $stanza[] = $stanzaLine;