• N
    grep/pcre: support utf-8 · 18547aac
    Nguyễn Thái Ngọc Duy 提交于
    In the previous change in this function, we add locale support for
    single-byte encodings only. It looks like pcre only supports utf-* as
    multibyte encodings, the others are left in the cold (which is
    fine).
    
    We need to enable PCRE_UTF8 so pcre can find character boundary
    correctly. It's needed for case folding (when --ignore-case is used)
    or '*', '+' or similar syntax is used.
    
    The "has_non_ascii()" check is to be on the conservative side. If
    there's non-ascii in the pattern, the searched content could still be
    in utf-8, but we can treat it just like a byte stream and everything
    should work. If we force utf-8 based on locale only and pcre validates
    utf-8 and the file content is in non-utf8 encoding, things break.
    Noticed-by: NPlamen Totev <plamen.totev@abv.bg>
    Helped-by: NPlamen Totev <plamen.totev@abv.bg>
    Signed-off-by: NNguyễn Thái Ngọc Duy <pclouds@gmail.com>
    Signed-off-by: NJunio C Hamano <gitster@pobox.com>
    18547aac
grep.c 43.1 KB