1
1
mirror of https://github.com/kanaka/mal.git synced 2024-09-20 10:07:45 +03:00
mal/cs/printer.cs
Joel Martin b8ee29b22f All: add keywords.
Also, fix nth and count to match cloure.
2015-01-09 16:16:50 -06:00

50 lines
1.7 KiB
C#

using System;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using Mal;
using MalVal = Mal.types.MalVal;
using MalList = Mal.types.MalList;
namespace Mal {
public class printer {
public static string join(List<MalVal> value,
string delim, bool print_readably) {
List<string> strs = new List<string>();
foreach (MalVal mv in value) {
strs.Add(mv.ToString(print_readably));
}
return String.Join(delim, strs.ToArray());
}
public static string join(Dictionary<string,MalVal> value,
string delim, bool print_readably) {
List<string> strs = new List<string>();
foreach (KeyValuePair<string, MalVal> entry in value) {
if (entry.Key.Length > 0 && entry.Key[0] == '\u029e') {
strs.Add(":" + entry.Key.Substring(1));
} else if (print_readably) {
strs.Add("\"" + entry.Key.ToString() + "\"");
} else {
strs.Add(entry.Key.ToString());
}
strs.Add(entry.Value.ToString(print_readably));
}
return String.Join(delim, strs.ToArray());
}
public static string _pr_str(MalVal mv, bool print_readably) {
return mv.ToString(print_readably);
}
public static string _pr_str_args(MalList args, String sep,
bool print_readably) {
return join(args.getValue(), sep, print_readably);
}
public static string escapeString(string str) {
return Regex.Escape(str);
}
}
}