aboutsummaryrefslogtreecommitdiffstats
path: root/src/common.rs
diff options
context:
space:
mode:
authorJan Tuomi <jan@jantuomi.fi>2024-10-05 10:00:45 +0200
committerJan Tuomi <jan@jantuomi.fi>2024-10-05 10:00:45 +0200
commit6532e4f4a94ada35c958cf53e1f98aaf175188c6 (patch)
tree2751105b940ef87a06f35ad90740c60e2141d652 /src/common.rs
parent47672de7f4fb917068923176658198d00d393ec8 (diff)
Split log_reader into reverse_log_reader and forward_log_reader
Diffstat (limited to 'src/common.rs')
-rw-r--r--src/common.rs16
1 files changed, 16 insertions, 0 deletions
diff --git a/src/common.rs b/src/common.rs
index 9ea43aa..ea179ab 100644
--- a/src/common.rs
+++ b/src/common.rs
@@ -39,6 +39,22 @@ pub const SEQ_LIT_FIELD_SEP: &[u8] = &[
ESCAPE_CHARACTER,
];
+/// There are three special sequences that need to be handled:
+/// Here: SC = escape char, FS = field separator.
+/// - SC FS FS SC -> actual record separator
+/// - SC SC FS SC -> literal FS
+/// - SC SC SC SC -> literal SC
+///
+/// Returns SpecialSequence or None if not valid.
+pub fn validate_special(buf: &[u8]) -> Option<SpecialSequence> {
+ match buf {
+ SEQ_RECORD_SEP => Some(SpecialSequence::RecordSeparator),
+ SEQ_LIT_FIELD_SEP => Some(SpecialSequence::LiteralFieldSeparator),
+ SEQ_LIT_ESCAPE => Some(SpecialSequence::LiteralEscape),
+ _ => None,
+ }
+}
+
#[derive(Debug, Eq, PartialEq)]
pub enum SpecialSequence {
RecordSeparator,