Merge commit 'catalyst/MOODLE_19_STABLE' into mdl19-linuxchix
[moodle-linuxchix.git] / search / Zend / Search / Lucene / Analysis / Analyzer / Common / TextNum.php
blobd68b594a07715eb6a9c8e01f68300233d290e7cf
1 <?php
2 /**
3 * Zend Framework
5 * LICENSE
7 * This source file is subject to the new BSD license that is bundled
8 * with this package in the file LICENSE.txt.
9 * It is also available through the world-wide-web at this URL:
10 * http://framework.zend.com/license/new-bsd
11 * If you did not receive a copy of the license and are unable to
12 * obtain it through the world-wide-web, please send an email
13 * to license@zend.com so we can send you a copy immediately.
15 * @category Zend
16 * @package Zend_Search_Lucene
17 * @subpackage Analysis
18 * @copyright Copyright (c) 2005-2007 Zend Technologies USA Inc. (http://www.zend.com)
19 * @license http://framework.zend.com/license/new-bsd New BSD License
23 /** Zend_Search_Lucene_Analysis_Analyzer_Common */
24 require_once $CFG->dirroot.'/search/Zend/Search/Lucene/Analysis/Analyzer/Common.php';
27 /**
28 * @category Zend
29 * @package Zend_Search_Lucene
30 * @subpackage Analysis
31 * @copyright Copyright (c) 2005-2007 Zend Technologies USA Inc. (http://www.zend.com)
32 * @license http://framework.zend.com/license/new-bsd New BSD License
35 class Zend_Search_Lucene_Analysis_Analyzer_Common_TextNum extends Zend_Search_Lucene_Analysis_Analyzer_Common
37 /**
38 * Current position in a stream
40 * @var integer
42 private $_position;
44 /**
45 * Reset token stream
47 public function reset()
49 $this->_position = 0;
51 if ($this->_input === null) {
52 return;
55 // convert input into ascii
56 $this->_input = iconv($this->_encoding, 'ASCII//TRANSLIT', $this->_input);
57 $this->_encoding = 'ASCII';
60 /**
61 * Tokenization stream API
62 * Get next token
63 * Returns null at the end of stream
65 * @return Zend_Search_Lucene_Analysis_Token|null
67 public function nextToken()
69 if ($this->_input === null) {
70 return null;
73 do {
74 if (! preg_match('/[a-zA-Z0-9]+/', $this->_input, $match, PREG_OFFSET_CAPTURE, $this->_position)) {
75 // It covers both cases a) there are no matches (preg_match(...) === 0)
76 // b) error occured (preg_match(...) === FALSE)
77 return null;
80 $str = $match[0][0];
81 $pos = $match[0][1];
82 $endpos = $pos + strlen($str);
84 $this->_position = $endpos;
86 $token = $this->normalize(new Zend_Search_Lucene_Analysis_Token($str, $pos, $endpos));
87 } while ($token === null); // try again if token is skipped
89 return $token;