MCPcopy Create free account
hub / github.com/Genivia/ugrep / init_is_binary

Method init_is_binary

src/ugrep.cpp:4017–4036  ·  view source on GitHub ↗

initial part of a file is binary

Source from the content-addressed store, hash-verified

4015
4016 // initial part of a file is binary
4017 bool init_is_binary()
4018 {
4019 // check initial input for binary data, fill up to 131072 bytes to check (similar GNU grep, but a bit more)
4020 size_t avail = matcher->avail(reflex::AbstractMatcher::Const::BUFSZ);
4021 if (avail == 0)
4022 return false;
4023
4024 // do not cut off the last UTF-8 sequence, ignore it, otherwise we risk failing the UTF-8 check
4025 const char *buf = matcher->begin();
4026 if ((buf[avail - 1] & 0x80) == 0x80)
4027 {
4028 size_t n = std::min<size_t>(avail, 4); // note: 1 <= n <= 4 bytes to check
4029 while (n > 0 && (buf[--avail] & 0xc0) == 0x80)
4030 --n;
4031 if ((buf[avail] & 0xc0) != 0xc0)
4032 return true;
4033 }
4034
4035 return is_binary(matcher->begin(), avail);
4036 }
4037
4038 // output the rest of the matching line or save it for later, uses lineno of previous match to check
4039 void output_or_save_restline(bool invert = false, bool hex_context = false)

Callers

nothing calls this directly

Calls 3

availMethod · 0.80
is_binaryFunction · 0.70
beginMethod · 0.45

Tested by

no test coverage detected