diff options
author | Michael Larabel <michael@phx-laptop.(none)> | 2008-11-19 17:48:08 -0500 |
---|---|---|
committer | Michael Larabel <michael@phx-laptop.(none)> | 2008-11-19 17:48:08 -0500 |
commit | d6fb6e9df231f73abd930e61e00998e78334002c (patch) | |
tree | 8cd1f30343918a124f286eab5d9a04a39c56d980 /pts-core/objects | |
parent | 1c3862541d0111c5bf629bdbe0f1204855144b07 (diff) | |
download | phoronix-test-suite-upstream-d6fb6e9df231f73abd930e61e00998e78334002c.tar.gz phoronix-test-suite-upstream-d6fb6e9df231f73abd930e61e00998e78334002c.tar.xz phoronix-test-suite-upstream-d6fb6e9df231f73abd930e61e00998e78334002c.zip |
tandem_XmlReader: Write internal regular expression matcher for systems
where preg_match and preg_match_all aren't available
Diffstat (limited to 'pts-core/objects')
-rw-r--r-- | pts-core/objects/tandem_XmlReader.php | 105 |
1 files changed, 93 insertions, 12 deletions
diff --git a/pts-core/objects/tandem_XmlReader.php b/pts-core/objects/tandem_XmlReader.php index aad26ff..c399ff5 100644 --- a/pts-core/objects/tandem_XmlReader.php +++ b/pts-core/objects/tandem_XmlReader.php @@ -81,10 +81,15 @@ class tandem_XmlReader } function listStatements($SEARCH_DO = false, $SEARCH_QUERY = "") { - preg_match_all("'<!--(.*?) -->'si", $this->XML_DATA, $statement_maches); + if(!function_exists("preg_match_all")) + { + return array(); // TODO: Write a software fallback for this parsing similar to parseXMLString() + } + + preg_match_all("'<!--(.*?) -->'si", $this->XML_DATA, $statement_matches); $return_array = array(); - foreach($statement_maches[0] as $statement) + foreach($statement_matches[0] as $statement) { $name = substr($statement, 0, strpos($statement, ':')); $name = trim(strstr($name, ' ')); @@ -133,13 +138,9 @@ class tandem_XmlReader { foreach(explode("/", $XML_TAG) as $xml_step) { - preg_match("'<$xml_step>(.*?)</$xml_step>'si", $XML_MATCH, $new_match); + $XML_MATCH = $this->parseXMLString($xml_step, $XML_MATCH, false); - if(count($new_match) > 1) - { - $XML_MATCH = $new_match[1]; - } - else + if($XML_MATCH == false) { if(!$FALLBACK_PROCESS) { @@ -160,6 +161,85 @@ class tandem_XmlReader return $XML_MATCH; } + function parseXMLString($TAG, $TO_PARSE, $DO_MULTIPLE = true) + { + $return = false; + + if(function_exists("preg_match") && function_exists("preg_match_all")) + { + if($DO_MULTIPLE) + { + preg_match_all("'<" . $TAG . ">(.*?)</" . $TAG . ">'si", $TO_PARSE, $matches); + + if(count($matches) >= 2) + { + $return = $matches[1]; + } + } + else + { + preg_match("'<" . $TAG . ">(.*?)</" . $TAG . ">'si", $TO_PARSE, $match); + + if(count($match) >= 2) + { + $return = $match[1]; + } + } + } + else + { + $open_tag = "<" . $TAG . ">"; + $close_tag = "</" . $TAG . ">"; + + if($DO_MULTIPLE) + { + $temp_r = array(); + $temp = $TO_PARSE; + + do + { + $return = null; + + if(($start = strpos($temp, $open_tag)) !== false) + { + $temp = substr($temp, $start + strlen($open_tag)); + + if(($end = strpos($temp, $close_tag)) !== false) + { + $return = substr($temp, 0, $end); + $temp = substr($temp, strlen($return) + strlen($close_tag)); + } + } + + if($return != null) + { + array_push($temp_r, $return); + } + } + while($return != null); + + if(count($temp_r) > 0) + { + $return = $temp_r; + } + } + else + { + if(($start = strpos($TO_PARSE, $open_tag)) !== false) + { + $temp = substr($TO_PARSE, $start + strlen($open_tag)); + + if(($end = strpos($temp, $close_tag)) !== false) + { + $temp = substr($temp, 0, $end); + $return = $temp; + } + } + } + } + + return $return; + } function handleXmlZeroTagFallback($XML_TAG) { return $this->NO_TAG_FALLBACK_VALUE; @@ -183,17 +263,17 @@ class tandem_XmlReader } $next_xml_step = $xml_steps[count($xml_steps) - 2]; - preg_match_all("'<$next_xml_step>(.*?)</$next_xml_step>'si", $this_xml, $xml_matches); + $xml_matches = $this->parseXMLString($next_xml_step, $this_xml); $return_array = array(); $extraction_tags = explode(',', end($xml_steps)); $extraction_tags_count = count($extraction_tags); - for($i = 0; $i < count($xml_matches[1]); $i++) + for($i = 0; $i < count($xml_matches); $i++) { if($extraction_tags_count == 1) { - $this_item = $this->getValue($XML_TAG, $extraction_tags[0], $xml_matches[1][$i], false); + $this_item = $this->getValue($XML_TAG, $extraction_tags[0], $xml_matches[$i], false); array_push($return_array, $this_item); } else @@ -207,7 +287,7 @@ class tandem_XmlReader } foreach($extraction_tags as $extract) { - $this_item = $this->getValue($XML_TAG, $extract, $xml_matches[1][$i], false); + $this_item = $this->getValue($XML_TAG, $extract, $xml_matches[$i], false); array_push($return_array[$extract], $this_item); } } @@ -228,4 +308,5 @@ class tandem_XmlReader $this->setTagCaching($BOOL); } } + ?> |