Skip to content

Commit

Permalink
serizlie array
Browse files Browse the repository at this point in the history
  • Loading branch information
recca0120 committed Apr 11, 2023
1 parent 07f2aa5 commit 289b089
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 16 deletions.
Binary file modified resources/Zip32_utf8_10501_1.zip
Binary file not shown.
1 change: 1 addition & 0 deletions resources/converter.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
$contents = mb_convert_encoding($contents, 'UTF-8', $encoding);
}
$contents = preg_replace("/^\xEF\xBB\xBF/", '', $contents);
$contents = trim(str_replace('Zip5,City,Area,Road,Scope', '', $contents));

$zip = new ZipArchive();
$zip->open($file, ZipArchive::OVERWRITE);
Expand Down
Binary file modified resources/data/zip3.rules
Binary file not shown.
Binary file modified resources/data/zip5.rules
Binary file not shown.
11 changes: 6 additions & 5 deletions src/Address.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public function set($address)
/**
* tokenize.
*
* @return JArray
* @return array
*/
private function tokenize()
{
Expand All @@ -106,7 +106,7 @@ private function tokenize()
}
}

return new JArray($tokens);
return $tokens;
}

/**
Expand All @@ -126,7 +126,7 @@ public function __toString()
*/
public function tokens()
{
return $this->tokens;
return new JArray($this->tokens);
}

/**
Expand Down Expand Up @@ -157,10 +157,11 @@ public function getPoint($index)
*/
public function flat($length = null, $offset = 0)
{
$length = $length ?: $this->tokens->length();
$tokens = $this->tokens();
$length = $length ?: $tokens->length();
$end = $offset + $length;

return (string) $this->tokens->slice($offset, $end)->map(function ($token) {
return (string) $tokens->slice($offset, $end)->map(function ($token) {
return implode('', $token);
})->join('');
}
Expand Down
23 changes: 12 additions & 11 deletions src/Rule.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class Rule
public $zip5;

/**
* $tokens.
* $address.
*
* @var Address
*/
Expand All @@ -31,7 +31,7 @@ class Rule
/**
* $tokens.
*
* @var JArray
* @var array
*/
public $tokens;

Expand Down Expand Up @@ -97,18 +97,19 @@ public function match($address)
$ruleAddressTokens
);
$addressTokens = $address->tokens();
$currentTokens = $this->tokens();

$cur = $ruleAddressTokens->length() - 1;
$cur -= $this->tokens->length() > 0 && $this->tokens->includes('') === false;
$cur -= $this->tokens->includes('');
$cur -= $currentTokens->length() > 0 && $currentTokens->includes('') === false;
$cur -= $currentTokens->includes('');

if ($this->equalsToken($ruleAddressTokens, $addressTokens, $cur) === false) {
return false;
}

$addressPoint = $address->getPoint($cur + 1);

if ($this->tokens->length() > 0 && $addressPoint->isEmpty() === true) {
if ($currentTokens->length() > 0 && $addressPoint->isEmpty() === true) {
return false;
}

Expand All @@ -123,7 +124,7 @@ public function match($address)
($token === '以下' && $addressPoint->compare($left, '<=') === false) ||
($token === '' && (
($right->compare($addressPoint, '<=') && $addressPoint->compare($left, '<=')) ||
($this->tokens->includes('含附號全') === true && ($addressPoint->x === $left->x))
($currentTokens->includes('含附號全') === true && ($addressPoint->x === $left->x))
) === false) ||
($token === '含附號' && ($addressPoint->x === $left->x) === false) ||
($token === '附號全' && ($addressPoint->x === $left->x && $addressPoint->y > 0) === false) ||
Expand All @@ -147,18 +148,18 @@ public function match($address)
*/
public function tokens()
{
return $this->tokens;
return new JArray($this->tokens);
}

/**
* tokenize.
*
* @param string $rule
* @return JArray
* @return array
*/
private function tokenize($rule, Closure $addressResolver)
{
$tokens = new JArray();
$tokens = [];

$pattern = [
'及以上附號|含附號以下|含附號全|含附號',
Expand All @@ -167,13 +168,13 @@ private function tokenize($rule, Closure $addressResolver)
'[連至單雙全](?=[\d全]|$)',
];

$addressResolver($this->normalize($rule)->replace('/'.implode('|', $pattern).'/u', function ($m) use ($tokens) {
$addressResolver($this->normalize($rule)->replace('/'.implode('|', $pattern).'/u', function ($m) use (&$tokens) {
$token = &$m[0];
if ($token === '') {
return '';
}

$tokens->append($token);
$tokens[] = $token;

return $token === '附號全' ? '' : '';
}));
Expand Down

0 comments on commit 289b089

Please sign in to comment.