private function applyCanonicalOrdering(array $input): array
    {
        $needsSwapping = true;
        $inputLength = count($input);
        while ($needsSwapping) {
            $needsSwapping = false;
            $previousClass = $this->getCombiningClass(intval($input[0]));
            for ($outerIndex = 0; $outerIndex < $inputLength - 1; ++$outerIndex) {
                $nextClass = $this->getCombiningClass(intval($input[$outerIndex + 1]));
                if ($nextClass !== 0 && $previousClass > $nextClass) {
                    // Move item leftward until it fits
                    for ($innerIndex = $outerIndex + 1; $innerIndex > 0; --$innerIndex) {
                        if ($this->getCombiningClass(intval($input[$innerIndex - 1])) <= $nextClass) {
                            break;
                        }
                        $charToMove = intval($input[$innerIndex]);
                        $input[$innerIndex] = intval($input[$innerIndex - 1]);
                        $input[$innerIndex - 1] = $charToMove;
                        $needsSwapping = true;
                    }
                    // Reentering the loop looking at the old character again
                    $nextClass = $previousClass;
                }
                $previousClass = $nextClass;
            }
        }

        return $input;
    }
private function applyCanonicalOrdering(array $input): array
    {
        $needsSwapping = true;
        $inputLength = count($input);
        while ($needsSwapping) {
            $needsSwapping = false;
            $previousClass = $this->getCombiningClass(intval($input[0]));
            for ($outerIndex = 0; $outerIndex < $inputLength - 1; ++$outerIndex) {
                $nextClass = $this->getCombiningClass(intval($input[$outerIndex + 1]));
                if ($nextClass !== 0 && $previousClass > $nextClass) {
                    // Move item leftward until it fits
                    for ($innerIndex = $outerIndex + 1; $innerIndex > 0; --$innerIndex) {
                        if ($this->getCombiningClass(intval($input[$innerIndex - 1])) <= $nextClass) {
                            break;
                        }
                        $charToMove = intval($input[$innerIndex]);
                        $input[$innerIndex] = intval($input[$innerIndex - 1]);
                        $input[$innerIndex - 1] = $charToMove;
                        $needsSwapping = true;
                    }
                    // Reentering the loop looking at the old character again
                    $nextClass = $previousClass;
                }
                $previousClass = $nextClass;
            }
        }

        return $input;
    }
private function applyCanonicalOrdering ( array $ input ) : array { $ needsSwapping = true ; $ inputLength = count ( $ input ) ; while ( $ needsSwapping ) { $ needsSwapping = false ; $ previousClass = $ this -> getCombiningClass ( intval ( $ input [ 0 ] ) ) ; for ( $ outerIndex = 0 ; $ outerIndex < $ inputLength - 1 ; ++ $ outerIndex ) { $ nextClass = $ this -> getCombiningClass ( intval ( $ input [ $ outerIndex + 1 ] ) ) ; if ( $ nextClass !== 0 && $ previousClass > $ nextClass ) { // Move item leftward until it fits for ( $ innerIndex = $ outerIndex + 1 ; $ innerIndex > 0 ; -- $ innerIndex ) { if ( $ this -> getCombiningClass ( intval ( $ input [ $ innerIndex - 1 ] ) ) <= $ nextClass ) { break ; } $ charToMove = intval ( $ input [ $ innerIndex ] ) ; $ input [ $ innerIndex ] = intval ( $ input [ $ innerIndex - 1 ] ) ; $ input [ $ innerIndex - 1 ] = $ charToMove ; $ needsSwapping = true ; } // Reentering the loop looking at the old character again $ nextClass = $ previousClass ; } $ previousClass = $ nextClass ; } } return $ input ; }
Applies the canonical ordering of a decomposed UCS4 sequence
@param array  $input Decomposed UCS4 sequence
@return array Ordered USC4 sequence
Applies the canonical ordering of a decomposed UCS4 sequence