Example #1
0
 /**
  * 文字列の先頭が, このオブジェクトにセットされている候補一覧の中のいずれかに合致するかどうかを調べます.
  * 合致した候補文字列を返します.
  * 
  * @param  string $input 検査対象の文字列
  * @return string        合致した候補文字列
  */
 public function match($input)
 {
     foreach ($this->candidates as $candidate) {
         if (Strings::startsWith($input, $candidate)) {
             return $candidate;
         }
     }
     return null;
 }
Example #2
0
 /**
  * 指定された UTF-8 の文字列を Unicode 符号点の配列に変換します.
  * 
  * @param  string $text UTF-8 でエンコードされた文字列
  * @return array        Unicode 符号点の配列
  */
 public function decode($text)
 {
     $bom = chr(0xef) . chr(0xbb) . chr(0xbf);
     if (Strings::startsWith($text, $bom)) {
         return $this->decode(substr($text, 3));
     }
     $context = new Utf8Context($text);
     $result = array();
     while ($context->hasNext()) {
         $result[] = $context->next();
     }
     // 文字列の末尾に不正な文字が存在していた場合,
     // $result の最後の要素に null が代入されるので取り除く
     $count = count($result);
     if ($count && $result[$count - 1] === null) {
         array_pop($result);
     }
     return $result;
 }
Example #3
0
 /**
  * 指定されたフィールド名を $fields のインデックスに変換します.
  * 不正なフィールド名の場合は -1 を返します.
  * 
  * @param  string $field フィールド名
  * @return int           インデックス
  * 
  * @see    Time::$YEAR
  * @see    Time::$MONTH
  * @see    Time::$DATE
  * @see    Time::$HOUR
  * @see    Time::$MINUTE
  * @see    Time::$SECOND
  * @codeCoverageIgnore
  */
 private function getFieldIndex($field)
 {
     static $mapping = null;
     if (!isset($mapping)) {
         $mapping = array("y" => self::$YEAR, "mo" => self::$MONTH, "d" => self::$DATE, "h" => self::$HOUR, "m" => self::$MINUTE, "s" => self::$SECOND);
     }
     $field = strtolower($field);
     foreach ($mapping as $key => $index) {
         if (Strings::startsWith($field, $key)) {
             return $index;
         }
     }
     return -1;
 }