修訂 | 8d004ca33cdf55bc7e4afb6cb8cf27e9d9bf176c (tree) |
---|---|
時間 | 2009-04-12 19:49:02 |
作者 | henoheno <henoheno> |
Commiter | henoheno |
generate_trie_regex(): Modified, comments only
@@ -1,6 +1,6 @@ | ||
1 | 1 | <?php |
2 | 2 | // PukiWiki - Yet another WikiWikiWeb clone. |
3 | -// $Id: func.php,v 1.100 2009/03/29 15:08:00 henoheno Exp $ | |
3 | +// $Id: func.php,v 1.101 2009/04/12 10:49:02 henoheno Exp $ | |
4 | 4 | // Copyright (C) |
5 | 5 | // 2002-2007,2009 PukiWiki Developers Team |
6 | 6 | // 2001-2002 Originally written by yu-ji |
@@ -617,9 +617,16 @@ function preg_quote_extended($string, $delimiter = NULL) | ||
617 | 617 | // Generate one compact regex for quick reTRIEval, |
618 | 618 | // that just matches with all $array-values. |
619 | 619 | // |
620 | -// USAGE: | |
620 | +// USAGE (PHP >= 4.4.0, PHP >= 5.0.2): | |
621 | 621 | // $array = array(7 => 'fooa', 5 => 'foob'); |
622 | -// sort($array, SORT_STRING); // Keys are replaced, as we had expected | |
622 | +// $array = array_unique($array); | |
623 | +// sort($array, SORT_LOCALE_STRING); // Keys will be replaced | |
624 | +// echo generate_trie_regex($array); // 'foo(?:a|b)' | |
625 | +// | |
626 | +// USAGE (PHP >= 5.2.9): | |
627 | +// $array = array(7 => 'fooa', 5 => 'foob'); | |
628 | +// $array = array_unique($array, SORT_LOCALE_STRING); | |
629 | +// $array = array_values($array); | |
623 | 630 | // echo generate_trie_regex($array); // 'foo(?:a|b)' |
624 | 631 | // |
625 | 632 | // ARGUMENTS: |
@@ -636,10 +643,10 @@ function preg_quote_extended($string, $delimiter = NULL) | ||
636 | 643 | // |
637 | 644 | function generate_trie_regex(& $array, $_offset = 0, $_sentry = NULL, $_pos = 0) |
638 | 645 | { |
639 | - if (empty($array)) return '(?!)'; // Zero | |
646 | + if (empty($array)) return '(?!)'; // Match with nothing | |
640 | 647 | if ($_sentry === NULL) $_sentry = count($array); |
641 | 648 | |
642 | - // Too short. Skip this | |
649 | + // Question mark: array('', 'something') => '(?:something)?' | |
643 | 650 | $skip = ($_pos >= mb_strlen($array[$_offset])); |
644 | 651 | if ($skip) ++$_offset; |
645 | 652 |