aboutsummaryrefslogtreecommitdiff
path: root/rust/src/printer.rs
diff options
context:
space:
mode:
authorJoel Martin <github@martintribe.org>2014-10-25 14:02:42 -0500
committerJoel Martin <github@martintribe.org>2015-01-06 21:58:57 -0600
commit0a4d62f2f8362290dfc956ba5c948794a77a6e4d (patch)
treeedf2cd63393da7c4f27068e236d13a3a4e32d530 /rust/src/printer.rs
parent8f5b0f1040de849da3fb5ade645308e7bbe7f025 (diff)
downloadmal-0a4d62f2f8362290dfc956ba5c948794a77a6e4d.tar.gz
mal-0a4d62f2f8362290dfc956ba5c948794a77a6e4d.zip
rust: add step4_if_fn_do
Diffstat (limited to 'rust/src/printer.rs')
-rw-r--r--rust/src/printer.rs19
1 files changed, 19 insertions, 0 deletions
diff --git a/rust/src/printer.rs b/rust/src/printer.rs
index 59821ec..f46b66c 100644
--- a/rust/src/printer.rs
+++ b/rust/src/printer.rs
@@ -1,3 +1,5 @@
+use types::MalVal;
+
pub fn escape_str(s: &str) -> String {
let mut escaped = String::new();
escaped.push('"');
@@ -24,3 +26,20 @@ pub fn unescape_str(s: &str) -> String {
let re2 = regex!(r#"\n"#);
re2.replace_all(re1.replace_all(s.as_slice(), "\"").as_slice(), "\n")
}
+
+pub fn pr_list(lst: &Vec<MalVal>, pr: bool,
+ start: &str , end: &str, join: &str) -> String {
+ let mut first = true;
+ let mut res = String::new();
+ res.push_str(start);
+ for mv in lst.iter() {
+ if first {
+ first = false;
+ } else {
+ res.push_str(join);
+ }
+ res.push_str(mv.pr_str(pr).as_slice());
+ }
+ res.push_str(end);
+ res
+}