vault/classes/Maikuolan/Demojibakefier.php
public function normalise($String)
    {
        $this->Last = '';
        $this->Len = strlen($String);
        /** Potential valid candidates will be populated here. */
        $Valid = [];
        /** Suppress errors (because every failed normalisation attempt will generate errors and fill logs otherwise). */
        set_error_handler(function ($errno) {
            return;
        });
        /** Cycle through supported encodings and attempt to generate valid candidates. */
        foreach ($this->supported() as $Encoding) {
            if (!$this->checkConformity($String, $Encoding)) {
                continue;
            }
            $Attempt = iconv($Encoding, $this->NormaliseTo, $String);
            if ($Attempt === false || !$this->checkConformity($Attempt, $this->NormaliseTo)) {
                continue;
            }
            if (strcmp(iconv($this->NormaliseTo, $Encoding, $Attempt), $String) === 0) {
                $Valid[$Encoding] = $Attempt;
                if ($Encoding === $this->NormaliseTo) {
                    break;
                }
            }
        }
        /** We're done.. Restore the error handler. */
        restore_error_handler();
        /** If the string conforms to our desired encoding, and can be reversed to it, we'll go with that. */
        if (isset($Valid[$this->NormaliseTo])) {
            $this->Last = $this->NormaliseTo;
            return $Valid[$this->NormaliseTo];
        }
        /** Okay.. Doesn't conform or can't be reversed. Time to apply weighting and some fuzzy heuristic guesswork. */
        foreach ($Valid as $Key => $Value) {
            $Valid[$Key] = ['String' => $Value, 'Weight' => 0];
        }
        $this->weigh($String, $Valid);
        /** Sort weights from highest to lowest and attempt to reduce candidates by the largest weight. */
        uasort($Valid, function ($A, $B) {
            return $A['Weight'] === $B['Weight'] ? 0 : ($A['Weight'] < $B['Weight'] ? 1 : -1);
        });
        $this->dropVariants($Valid);
        $Current = key($Valid);
        foreach ($Valid as $Key => $Value) {
            if ($Value['Weight'] < $Valid[$Current]['Weight']) {
                unset($Valid[$Key]);
            }
        }
        /** Check whether we can return a single possible value. */
        if (($Count = count($Valid)) === 1) {
            $this->Last = $Current;
            return $Valid[$Current]['String'];
        }
        /** If we haven't decided on a particular candidate by this pointm we'll just give up and return the original string. */
        return $String;
    }
public function normalise($String)
    {
        $this->Last = '';
        $this->Len = strlen($String);
        /** Potential valid candidates will be populated here. */
        $Valid = [];
        /** Suppress errors (because every failed normalisation attempt will generate errors and fill logs otherwise). */
        set_error_handler(function ($errno) {
            return;
        });
        /** Cycle through supported encodings and attempt to generate valid candidates. */
        foreach ($this->supported() as $Encoding) {
            if (!$this->checkConformity($String, $Encoding)) {
                continue;
            }
            $Attempt = iconv($Encoding, $this->NormaliseTo, $String);
            if ($Attempt === false || !$this->checkConformity($Attempt, $this->NormaliseTo)) {
                continue;
            }
            if (strcmp(iconv($this->NormaliseTo, $Encoding, $Attempt), $String) === 0) {
                $Valid[$Encoding] = $Attempt;
                if ($Encoding === $this->NormaliseTo) {
                    break;
                }
            }
        }
        /** We're done.. Restore the error handler. */
        restore_error_handler();
        /** If the string conforms to our desired encoding, and can be reversed to it, we'll go with that. */
        if (isset($Valid[$this->NormaliseTo])) {
            $this->Last = $this->NormaliseTo;
            return $Valid[$this->NormaliseTo];
        }
        /** Okay.. Doesn't conform or can't be reversed. Time to apply weighting and some fuzzy heuristic guesswork. */
        foreach ($Valid as $Key => $Value) {
            $Valid[$Key] = ['String' => $Value, 'Weight' => 0];
        }
        $this->weigh($String, $Valid);
        /** Sort weights from highest to lowest and attempt to reduce candidates by the largest weight. */
        uasort($Valid, function ($A, $B) {
            return $A['Weight'] === $B['Weight'] ? 0 : ($A['Weight'] < $B['Weight'] ? 1 : -1);
        });
        $this->dropVariants($Valid);
        $Current = key($Valid);
        foreach ($Valid as $Key => $Value) {
            if ($Value['Weight'] < $Valid[$Current]['Weight']) {
                unset($Valid[$Key]);
            }
        }
        /** Check whether we can return a single possible value. */
        if (($Count = count($Valid)) === 1) {
            $this->Last = $Current;
            return $Valid[$Current]['String'];
        }
        /** If we haven't decided on a particular candidate by this pointm we'll just give up and return the original string. */
        return $String;
    }
