public function testMatchAll() { $this->assertEquals(array("#str rst#", "str", "rst"), StrUtil::matchAll('@#([a-z]*) ([a-z]*)#@', 'yxa#str rst#bxy')); // named patterns $this->assertEquals(array("#str rst#", "str", "rst", "first" => "str", "second" => "rst"), StrUtil::matchAll('@#(?P<first>[a-z]*) (?P<second>[a-z]*)#@', 'yxa#str rst#bxy')); $this->assertEquals(false, StrUtil::matchAll('@x(.*)x@', 'yyabxy')); }
/** * Parses the AIS2 version from html page. * * @param string $html AIS2 html reply to be parsed * * @returns AIS2Version AIS2 version * @throws ParseException on error */ public function parseVersionStringFromMainPage($html) { Preconditions::checkIsString($html); $data = StrUtil::matchAll(self::VERSION_PATTERN, $html); if ($data === false) { throw new ParseException("Cannot parse AIS version from response."); } return new AIS2Version(2, $data['major'], $data['minor'], $data['patch']); }
/** * Parses user name from AIS2 start page * * @param string $html AIS2 html reply to be parsed * * @returns AIS2Version AIS2 version * @throws ParseException on error */ public function parseUserNameFromMainPage($html) { Preconditions::checkIsString($html); $data = StrUtil::matchAll(self::USERNAME_PATTERN, $html); if ($data === false) { throw new ParseException("Cannot parse username from response."); } return $data['username']; }
/** * * @param str predpokladame range v 2 moznych standardnych ais formatoch * - "do [datum a cas]" * - "[datum a cas] do [datum a cas]" * @see parseAISDateTime * @returns array('od'=>timestamp, 'do'=>timestamp) */ public static function parseAISDateTimeRange($str) { $pattern = '@(?P<od>[0-9:. ]*)do (?P<do>[0-9:. ]*)@'; $data = StrUtil::matchAll($pattern, $str); $result = array(); if ($data['od'] == '') { $result['od'] = null; } else { $result['od'] = self::parseAISDateTime($data['od']); } $result['do'] = self::parseAISDateTime($data['do']); return $result; }