버그 수정

This commit is contained in:
2020-04-21 01:19:24 +09:00
parent 6af3c1d523
commit e229b207c1
8 changed files with 120 additions and 87 deletions
+48 -13
View File
@@ -604,23 +604,58 @@ class JosaUtil{
};
}
public static function batch(string $text, string $key, array $decorator =[':',':']){
public static function batch(string $text, string $decorator = ';'){
JosaUtil::init();
$search = [];
$replace = [];
if($decorator === ';'){
preg_match_all('/;([^;]+);/', $text, $matches, PREG_OFFSET_CAPTURE);
}
else{
$decorator = preg_quote($decorator);
$pattern = "/{$decorator}([^{$decorator}]+){$decorator}/";
preg_match_all($pattern, $text, $matches, PREG_OFFSET_CAPTURE);
}
$prefix = ':';
$postfix = ':';
foreach(static::DEFAULT_POSTPOSITION as $wJong => $woJong){
$value = JosaUtil::pick($key, $wJong);
$search[] = "{$prefix}{$wJong}{$postfix}";
$replace[] = $value;
$search[] = "{$prefix}{$woJong}{$postfix}";
$replace[] = $value;
$matchCnt = count($matches[0]);
if($matchCnt & 1){
$matchCnt -= 1;
}
return str_replace($search, $replace, $text);
if(!$matchCnt){
return $text;
}
$result = [];
$prePos = 0;
foreach(Util::range(0, $matchCnt, 2) as $matchIdx){
$bodyRawText = $matches[0][$matchIdx][0];
$bodyText = $matches[1][$matchIdx][0];
$bodyRawPos = $matches[0][$matchIdx][1];
if($bodyRawPos > $prePos){
$result[] = substr($text, $prePos, $bodyRawPos - $prePos);
}
$prePos = $bodyRawPos + strlen($bodyRawText);
$result[] = $bodyText;
$josaRawText = $matches[0][$matchIdx+1][0];
$josaText = $matches[1][$matchIdx+1][0];
$josaRawPos = $matches[0][$matchIdx+1][1];
if($josaRawPos > $prePos){
$result[] = substr($text, $prePos, $josaRawPos - $prePos);
}
$prePos = $josaRawPos + strlen($josaRawText);
$pickedJosa = JosaUtil::pick($bodyText, $josaText);
$result[] = $pickedJosa;
}
$textLen = strlen($text);
if($prePos < $textLen){
$result[] = substr($text, $prePos, $textLen - $prePos);
}
return join('', $result);
}
}
+2 -2
View File
@@ -776,13 +776,13 @@ class Util extends \utilphp\util
if($step > 0){
while($from < $to){
yield $from;
$from += 1;
$from += $step;
}
}
else{
while($from > $to){
yield $from;
$from -= 1;
$from -= $step;
}
}
}