*prechod na novsiu verziu ZF
[sport-group.git] / library / Zend / Search / Lucene / Analysis / Analyzer / Common / Text.php
bloba9bf3d06ac6e1c41e381279f9d33770e05eb2aac
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-2009 Zend Technologies USA Inc. (http://www.zend.com)
19 * @license http://framework.zend.com/license/new-bsd New BSD License
20 * @version $Id: Text.php 16541 2009-07-07 06:59:03Z bkarwin $
24 /** Zend_Search_Lucene_Analysis_Analyzer_Common */
25 require_once 'Zend/Search/Lucene/Analysis/Analyzer/Common.php';
28 /**
29 * @category Zend
30 * @package Zend_Search_Lucene
31 * @subpackage Analysis
32 * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
33 * @license http://framework.zend.com/license/new-bsd New BSD License
36 class Zend_Search_Lucene_Analysis_Analyzer_Common_Text extends Zend_Search_Lucene_Analysis_Analyzer_Common
38 /**
39 * Current position in a stream
41 * @var integer
43 private $_position;
45 /**
46 * Reset token stream
48 public function reset()
50 $this->_position = 0;
52 if ($this->_input === null) {
53 return;
56 // convert input into ascii
57 if (PHP_OS != 'AIX') {
58 $this->_input = iconv($this->_encoding, 'ASCII//TRANSLIT', $this->_input);
60 $this->_encoding = 'ASCII';
63 /**
64 * Tokenization stream API
65 * Get next token
66 * Returns null at the end of stream
68 * @return Zend_Search_Lucene_Analysis_Token|null
70 public function nextToken()
72 if ($this->_input === null) {
73 return null;
77 do {
78 if (! preg_match('/[a-zA-Z]+/', $this->_input, $match, PREG_OFFSET_CAPTURE, $this->_position)) {
79 // It covers both cases a) there are no matches (preg_match(...) === 0)
80 // b) error occured (preg_match(...) === FALSE)
81 return null;
84 $str = $match[0][0];
85 $pos = $match[0][1];
86 $endpos = $pos + strlen($str);
88 $this->_position = $endpos;
90 $token = $this->normalize(new Zend_Search_Lucene_Analysis_Token($str, $pos, $endpos));
91 } while ($token === null); // try again if token is skipped
93 return $token;