Inline utils module into parse
This commit is contained in:
parent
29dc6ceab4
commit
db7fd2300f
|
@ -1,4 +1,2 @@
|
|||
pub mod parse;
|
||||
pub mod types;
|
||||
|
||||
mod utils;
|
||||
|
|
|
@ -13,7 +13,7 @@ use nom::{
|
|||
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 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)]
|
||||
pub mod test {
|
||||
use super::sub_domain;
|
||||
|
|
|
@ -3,7 +3,8 @@ use std::{borrow::Cow, fmt, io::Write, ops::Deref};
|
|||
#[cfg(feature = "serde")]
|
||||
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)]
|
||||
pub enum Command {
|
||||
|
|
29
src/utils.rs
29
src/utils.rs
|
@ -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
|
||||
}
|
Loading…
Reference in New Issue