소스 검색

Merge branch 'master' of https://gitlab.com/nicolaswinkler/zombie

Nicolas Winkler 5 년 전
부모
커밋
863a6d61d7
1개의 변경된 파일37개의 추가작업 그리고 0개의 파일을 삭제
  1. 37 0
      src/formatter.rs

+ 37 - 0
src/formatter.rs

@@ -0,0 +1,37 @@
+
+
+
+pub struct Formatter {
+    indent: String,
+    code: String
+}
+
+
+
+impl Formatter {
+    pub fn new() -> Self {
+        Formatter {
+            indent: String::new(),
+            code: String::new()
+        }
+    }
+
+    pub fn add_line(&mut self, line: &str) {
+        self.code += &self.indent;
+        self.code += line;
+        self.code += "\n"
+    }
+
+    pub fn indent(&mut self) {
+        self.indent += "    ";
+    }
+    pub fn unindent(&mut self) {
+        if self.indent.len() >= 4 {
+            self.indent = (&self.indent[..(self.indent.len() - 4)]).to_string();
+        }
+    }
+
+    pub fn get_code(self) -> String {
+        self.code
+    }
+}