mirror of
https://github.com/flectar/mail.git
synced 2026-11-12 18:23:36 +00:00
perf: escape vCard values in one buffer
This commit is contained in:
1 parent
32557800ab
commit
d048cc699a
1 file changed
+18
-5
@@ -30,11 +30,24 @@ fn unescape(value: &str) -> String {
|
||||
}
|
||||
|
||||
fn escape(value: &str) -> String {
|
||||
value
|
||||
.replace('\\', "\\\\")
|
||||
.replace('\n', "\\n")
|
||||
.replace(';', "\\;")
|
||||
.replace(',', "\\,")
|
||||
let capacity = value
|
||||
.chars()
|
||||
.map(|ch| match ch {
|
||||
'\\' | '\n' | ';' | ',' => 2,
|
||||
_ => ch.len_utf8(),
|
||||
})
|
||||
.sum();
|
||||
let mut escaped = String::with_capacity(capacity);
|
||||
for ch in value.chars() {
|
||||
match ch {
|
||||
'\\' => escaped.push_str("\\\\"),
|
||||
'\n' => escaped.push_str("\\n"),
|
||||
';' => escaped.push_str("\\;"),
|
||||
',' => escaped.push_str("\\,"),
|
||||
_ => escaped.push(ch),
|
||||
}
|
||||
}
|
||||
escaped
|
||||
}
|
||||
|
||||
fn split_escaped(value: &str, delimiter: char) -> Vec<String> {
|
||||
|
||||
Reference in new issue
Block a user