public string RepString(string code) { RCValue result = Rep(code, restoreStateOnError: false); if (result == null) { return(""); } return(result.Format(RCFormat.DefaultNoT)); }
public override void BodyToString(StringBuilder builder, RCFormat args, int level) { _code.Format(builder, args, level); }
public static void DoFormat(RCTemplate template, StringBuilder builder, RCFormat args, RCColmap colmap, int level) { // templates need to follow the same indenting rules as everyone else please. builder.Append("["); builder.Append('?', template.EscapeCount); // Use AppendLine not args.Newline, because the newline is signficant // and needs to be there no matter what. Otherwise when we parse it again ++level; if (template.Multiline) { builder.Append("\n"); for (int tab = args.Fragment ? 1 : 0; tab < level; ++tab) { builder.Append(args.Indent); } } for (int i = 0; i < template.Count - 1; ++i) { RCValue child = template.Get(i); RCString str = child as RCString; if (str != null && i % 2 == 0) { for (int j = 0; j < str.Count; ++j) { // Now go through str one char at a time to find the newlines. int start = 0, end = 0; for (; end < str[j].Length; ++end) { if (str[j][end] == '\n') { string line = str[j].Substring(start, end - start); builder.Append(line); builder.Append("\n"); if (i < template.Count - 2 || end < str[j].Length - 1) { for (int tab = args.Fragment ? 1 : 0; tab < level; ++tab) { builder.Append(args.Indent); } } start = end + 1; } else if (end == str[j].Length - 1) { builder.Append(str[j].Substring(start, 1 + end - start)); } } } } else { if (template.Multiline) { // for (int tab = 0; tab < level; ++tab) // { // builder.Append (args.Indent); // } /* * int k = builder.Length - 1; * while (k >= 0) * { * if (builder[k] == '\n') * { * for (int tab = 0; tab < level; ++tab) * { * builder.Append (args.Indent); * } * break; * } * else if (builder[k] != ' ') * { * break; * } * --k; * } */ } builder.Append("["); builder.Append('!', template.EscapeCount); builder.Append(' '); child.Format(builder, RCFormat.Default, colmap, level); builder.Append(' '); builder.Append('!', template.EscapeCount); builder.Append("]"); } } --level; if (template.Multiline) { for (int tab = args.Fragment ? 1 : 0; tab < level; ++tab) { builder.Append(args.Indent); } } builder.Append('?', template.EscapeCount); builder.Append("]"); }
public void EvalFormat(RCRunner runner, RCClosure closure, object left, object right) { // eventually should support xml and json, maybe csv? string which = "default"; RCSymbol format = (RCSymbol)left; RCValue content = (RCValue)right; which = format[0].Part(0).ToString(); string result = null; if (which.Equals("default")) { result = content.Format(RCFormat.Default); } else if (which.Equals("pretty")) { result = content.Format(RCFormat.Pretty); } else if (which.Equals("defaultnot")) { result = content.Format(RCFormat.DefaultNoT); } else if (which.Equals("canonical")) { result = content.Format(RCFormat.Canonical); } else if (which.Equals("testcanonical")) { result = content.Format(RCFormat.TestCanonical); } else if (which.Equals("fragment")) { result = content.Format(RCFormat.EditorFragment); } else if (which.Equals("html")) { // content must be a cube result = content.Format(RCFormat.Html); } else if (which.Equals("csv")) { // content must be a cube result = content.Format(RCFormat.Csv); } else if (which.Equals("log")) { // content must be a cube containing expected logging fields result = content.Format(RCFormat.Log); } else if (which.Equals("json")) { result = content.Format(RCFormat.Json); } else if (which.Equals("text")) { result = DoTextFormat(right, Environment.NewLine); } else if (which.Equals("textcrlf")) { result = DoTextFormat(right, "\r\n"); } else if (which.Equals("textlf")) { result = DoTextFormat(right, "\n"); } else { throw new Exception("Unknown format:" + which); } runner.Yield(closure, new RCString(result)); }