From: Chuck Hagenbuch Date: Wed, 28 Jan 2009 21:26:44 +0000 (-0500) Subject: port scalar scanners X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=03a935eb6fbbe77342312d0aaa66887612e656e6;p=horde.git port scalar scanners --- diff --git a/framework/Date_Parser/lib/Horde/Date/Parser/Locale/Base/Scalar.php b/framework/Date_Parser/lib/Horde/Date/Parser/Locale/Base/Scalar.php index b08cfee18..7ae60467b 100644 --- a/framework/Date_Parser/lib/Horde/Date/Parser/Locale/Base/Scalar.php +++ b/framework/Date_Parser/lib/Horde/Date/Parser/Locale/Base/Scalar.php @@ -1,74 +1,102 @@ -module Chronic + 31 || (post_token && %w{am pm morning afternoon evening night}.include?(post_token)) - return ScalarDay.new(token.word.to_i) - end - end - return nil - end - - def self.scan_for_months(token, post_token) - if token.word =~ /^\d\d?$/ - unless token.word.to_i > 12 || (post_token && %w{am pm morning afternoon evening night}.include?(post_token)) - return ScalarMonth.new(token.word.to_i) - end - end - return nil - end - - def self.scan_for_years(token, post_token) - if token.word =~ /^([1-9]\d)?\d\d?$/ - unless post_token && %w{am pm morning afternoon evening night}.include?(post_token) - return ScalarYear.new(token.word.to_i) - end - end - return nil - end - - def to_s - 'scalar' - end - end - - class ScalarDay < Scalar #:nodoc: - def to_s - super << '-day-' << @type.to_s - end - end - - class ScalarMonth < Scalar #:nodoc: - def to_s - super << '-month-' << @type.to_s - end - end - - class ScalarYear < Scalar #:nodoc: - def to_s - super << '-year-' << @type.to_s - end - end + public function scan($tokens) + { + foreach ($tokens as $i => &$token) { + $postToken = isset($tokens[$i + 1]) ? $tokens[$i + 1] : null; + if ($t = $this->scanForScalars($token, $postToken)) { + $token->tag($t); + } + if ($t = $this->scanForDays($token, $postToken)) { + $token->tag($t); + } + if ($t = $this->scanForMonths($token, $postToken)) { + $token->tag($t); + } + if ($t = $this->scanForYears($token, $postToken)) { + $token->tag($t); + } + } + return $tokens; + } -end \ No newline at end of file + public function scanForScalars($token, $postToken) + { + if (preg_match($this->scalarRegex, $token->word)) { + if (!in_array($postToken, $this->timeSignifiers)) { + return new self((int)$token->word); + } + } + return null; + } + + public function scanForDays($token, $postToken) + { + if (preg_match($this->dayRegex, $token->word)) { + if ((int)$token->word <= 31 && !in_array($postToken, $this->timeSignifiers)) { + return new Horde_Date_Parser_Locale_Base_ScalarDay((int)$token->word); + } + } + return null; + } + + public function scanForMonths($token, $postToken) + { + if (preg_match($this->monthRegex, $token->word)) { + if ((int)$token->word <= 12 && !in_array($postToken, $this->timeSignifiers)) { + return new Horde_Date_Parser_Locale_Base_ScalarMonth((int)$token->word); + } + } + return null; + } + + public function scanForYears($token, $postToken) + { + if (preg_match($this->yearRegex, $token->word)) { + if (!in_array($postToken, $this->timeSignifiers)) { + return new Horde_Date_Parser_Locale_Base_ScalarYear((int)$token->word); + } + } + return null; + } + + public function __toString() + { + return 'scalar'; + } + +} + +class Horde_Date_Parser_Locale_Base_ScalarDay extends Horde_Date_Parser_Locale_Base_Scalar +{ + public function __toString() + { + return parent::__toString() . '-day-' . $this->type; + } + +} + +class Horde_Date_Parser_Locale_Base_ScalarMonth extends Horde_Date_Parser_Locale_Base_Scalar +{ + public function __toString() + { + return parent::__toString() . '-month-' . $this->type; + } + +} + +class Horde_Date_Parser_Locale_Base_ScalarYear extends Horde_Date_Parser_Locale_Base_Scalar +{ + public function __toString() + { + return parent::__toString() . '-year-' . $this->type; + } + +}