mirror of
https://github.com/sharkdp/bat
synced 2026-08-26 14:13:37 +01:00
improve patch
This commit is contained in:
+3
-5
@@ -155,11 +155,9 @@ pub fn sanitize(line: &str) -> String {
|
|||||||
let bytes = stripped.as_bytes();
|
let bytes = stripped.as_bytes();
|
||||||
let mut start = 0;
|
let mut start = 0;
|
||||||
let mut i = 0;
|
let mut i = 0;
|
||||||
while i < bytes.len() {
|
// Skip directly to the next trigger byte instead of testing each one.
|
||||||
if !is_sanitize_trigger(bytes[i]) {
|
while let Some(off) = bytes[i..].iter().position(|&b| is_sanitize_trigger(b)) {
|
||||||
i += 1;
|
i += off;
|
||||||
continue;
|
|
||||||
}
|
|
||||||
let len = sanitize_at(bytes, i, &stripped, &mut buffer, &mut start);
|
let len = sanitize_at(bytes, i, &stripped, &mut buffer, &mut start);
|
||||||
i += len;
|
i += len;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -194,13 +194,10 @@ impl<'a> PrettyPrinter<'a> {
|
|||||||
|
|
||||||
/// Whether to sanitize untrusted input for safe display (default: never)
|
/// Whether to sanitize untrusted input for safe display (default: never)
|
||||||
///
|
///
|
||||||
/// Implies [`strip_ansi`](Self::strip_ansi) at the same value, and also
|
/// Strips ANSI escape sequences and additionally substitutes terminal-active
|
||||||
/// replaces terminal-active and bidi / zero-width bytes with U+FFFD.
|
/// control bytes and bidi / zero-width codepoints with U+FFFD.
|
||||||
pub fn sanitize(&mut self, mode: StripAnsiMode) -> &mut Self {
|
pub fn sanitize(&mut self, mode: StripAnsiMode) -> &mut Self {
|
||||||
self.config.sanitize = mode;
|
self.config.sanitize = mode;
|
||||||
if mode != StripAnsiMode::Never {
|
|
||||||
self.config.strip_ansi = mode;
|
|
||||||
}
|
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user