1use std::fmt::{self, Formatter};
2
3use super::{
4 super::{escaping::*, TEXT_RE},
5 *,
6};
7
8validated_customized_regex_string!(pub Text, ref TEXT_RE);
9
10validated_customized_regex_string!(pub Component, ref TEXT_RE);
11
12impl Text {
13 pub fn is_empty(&self) -> bool {
14 self.as_str().is_empty()
15 }
16}
17
18impl Value for Text {
19 fn fmt(&self, f: &mut Formatter) -> Result<(), fmt::Error> {
20 if self.is_empty() {
21 return Ok(());
22 }
23
24 let c = escape_backslash(self.as_str());
25 let c = escape_new_line(c.as_ref());
26 let c = escape_tab(c.as_ref());
27 let c = escape_comma(c.as_ref());
28
29 f.write_str(c.as_ref())?;
30
31 Ok(())
32 }
33}
34
35impl Component {
36 pub fn is_empty(&self) -> bool {
37 self.as_str().is_empty()
38 }
39}
40
41impl Value for Component {
42 fn fmt(&self, f: &mut Formatter) -> Result<(), fmt::Error> {
43 if self.is_empty() {
44 return Ok(());
45 }
46
47 let c = escape_backslash(self.as_str());
48 let c = escape_new_line(c.as_ref());
49 let c = escape_tab(c.as_ref());
50 let c = escape_comma(c.as_ref());
51 let c = escape_semicolon(c.as_ref());
52
53 f.write_str(c.as_ref())?;
54
55 Ok(())
56 }
57}