web/Zend/Search/Lucene/Analysis/Analyzer/Common/TextNum.php
changeset 0 4eba9c11703f
equal deleted inserted replaced
-1:000000000000 0:4eba9c11703f
       
     1 <?php
       
     2 /**
       
     3  * Zend Framework
       
     4  *
       
     5  * LICENSE
       
     6  *
       
     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.
       
    14  *
       
    15  * @category   Zend
       
    16  * @package    Zend_Search_Lucene
       
    17  * @subpackage Analysis
       
    18  * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
       
    19  * @license    http://framework.zend.com/license/new-bsd     New BSD License
       
    20  * @version    $Id: TextNum.php 20096 2010-01-06 02:05:09Z bkarwin $
       
    21  */
       
    22 
       
    23 
       
    24 /** Zend_Search_Lucene_Analysis_Analyzer_Common */
       
    25 require_once 'Zend/Search/Lucene/Analysis/Analyzer/Common.php';
       
    26 
       
    27 
       
    28 /**
       
    29  * @category   Zend
       
    30  * @package    Zend_Search_Lucene
       
    31  * @subpackage Analysis
       
    32  * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
       
    33  * @license    http://framework.zend.com/license/new-bsd     New BSD License
       
    34  */
       
    35 
       
    36 class Zend_Search_Lucene_Analysis_Analyzer_Common_TextNum extends Zend_Search_Lucene_Analysis_Analyzer_Common
       
    37 {
       
    38     /**
       
    39      * Current position in a stream
       
    40      *
       
    41      * @var integer
       
    42      */
       
    43     private $_position;
       
    44 
       
    45     /**
       
    46      * Reset token stream
       
    47      */
       
    48     public function reset()
       
    49     {
       
    50         $this->_position = 0;
       
    51 
       
    52         if ($this->_input === null) {
       
    53             return;
       
    54         }
       
    55 
       
    56         // convert input into ascii
       
    57         if (PHP_OS != 'AIX') {
       
    58             $this->_input = iconv($this->_encoding, 'ASCII//TRANSLIT', $this->_input);
       
    59         }
       
    60         $this->_encoding = 'ASCII';
       
    61     }
       
    62 
       
    63     /**
       
    64      * Tokenization stream API
       
    65      * Get next token
       
    66      * Returns null at the end of stream
       
    67      *
       
    68      * @return Zend_Search_Lucene_Analysis_Token|null
       
    69      */
       
    70     public function nextToken()
       
    71     {
       
    72         if ($this->_input === null) {
       
    73             return null;
       
    74         }
       
    75 
       
    76         do {
       
    77             if (! preg_match('/[a-zA-Z0-9]+/', $this->_input, $match, PREG_OFFSET_CAPTURE, $this->_position)) {
       
    78                 // It covers both cases a) there are no matches (preg_match(...) === 0)
       
    79                 // b) error occured (preg_match(...) === FALSE)
       
    80                 return null;
       
    81             }
       
    82 
       
    83             $str = $match[0][0];
       
    84             $pos = $match[0][1];
       
    85             $endpos = $pos + strlen($str);
       
    86 
       
    87             $this->_position = $endpos;
       
    88 
       
    89             $token = $this->normalize(new Zend_Search_Lucene_Analysis_Token($str, $pos, $endpos));
       
    90         } while ($token === null); // try again if token is skipped
       
    91 
       
    92         return $token;
       
    93     }
       
    94 }
       
    95