Esempio n. 1
0
        internal void WriteKDL(StreamWriter writer, int depth, PrintConfig printConfig) /*throws IOException*/
        {
            if (Nodes.Count == 0 && depth == 0)
            {
                writer.Write(printConfig.NewLine);
                return;
            }

            foreach (var node in Nodes)
            {
                for (int i = 0; i < printConfig.Indent * depth; i++)
                {
                    writer.Write(printConfig.IndentChar);
                }
                node.WriteKDLPretty(writer, depth, printConfig);
                if (printConfig.RequireSemicolons)
                {
                    writer.Write(';');
                }
                writer.Write(printConfig.NewLine);
            }
        }
Esempio n. 2
0
 public void WriteKDL(StreamWriter writer, PrintConfig printConfig)
 {
     WriteKDLPretty(writer, printConfig);
 }
Esempio n. 3
0
 public void WriteKDLPretty(StreamWriter writer, PrintConfig printConfig) // throws IOException
 {
     WriteKDL(writer, 0, printConfig);
 }
Esempio n. 4
0
 public void WriteKDL(StreamWriter writer, PrintConfig printConfig)
 => PrintUtil.WriteStringQuotedAppropriately(writer, Value, false, printConfig);
Esempio n. 5
0
 public void WriteKDL(StreamWriter writer, PrintConfig printConfig)
 => writer.Write(Value ? "true" : "false");
Esempio n. 6
0
 public void WriteKDL(StreamWriter writer, PrintConfig printConfig)
 => writer.Write(Value.ToString());
Esempio n. 7
0
 public void WriteKDL(StreamWriter writer, PrintConfig printConfig)
 => writer.Write("null");
Esempio n. 8
0
        public static void WriteStringQuotedAppropriately(
            StreamWriter writer,
            string str,
            bool bareAllowed,
            PrintConfig printConfig)
        {
            if (str.Length == 0)
            {
                writer.Write("\"\"");
                return;
            }

            int hashDepth = 0;

            if (!printConfig.EscapeNonPrintableAscii)
            {
                int quoteAt = str.IndexOf('"');
                while (quoteAt >= 0)
                {
                    int hashesNeeded = 1;
                    for (int i = quoteAt + 1; i < str.Length && str[i] == '#'; i++)
                    {
                        hashesNeeded++;
                    }
                    hashDepth = Math.Max(hashDepth, hashesNeeded);
                    quoteAt   = str.IndexOf('"', quoteAt + 1);
                }
            }

            if (hashDepth == 0 && !str.Contains("\\") && !str.Contains("\""))
            {
                if (bareAllowed && ValidBareId.IsMatch(str))
                {
                    writer.Write(str);
                }
                else
                {
                    writer.Write('"');
                    for (int i = 0; i < str.Length; i++)
                    {
                        char c = str[i];
                        if (IsPrintableAscii(c))
                        {
                            writer.Write(c);
                        }
                        else if (c == '\n' && printConfig.EscapeNewLines)
                        {
                            writer.Write("\\n");
                        }
                        else if (printConfig.EscapeNonPrintableAscii)
                        {
                            writer.Write(GetEscapeIncludingUnicode(c));
                        }
                        else if (printConfig.EscapeCommon)
                        {
                            writer.Write(GetCommonEscape(c) ?? c.ToString());
                        }
                        else
                        {
                            writer.Write(c);
                        }
                    }
                    writer.Write('"');
                }
            }
            else
            {
                writer.Write('r');
                for (int i = 0; i < hashDepth; i++)
                {
                    writer.Write('#');
                }

                writer.Write('"');
                writer.Write(str);
                writer.Write('"');

                for (int i = 0; i < hashDepth; i++)
                {
                    writer.Write('#');
                }
            }
        }