rbatis_codegen/codegen/syntax_tree_pysql/
trim_node.rs

1use crate::codegen::syntax_tree_pysql::{Name, NodeType, ToHtml};
2
3/// Represents a `trim` node in py_sql.
4/// It's used to remove leading and/or trailing characters from a string.
5/// 
6/// # Examples
7/// 
8/// PySQL syntax:
9/// ```py
10/// trim ',' 
11/// trim start=',' 
12/// trim end=',' 
13/// ```
14#[derive(Clone, Debug, Eq, PartialEq)]
15pub struct TrimNode {
16    pub childs: Vec<NodeType>,
17    pub start: String,
18    pub end: String,
19}
20
21impl Name for TrimNode {
22    fn name() -> &'static str {
23        "trim"
24    }
25}
26
27impl ToHtml for TrimNode {
28    fn as_html(&self) -> String {
29        let mut childs = String::new();
30        for x in &self.childs {
31            childs.push_str(&x.as_html());
32        }
33        format!(
34            "<trim prefixOverrides=\"{}\" suffixOverrides=\"{}\">{}</trim>",
35            self.start, self.end, childs
36        )
37    }
38}