Page MenuHomeDevCentral

Use PHP 7.4 mb_str_split in OmniString::getBigrams
Open, LowPublic

Description

PHP 7.4 introduced mb_str_split(), which roughly do the same than our for loop in OmniString::getBigrams code.

That means:

public function getBigrams () {
    $bigrams = [];

    $len = $this->len();
    for ($i = 0 ; $i < $len - 1 ; $i++) {
        $bigrams[] = mb_substr($this->value, $i, 2, $this->encoding);
    }

    return $bigrams;
}

Could in PHP 7.4+ rewritten as:

public function getBigrams () {
    return mb_str_split($this->value, 2, $this->encoding);
}

Reference: https://wiki.php.net/rfc/mb_str_split

Event Timeline

dereckson triaged this task as Low priority.Dec 5 2019, 11:04
dereckson created this task.
dereckson updated the task description. (Show Details)
dereckson moved this task from Backlog to Dev on the easy board.