Inline utils module into parse

This commit is contained in:
Dirkjan Ochtman 2022-11-21 14:27:40 -08:00
parent 29dc6ceab4
commit db7fd2300f
4 changed files with 31 additions and 33 deletions

View File

@ -1,4 +1,2 @@
pub mod parse; pub mod parse;
pub mod types; pub mod types;
mod utils;

View File

@ -13,7 +13,7 @@ use nom::{
IResult, IResult,
}; };
use crate::{parse::imf::atom::is_atext, types::AtomOrQuoted, utils::unescape_quoted}; use crate::{parse::imf::atom::is_atext, types::AtomOrQuoted};
pub mod address; pub mod address;
pub mod command; pub mod command;
@ -150,6 +150,34 @@ pub fn Ldh_str(input: &[u8]) -> IResult<&[u8], &[u8]> {
// ------------------------------------------------------------------------------------------------- // -------------------------------------------------------------------------------------------------
pub(crate) fn escape_quoted(unescaped: &str) -> Cow<str> {
let mut escaped = Cow::Borrowed(unescaped);
if escaped.contains('\\') {
escaped = Cow::Owned(escaped.replace('\\', "\\\\"));
}
if escaped.contains('\"') {
escaped = Cow::Owned(escaped.replace('\"', "\\\""));
}
escaped
}
pub(crate) fn unescape_quoted(escaped: &str) -> Cow<str> {
let mut unescaped = Cow::Borrowed(escaped);
if unescaped.contains("\\\\") {
unescaped = Cow::Owned(unescaped.replace("\\\\", "\\"));
}
if unescaped.contains("\\\"") {
unescaped = Cow::Owned(unescaped.replace("\\\"", "\""));
}
unescaped
}
#[cfg(test)] #[cfg(test)]
pub mod test { pub mod test {
use super::sub_domain; use super::sub_domain;

View File

@ -3,7 +3,8 @@ use std::{borrow::Cow, fmt, io::Write, ops::Deref};
#[cfg(feature = "serde")] #[cfg(feature = "serde")]
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use crate::{parse::response::is_text_string_byte, utils::escape_quoted}; use crate::parse::escape_quoted;
use crate::parse::response::is_text_string_byte;
#[derive(Clone, Debug, PartialEq, Eq)] #[derive(Clone, Debug, PartialEq, Eq)]
pub enum Command { pub enum Command {

View File

@ -1,29 +0,0 @@
use std::borrow::Cow;
pub(crate) fn escape_quoted(unescaped: &str) -> Cow<str> {
let mut escaped = Cow::Borrowed(unescaped);
if escaped.contains('\\') {
escaped = Cow::Owned(escaped.replace('\\', "\\\\"));
}
if escaped.contains('\"') {
escaped = Cow::Owned(escaped.replace('\"', "\\\""));
}
escaped
}
pub(crate) fn unescape_quoted(escaped: &str) -> Cow<str> {
let mut unescaped = Cow::Borrowed(escaped);
if unescaped.contains("\\\\") {
unescaped = Cow::Owned(unescaped.replace("\\\\", "\\"));
}
if unescaped.contains("\\\"") {
unescaped = Cow::Owned(unescaped.replace("\\\"", "\""));
}
unescaped
}