Overview
Comment:The code provided by PHP.watch was broken, fix it, and use utf8_encode silently until it's not available anymore
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk | stable
Files: files | file ages | folders
SHA3-256: 4f31e7e26a2aa5bf2d32bcac86914f79a87f44729744437a73361ff1680e5598
User & Date: bohwaz on 2023-01-30 20:14:47
Other Links: manifest | tags
Context
2023-01-30
20:19
If we cannot find any user data it probably means this CSV is not from our own format, so abort check-in: 238e1a40f3 user: bohwaz tags: trunk, stable
20:14
The code provided by PHP.watch was broken, fix it, and use utf8_encode silently until it's not available anymore check-in: 4f31e7e26a user: bohwaz tags: trunk, stable
18:40
Don't use deprecated utf8_encode with PHP 8.2+ check-in: ebc88679fa user: bohwaz tags: trunk, stable
Changes

Modified src/include/lib/Garradin/Utils.php from [c3641cb48b] to [fbcc56cf50].

921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
        }

        // Check if string is already UTF-8 encoded or not
        return !preg_match('//u', $str) ? self::iso8859_1_to_utf8($str) : $str;
    }

    /**
     * Poly-fill to encode a ISO-8859-1 string to UTF-8 for PHP > =8.2
     * @see https://php.watch/versions/8.2/utf8_encode-utf8_decode-deprecated
     */
    static public function iso8859_1_to_utf8(string $string): string
    {
        if (PHP_VERSION_ID < 80200) {
            return utf8_encode($string);
        }

        $s = $string;
        $len = strlen($s);

        for ($i = $len >> 1, $j = 0; $i < $len; ++$i, ++$j) {
            switch (true) {
                case $s[$i] < "\x80":
                    $s[$j] = $s[$i];
                    break;







|


|

|
|


|







921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
        }

        // Check if string is already UTF-8 encoded or not
        return !preg_match('//u', $str) ? self::iso8859_1_to_utf8($str) : $str;
    }

    /**
     * Poly-fill to encode a ISO-8859-1 string to UTF-8 for PHP >= 9.0
     * @see https://php.watch/versions/8.2/utf8_encode-utf8_decode-deprecated
     */
    static public function iso8859_1_to_utf8(string $s): string
    {
        if (PHP_VERSION_ID < 90000) {
            return @utf8_encode($s);
        }

        $s .= $s;
        $len = strlen($s);

        for ($i = $len >> 1, $j = 0; $i < $len; ++$i, ++$j) {
            switch (true) {
                case $s[$i] < "\x80":
                    $s[$j] = $s[$i];
                    break;