From af1cc6c54962b705cc20f8b0c4db28eb2bc809a4 Mon Sep 17 00:00:00 2001 From: dota17 Date: Wed, 1 Jul 2020 15:45:10 +0800 Subject: [PATCH] generate the Exp::CR() to support the escape of CR. --- src/emitterutils.cpp | 4 ++-- src/exp.h | 6 +++++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/emitterutils.cpp b/src/emitterutils.cpp index 0410f93..1eceb2a 100644 --- a/src/emitterutils.cpp +++ b/src/emitterutils.cpp @@ -176,11 +176,11 @@ bool IsValidPlainScalar(const std::string& str, FlowType::value flowType, static const RegEx& disallowed_flow = Exp::EndScalarInFlow() | (Exp::BlankOrBreak() + Exp::Comment()) | Exp::NotPrintable() | Exp::Utf8_ByteOrderMark() | Exp::Break() | - Exp::Tab(); + Exp::Tab() | Exp::CR(); static const RegEx& disallowed_block = Exp::EndScalar() | (Exp::BlankOrBreak() + Exp::Comment()) | Exp::NotPrintable() | Exp::Utf8_ByteOrderMark() | Exp::Break() | - Exp::Tab(); + Exp::Tab() | Exp::CR(); const RegEx& disallowed = flowType == FlowType::Flow ? disallowed_flow : disallowed_block; diff --git a/src/exp.h b/src/exp.h index 0b2b306..7ec82fb 100644 --- a/src/exp.h +++ b/src/exp.h @@ -32,6 +32,10 @@ inline const RegEx& Tab() { static const RegEx e = RegEx('\t'); return e; } +inline const RegEx& CR() { + static const RegEx e = RegEx('\r'); + return e; +} inline const RegEx& Blank() { static const RegEx e = Space() | Tab(); return e; @@ -69,7 +73,7 @@ inline const RegEx& Hex() { inline const RegEx& NotPrintable() { static const RegEx e = RegEx(0) | - RegEx("\x01\x02\x03\x04\x05\x06\x07\x08\x0B\x0C\x0D\x7F", REGEX_OR) | + RegEx("\x01\x02\x03\x04\x05\x06\x07\x08\x0B\x0C\x7F", REGEX_OR) | RegEx(0x0E, 0x1F) | (RegEx('\xC2') + (RegEx('\x80', '\x84') | RegEx('\x86', '\x9F'))); return e;