public function normalise ( $ String ) { $ this -> Last = '' ; $ this -> Len = strlen ( $ String ) ; /** Potential valid candidates will be populated here. */ $ Valid = [ ] ; /** Suppress errors (because every failed normalisation attempt will generate errors and fill logs otherwise). */ set_error_handler ( function ( $ errno ) { return ; } ) ; /** Cycle through supported encodings and attempt to generate valid candidates. */ foreach ( $ this -> supported ( ) as $ Encoding ) { if ( ! $ this -> checkConformity ( $ String , $ Encoding ) ) { continue ; } $ Attempt = iconv ( $ Encoding , $ this -> NormaliseTo , $ String ) ; if ( $ Attempt === false || ! $ this -> checkConformity ( $ Attempt , $ this -> NormaliseTo ) ) { continue ; } if ( strcmp ( iconv ( $ this -> NormaliseTo , $ Encoding , $ Attempt ) , $ String ) === 0 ) { $ Valid [ $ Encoding ] = $ Attempt ; if ( $ Encoding === $ this -> NormaliseTo ) { break ; } } } /** We're done.. Restore the error handler. */ restore_error_handler ( ) ; /** If the string conforms to our desired encoding, and can be reversed to it, we'll go with that. */ if ( isset ( $ Valid [ $ this -> NormaliseTo ] ) ) { $ this -> Last = $ this -> NormaliseTo ; return $ Valid [ $ this -> NormaliseTo ] ; } /** Okay.. Doesn't conform or can't be reversed. Time to apply weighting and some fuzzy heuristic guesswork. */ foreach ( $ Valid as $ Key => $ Value ) { $ Valid [ $ Key ] = [ 'String' => $ Value , 'Weight' => 0 ] ; } $ this -> weigh ( $ String , $ Valid ) ; /** Sort weights from highest to lowest and attempt to reduce candidates by the largest weight. */ uasort ( $ Valid , function ( $ A , $ B ) { return $ A [ 'Weight' ] === $ B [ 'Weight' ] ? 0 : ( $ A [ 'Weight' ] < $ B [ 'Weight' ] ? 1 : - 1 ) ; } ) ; $ this -> dropVariants ( $ Valid ) ; $ Current = key ( $ Valid ) ; foreach ( $ Valid as $ Key => $ Value ) { if ( $ Value [ 'Weight' ] < $ Valid [ $ Current ] [ 'Weight' ] ) { unset ( $ Valid [ $ Key ] ) ; } } /** Check whether we can return a single possible value. */ if ( ( $ Count = count ( $ Valid ) ) === 1 ) { $ this -> Last = $ Current ; return $ Valid [ $ Current ] [ 'String' ] ; } /** If we haven't decided on a particular candidate by this pointm we'll just give up and return the original string. */ return $ String ; }
Attempts to normalise a string.

@param string $String The string to normalise.
@return string The normalised string (could be the same as the input, if there isn't anything to normalise).
Attempts to normalise a string .