/** * Specifies all escape sequences that are valid following any of the * escape characters. Each escape sequence may be greater than one * character in length and may be specified by a REGEX-string - look-behind * assertions on such regexes are not supported. * @param Mixed Array of strings or single string. */ function setCharactersToEscape(array $chars) { static $re_starter_c = 'REGEX'; static $re_starter_len_c = 5; $this->_charsToEscape = array(); /* Save a little time and processing by anchoring all regexes now, * rather than each time geshi_whichsubstr() is called. */ foreach ($chars as $escSeq) { if (strncmp($escSeq, $re_starter_c, $re_starter_len_c) == 0) { $re = substr($escSeq, $re_starter_len_c); $re = geshi_anchor_re($re); $this->_charsToEscape[] = $re_starter_c . $re; } else { $this->_charsToEscape[] = $escSeq; } } }
function geshi_whichsubstr($str, $substrs, $offset = 0, $flags = 0) { /* Constants */ static $re_starter_c = 'REGEX'; static $re_starter_len_c = 5; $ret = null; $max_len = -1; foreach ($substrs as $substr) { if ($flags & GESHI_WHICHSS_TRYREGEX && strncmp($substr, $re_starter_c, $re_starter_len_c) == 0) { $re = substr($substr, $re_starter_len_c); if (!($flags & GESHI_WHICHSS_SKIPANCHORINSERT)) { $re = geshi_anchor_re($re); } $haystack = $offset > 0 ? substr($str, $offset) : $str; $match = preg_match($re, $haystack, $matches, PREG_OFFSET_CAPTURE) ? $matches[0][0] : null; $len = strlen($match); /* This code is reached only if GESHI_WHICHSS_SKIPANCHORINSERT was * specified without a pre-existing anchor and with a match that * started beyond $offset. */ if ($match !== null && $matches[0][1]) { $len = $match = null; } } else { $len = strlen($substr); if (!($flags & GESHI_WHICHSS_CASEINSENSITIVE)) { $match = substr($str, $offset, $len) == $substr ? $substr : null; } else { if (strcasecmp(substr($str, $offset, $len), $substr) == 0) { $match = $substr; } else { $match = null; } } } if ($match !== null) { if (!($flags & GESHI_WHICHSS_MAXIMAL)) { $ret = $match; break; } else { if ($len > $max_len) { $ret = $match; $max_len = $len; } } } } return $ret; }