코드 수정

This commit is contained in:
2020-05-01 18:24:05 +09:00
parent 180b3c7c5d
commit 2220920afe
11 changed files with 63 additions and 157 deletions
+6 -6
View File
@@ -183,19 +183,19 @@ class StringUtil
}
public static function uniord(string $c) {
$c0 = ord($c{0});
$c0 = ord($c[0]);
if ($c0 >=0 && $c0 <= 127)
return $c0;
if ($c0 >= 192 && $c0 <= 223)
return ($c0-192)*64 + (ord($c{1})-128);
return ($c0-192)*64 + (ord($c[1])-128);
if ($c0 >= 224 && $c0 <= 239)
return ($c0-224)*4096 + (ord($c{1})-128)*64 + (ord($c{2})-128);
return ($c0-224)*4096 + (ord($c[1])-128)*64 + (ord($c[2])-128);
if ($c0 >= 240 && $c0 <= 247)
return ($c0-240)*262144 + (ord($c{1})-128)*4096 + (ord($c{2})-128)*64 + (ord($c{3})-128);
return ($c0-240)*262144 + (ord($c[1])-128)*4096 + (ord($c[2])-128)*64 + (ord($c[3])-128);
if ($c0 >= 248 && $c0 <= 251)
return ($c0-248)*16777216 + (ord($c{1})-128)*262144 + (ord($c{2})-128)*4096 + (ord($c{3})-128)*64 + (ord($c{4})-128);
return ($c0-248)*16777216 + (ord($c[1])-128)*262144 + (ord($c[2])-128)*4096 + (ord($c[3])-128)*64 + (ord($c[4])-128);
if ($c0 >= 252 && $c0 <= 253)
return ($c0-252)*1073741824 + (ord($c{1})-128)*16777216 + (ord($c{2})-128)*262144 + (ord($c{3})-128)*4096 + (ord($c{4})-128)*64 + (ord($c{5})-128);
return ($c0-252)*1073741824 + (ord($c[1])-128)*16777216 + (ord($c[2])-128)*262144 + (ord($c[3])-128)*4096 + (ord($c[4])-128)*64 + (ord($c[5])-128);
if ($c0 >= 254 && $c0 <= 255) // error
return FALSE;
return 0;
+20 -3
View File
@@ -685,8 +685,25 @@ class Util extends \utilphp\util
* 길이가 다른 경우, 앞의 결과를 먼저 비교한 뒤, 짧은쪽의 값을 null으로 가정하여 길이 처리
*/
public static function arrayCompare(iterable $lhs, iterable $rhs, ?callable $comp=null){
$lhsIter = new \Iterator($lhs);
$rhsIter = new \Iterator($rhs);
if($lhs instanceof \Traversable){
$lhsIter = new \IteratorIterator($lhs);
}
else if(is_array($lhs)){
$lhsIter = new \ArrayIterator($lhs);
}
else{
throw new \InvalidArgumentException('$lhs is not Traversable');
}
if($rhs instanceof \Traversable){
$rhsIter = new \IteratorIterator($rhs);
}
else if(is_array($rhs)){
$rhsIter = new \ArrayIterator($rhs);
}
else{
throw new \InvalidArgumentException('$rhs is not Traversable');
}
while($lhsIter->valid() && $rhsIter->valid()){
$lhsVal = $lhsIter->current();
@@ -759,7 +776,7 @@ class Util extends \utilphp\util
* @param null|int $to
* @param null|int $step
* @return \Traversable
* @throws InvalidArgumentException
* @throws \InvalidArgumentException
*/
public static function range(int $from, ?int $to=null, ?int $step=null):\Traversable{
if($to === null){