<?php
+/**
+ *
+ * @package MediaWiki
+ */
+
+/**
+ *
+ * @package MediaWiki
+ */
class Tokenizer {
/* private */ var $mText, # Text to be processed by the tokenizer
$mPos, # current position of tokenizer in text
$mQueuedToken; # Tokens that were already found, but not
# returned yet.
- /* private */ function Tokenizer()
- {
+ /**
+ * Constructor
+ * @access private
+ */
+ function Tokenizer() {
global $wgLang;
$this->mPos=0;
$this->linkPrefixExtension = $wgLang->linkPrefixExtension();
}
- # factory function
- function newFromString( $s )
- {
+ /**
+ * factory function
+ */
+ function newFromString( $s ) {
$fname = 'Tokenizer::newFromString';
wfProfileIn( $fname );
}
- // Return the next token, but do not increase the pointer. The next call
- // to previewToken or nextToken will return the same token again.
- // Actually, the pointer is increased, but the token is queued. The next
- // call to previewToken or nextToken will check the queue and return
- // the stored token.
- function previewToken()
- {
+ /**
+ * Return the next token, but do not increase the pointer. The next call
+ * to previewToken or nextToken will return the same token again.
+ * Actually, the pointer is increased, but the token is queued. The next
+ * call to previewToken or nextToken will check the queue and return
+ * the stored token.
+ */
+ function previewToken() {
$fname = 'Tokenizer::previewToken';
wfProfileIn( $fname );
}
- // get the next token
- // proceeds character by character through the text, looking for characters needing
- // special attention. Those are currently: I, R, ', [, ], newline
- //
- // TODO: handling of French blanks not yet implemented
- function nextToken()
- {
+ /**
+ * Get the next token.
+ *
+ * proceeds character by character through the text, looking for characters needing
+ * special attention. Those are currently: I, R, ', [, ], newline
+ *
+ * @todo handling of French blanks not yet implemented
+ */
+ function nextToken() {
$fname = 'Tokenizer::nextToken';
wfProfileIn( $fname );
// still one token from the last round around. Return that one first.
$token = array_shift( $this->mQueuedToken );
} else if ( $this->mPos > $this->mTextLength ) {
- // If no text is left, return "false".
+ // If no text is left, return 'false'.
$token = false;
} else {
// strip blank from Token
$token['text'] = substr( $token['text'], 0, -1 );
$queueToken['type'] = 'blank';
- $queueToken['text'] = " {$ch}";
+ $queueToken['text'] = ' '.$ch;
$this->mQueuedToken[] = $queueToken;
$this->mPos ++;
break 2; // switch + while
case '8':
case '9':
if ( ($this->mTextLength >= $this->mPos +2)
- && ($this->mText[$this->mPos+1] == " ")
+ && ($this->mText[$this->mPos+1] == ' ')
&& ctype_digit( $this->mText[$this->mPos+2] ) )
{
$queueToken['type'] = 'blank';
break;
case '&': //extensions like <timeline>, since HTML stripping has already been done,
//those look like <timeline>
- if ( $this->continues( "lt;timeline>" ) )
+ if ( $this->continues( 'lt;timeline>' ) )
{
- $queueToken['type'] = "<timeline>";
- $queueToken['text'] = "<timeline>";
+ $queueToken['type'] = '<timeline>';
+ $queueToken['text'] = '<timeline>';
$this->mQueuedToken[] = $queueToken;
$this->mPos += 16;
break 2; // switch + while
return $token;
}
- // function continues
- // checks whether the mText continues with $cont from mPos+1
- /* private */ function continues( $cont )
- {
+ /**
+ * function continues
+ *
+ * checks whether the mText continues with $cont from mPos+1
+ *
+ * @access private
+ */
+ function continues( $cont ) {
// If string is not long enough to contain $cont, return false
if ( $this->mTextLength < $this->mPos + strlen( $cont ) )
return false;
return true;
}
- // function preceeded
- // checks whether the mText is preceeded by $prec at position mPos
- /* private */ function preceeded( $prec )
- {
+ /**
+ * function preceeded
+ *
+ * checks whether the mText is preceeded by $prec at position mPos
+ *
+ * @access private
+ */
+ function preceeded( $prec ) {
$len = strlen( $prec );
// if $prec is longer than the text up to mPos, return false
if ( $this->mPos < $len )
return ( 0 == strcmp( $prec, substr($this->mText, $this->mPos-$len, $len) ) );
}
- function readAllUntil( $border )
- {
+ /**
+ *
+ */
+ function readAllUntil( $border ) {
$n = strpos( $this->mText, $border, $this->mPos );
if ( $n === false )
return '';