diff-match-patch icon indicating copy to clipboard operation
diff-match-patch copied to clipboard

Optimize Unicode chr/ord

Open ranvis opened this issue 5 years ago • 1 comments

Small optimization for unicodeChr() and unicodeOrd().

ranvis avatar Feb 21 '20 23:02 ranvis

The maintainer of this project and the author of this PR have probably moved on a long time ago.

For anyone stopping by here, in modern versions of you PHP you can just do:

    public static function unicodeChr($code) {
        return mb_chr($code, 'UCS-2LE');
    }

    public static function unicodeOrd($char) {
       return mb_ord($char, 'UCS-2LE');
    }

Note that in my private patched copy of yetanotherape/diff-match-patch I'm using UTF-8 everywhere instead of UCS-2LE. Without having tested it, I would wager that the mb_* functions will also work when the encoding is UCS-2LE.

shuuryou avatar Mar 15 '24 11:03 shuuryou