summaryrefslogtreecommitdiff
path: root/inc/parser
diff options
context:
space:
mode:
Diffstat (limited to 'inc/parser')
-rw-r--r--inc/parser/lexer.php35
1 files changed, 30 insertions, 5 deletions
diff --git a/inc/parser/lexer.php b/inc/parser/lexer.php
index cc87df31a..394eae3f6 100644
--- a/inc/parser/lexer.php
+++ b/inc/parser/lexer.php
@@ -98,6 +98,34 @@ class Doku_LexerParallelRegex {
}
/**
+ * Attempts to split the string against all patterns at once
+ *
+ * @param string $subject String to match against.
+ * @param array $split The split result: array containing, pre-match, match & post-match strings
+ * @return boolean True on success.
+ * @access public
+ *
+ * @author Christopher Smith <chris@jalakai.co.uk>
+ */
+ function split($subject, &$split) {
+ if (count($this->_patterns) == 0) {
+ return false;
+ }
+
+ if (! preg_match($this->_getCompoundedRegex(), $subject, $matches)) {
+ $split = array($subject, "", "");
+ return false;
+ }
+
+ $idx = count($matches)-2;
+
+ list($pre, $post) = preg_split($this->_patterns[$idx].$this->_getPerlMatchingFlags(), $subject, 2);
+
+ $split = array($pre, $matches[0], $post);
+ return isset($this->_labels[$idx]) ? $this->_labels[$idx] : true;
+ }
+
+ /**
* Compounds the patterns into a single
* regular expression separated with the
* "or" operator. Caches the regex.
@@ -505,10 +533,8 @@ class Doku_Lexer {
if ($raw === "") {
return true;
}
- if ($action = $this->_regexes[$this->_mode->getCurrent()]->match($raw, $match)) {
- $unparsed_character_count = strpos($raw, $match);
- $unparsed = substr($raw, 0, $unparsed_character_count);
- $raw = substr($raw, $unparsed_character_count + strlen($match));
+ if ($action = $this->_regexes[$this->_mode->getCurrent()]->split($raw, $split)) {
+ list($unparsed, $match, $raw) = $split;
return array($unparsed, $match, $action);
}
return true;
@@ -563,5 +589,4 @@ function Doku_Lexer_Escape($str) {
return preg_replace($chars, $escaped, $str);
}
-
//Setup VIM: ex: et ts=4 enc=utf-8 :