MDL-26229 restore - parser improvements (repetitions and skipped tags)

This commit is contained in:
Eloy Lafuente (stronk7)
2011-02-12 02:19:02 +01:00
parent d911c72bf9
commit 5539e69862
3 changed files with 23 additions and 5 deletions
@@ -104,13 +104,18 @@ abstract class simplified_parser_processor extends progressive_parser_processor
$alltagswhitespace = false;
continue;
}
// If the path including the tag name matches another selected path
// (registered or parent) delete it, another chunk will contain that info
// (registered or parent) and is null or begins with linefeed, we know it's part
// of another chunk, delete it, another chunk will contain that info
if ($this->path_is_selected($path . '/' . $key) ||
$this->path_is_selected_parent($path . '/' . $key)) {
unset($data['tags'][$key]);
continue;
if (!isset($value['cdata']) || substr($value['cdata'], 0, 1) === "\n") {
unset($data['tags'][$key]);
continue;
}
}
// Convert to simple name => value array
$data['tags'][$key] = isset($value['cdata']) ? $value['cdata'] : null;
@@ -201,7 +201,12 @@ class progressive_parser {
// Entering a new inner level, publish all the information available
if ($this->level > $this->prevlevel) {
if (!empty($this->currtag) && (!empty($this->currtag['attrs']) || !empty($this->currtag['cdata']))) {
$this->topush['tags'][$this->currtag['name']] = $this->currtag;
// We always add the last not-empty repetition. Empty ones are ignored.
if (isset($this->topush['tags'][$this->currtag['name']]) && trim($this->currtag['cdata']) === '') {
// Do nothing, the tag already exists and the repetition is empty
} else {
$this->topush['tags'][$this->currtag['name']] = $this->currtag;
}
}
if (!empty($this->topush['tags'])) {
$this->publish($this->topush);
@@ -233,7 +238,12 @@ class progressive_parser {
// Ending rencently started tag, add value to current tag
if ($this->level == $this->prevlevel) {
$this->currtag['cdata'] = $this->postprocess_cdata($this->accum);
$this->topush['tags'][$this->currtag['name']] = $this->currtag;
// We always add the last not-empty repetition. Empty ones are ignored.
if (isset($this->topush['tags'][$this->currtag['name']]) && trim($this->currtag['cdata']) === '') {
// Do nothing, the tag already exists and the repetition is empty
} else {
$this->topush['tags'][$this->currtag['name']] = $this->currtag;
}
$this->currtag = array();
}
@@ -106,6 +106,9 @@
<name>4</name><!-- Only last will be processed. We don't allow repeated final tags in our parser -->
<value>4</value>
<value>5</value><!-- Only last will be processed. We don't allow repeated final tags in our parser -->
<value>
</value><!-- If one tag already is set and the repeated is empty, the original value is kept -->
</othertest>
</glossary>
</activity>