Skip to content

Commit

Permalink
refactor: Remove use of abandoned patchwork/utf8 library.
Browse files Browse the repository at this point in the history
  • Loading branch information
pointybeard committed Nov 14, 2021
1 parent 8ef3af2 commit a0b8c46
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
9 changes: 4 additions & 5 deletions src/ReverseRegex/Parser/CharacterClass.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
use ReverseRegex\Generator\LiteralScope;
use ReverseRegex\Lexer;
use ReverseRegex\Exception as ParserException;
use Patchwork\Utf8;

/**
* Parse a character class [0-9][a-z]
Expand Down Expand Up @@ -108,7 +107,7 @@ public function parse(Scope $head, Scope $set, Lexer $lexer)

break;
case($normal_lexer->isNextToken(Lexer::T_LITERAL_NUMERIC) || $normal_lexer->isNextToken(Lexer::T_LITERAL_CHAR)) :
$index = (integer)Utf8::ord($normal_lexer->lookahead['value']);
$index = (integer)mb_ord($normal_lexer->lookahead['value']);
$head->setLiteral($index,$normal_lexer->lookahead['value']);
break;
default:
Expand All @@ -131,15 +130,15 @@ public function parse(Scope $head, Scope $set, Lexer $lexer)
public function fillRange(Scope $head,$start,$end)
{

$start_index = Utf8::ord($start);
$ending_index = Utf8::ord($end);
$start_index = mb_ord($start);
$ending_index = mb_ord($end);

if($ending_index < $start_index ) {
throw new ParserException(sprintf('Character class range %s - %s is out of order',$start,$end));
}

for($i = $start_index; $i <= $ending_index; $i++) {
$head->setLiteral($i,Utf8::chr($i));
$head->setLiteral($i,mb_chr($i));
}
}

Expand Down
5 changes: 2 additions & 3 deletions src/ReverseRegex/Parser/Unicode.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
use ReverseRegex\Generator\Scope;
use ReverseRegex\Lexer;
use ReverseRegex\Exception as ParserException;
use Patchwork\Utf8;

/**
* Parse a unicode sequence e.g \x54 \X{4444}
Expand Down Expand Up @@ -74,7 +73,7 @@ public function evaluate(Lexer $lexer)

$number = trim(implode('',$tokens));

return Utf8::chr(hexdec($number));
return mb_chr(hexdec($number));

break;
case ($lexer->isNextToken(Lexer::T_SHORT_X)) :
Expand All @@ -92,7 +91,7 @@ public function evaluate(Lexer $lexer)
}

$value = trim(implode('',$tokens));
return Utf8::chr(hexdec($value));
return mb_chr(hexdec($value));
break;
default :
throw new ParserException('No Unicode expression to evaluate');
Expand Down

0 comments on commit a0b8c46

Please sign in to comment.