Help class for writing a Yaml tree to a string
Beispiel #1
0
        /// <summary> Return a Yaml string </summary>
        public string Write()
        {
            StringWriter stringWriter = new StringWriter();
            WriteStream  writeStream  = new WriteStream(stringWriter);

            Write(writeStream);

            stringWriter.Close();
            return(stringWriter.ToString());
        }
Beispiel #2
0
 /// <summary> Write to YAML </summary>
 protected internal override void Write(WriteStream stream)
 {
     if (Content)
     {
         stream.Append("y");
     }
     else
     {
         stream.Append("n");
     }
 }
Beispiel #3
0
        /// <summary> Write back to a stream </summary>
        protected internal override void Write(WriteStream stream)
        {
            foreach (Node node in childNodes)
            {
                stream.Append("- ");

                stream.Indent();
                node.Write(stream);
                stream.UnIndent();
            }
        }
Beispiel #4
0
        /// <summary>
        ///   Write a YAML tree to a file
        /// </summary>
        public void ToFile(string filename, Encoding enc)
        {
            // Open YAML file
            StreamWriter writer      = new StreamWriter(filename, false, enc);
            WriteStream  writestream = new WriteStream(writer);

            // Write
            Write(writestream);

            // Close YAML file
            writer.Close();
        }
Beispiel #5
0
        /// <summary>
        ///   Write the base64 content to YAML
        /// </summary>
        /// <remarks> The lines are splitted in blocks of 20 bytes </remarks>
        protected internal override void Write(WriteStream stream)
        {
            stream.Append("!!binary |" + "\n");

            string bin = System.Convert.ToBase64String(content);

            while (bin.Length > 75)
            {
                stream.Append("  " + bin.Substring(0, 75) + "\n");
                bin = bin.Substring(75);
            }
            stream.Append("  " + bin);

            // Old coden, everything on one line
            // stream.Append ("!!binary \"" + System.Convert.ToBase64String (content) + "\"");
        }
Beispiel #6
0
        /// <summary> Write to YAML </summary>
        protected internal override void Write(WriteStream stream)
        {
            foreach (MappingNode node in childNodes)
            {
                stream.Append("? ");

                stream.Indent();
                Yaml.Node key = node.Key;
                key.Write(stream);
                stream.UnIndent();

                stream.Append(": ");

                stream.Indent();
                node.Value.Write(stream);
                stream.UnIndent();
            }
        }
Beispiel #7
0
        /// <summary> Write to a YAML node </summary>
        protected internal override void Write(WriteStream stream)
        {
            if (content.Equals(double.NaN))
            {
                stream.Append("!!float .NaN");
            }

            else if (content.Equals(double.NegativeInfinity))
            {
                stream.Append("!!float -.Inf");
            }

            else if (content.Equals(double.PositiveInfinity))
            {
                stream.Append("!!float +.Inf");
            }

            else
            {
                stream.Append("!!float " + content);
            }
        }
        /// <summary> Write to YAML </summary>
        protected internal override void Write(WriteStream stream)
        {
            foreach (MappingNode node in childNodes)
            {
                stream.Append ("? ");

                stream.Indent ();
                Yaml.Node key = node.Key;
                key.Write (stream);
                stream.UnIndent ();

                stream.Append (": ");

                stream.Indent ();
                node.Value.Write (stream);
                stream.UnIndent ();
            }
        }
 /// <summary> Write to YAML </summary>
 protected internal override void Write(WriteStream stream)
 {
     if (Content)
         stream.Append ("y");
     else
         stream.Append ("n");
 }
Beispiel #10
0
 /// <summary> Write to YAML </summary>
 protected internal override void Write(WriteStream stream)
 {
     stream.Append(content.ToString());
 }
Beispiel #11
0
        /// <summary> Write </summary>
        protected internal override void Write(WriteStream stream)
        {
            // TODO, not required, but writing to block or folded scalars
            //       generates a little more neat code.

            // Analyze string
            bool multiline    = false;
            bool mustbequoted = false;

            for (int i = 0; i < content.Length; i++)
            {
                char c = content [i];

                if (c == '\n')
                {
                    multiline = true;
                }

                // We quote everything except strings like /[a-zA-Z]*/
                // However there are more strings which don't require
                // quotes.
                if (!(c >= 'a' && c <= 'z' || c >= 'A' && c <= 'Z'))
                {
                    mustbequoted = true;
                }
            }

            // Double quoted strings
            if (mustbequoted)
            {
                stream.Append("\"");

                for (int i = 0; i < content.Length; i++)
                {
                    char c = content [i];

                    // Backslash
                    if (c == '\\')
                    {
                        stream.Append("\\" + "\\");
                    }

                    // Double quote
                    else if (c == '\"')
                    {
                        stream.Append("\\" + "\"");
                    }

                    // Single quote
                    else if (c == '\'')
                    {
                        stream.Append("\\" + "\'");
                    }

                    // ASCII null
                    else if (c == '\0')
                    {
                        stream.Append("\\0");
                    }

                    // ASCII bell
                    else if (c == (char)0x7)
                    {
                        stream.Append("\\a");
                    }

                    // ASCII backspace
                    else if (c == (char)0x8)
                    {
                        stream.Append("\\b");
                    }

                    // ASCII horizontal tab
                    else if (c == (char)0x9)
                    {
                        stream.Append("\\t");
                    }

                    // ASCII newline
                    else if (c == (char)0xA)
                    {
                        stream.Append("\\n");
                    }

                    // ASCII vertical tab
                    else if (c == (char)0xB)
                    {
                        stream.Append("\\v");
                    }

                    // ASCII form feed
                    else if (c == (char)0xC)
                    {
                        stream.Append("\\f");
                    }

                    // ASCII carriage return
                    else if (c == (char)0xD)
                    {
                        stream.Append("\\r");
                    }

                    // ASCII escape
                    else if (c == (char)0x1D)
                    {
                        stream.Append("\\e");
                    }

                    // Unicode next line
                    else if (c == (char)0x85)
                    {
                        stream.Append("\\N");
                    }

                    // Unicode non breaking space
                    else if (c == (char)0xA0)
                    {
                        stream.Append("\\_");
                    }

                    // TODO larger unicode characters

                    else
                    {
                        stream.Append("" + c);
                    }
                }
                stream.Append("\"");
            }

            // Simple non-quoted strings
            else
            {
                stream.Append(content);
            }
        }
        /// <summary> Write </summary>
        protected internal override void Write(WriteStream stream)
        {
            // TODO, not required, but writing to block or folded scalars
            //       generates a little more neat code.

            // Analyze string
            bool multiline    = false;
            bool mustbequoted = false;

            for (int i = 0; i < content.Length; i ++)
            {
                char c = content [i];

                if (c == '\n')
                    multiline = true;

                // We quote everything except strings like /[a-zA-Z]*/
                // However there are more strings which don't require
                // quotes.
                if ( ! ( c >= 'a' && c <= 'z' || c >= 'A' && c <= 'Z'))
                    mustbequoted = true;
            }

            // Double quoted strings
            if (mustbequoted)
            {
                stream.Append ("\"");

                for (int i = 0; i < content.Length; i ++)
                {
                    char c = content [i];

                    // Backslash
                    if (c == '\\')             stream.Append ("\\" + "\\");

                    // Double quote
                    else if (c == '\"')        stream.Append ("\\" + "\"");

                    // Single quote
                    else if (c == '\'')        stream.Append ("\\" + "\'");

                    // ASCII null
                    else if (c == '\0')        stream.Append ("\\0");

                    // ASCII bell
                    else if (c == (char) 0x7)  stream.Append ("\\a");

                    // ASCII backspace
                    else if (c == (char) 0x8)  stream.Append ("\\b");

                    // ASCII horizontal tab
                    else if (c == (char) 0x9)  stream.Append ("\\t");

                    // ASCII newline
                    else if (c == (char) 0xA)  stream.Append ("\\n");

                    // ASCII vertical tab
                    else if (c == (char) 0xB)  stream.Append ("\\v");

                    // ASCII form feed
                    else if (c == (char) 0xC)  stream.Append ("\\f");

                    // ASCII carriage return
                    else if (c == (char) 0xD)  stream.Append ("\\r");

                    // ASCII escape
                    else if (c == (char) 0x1D)  stream.Append ("\\e");

                    // Unicode next line
                    else if (c == (char) 0x85)  stream.Append ("\\N");

                    // Unicode non breaking space
                    else if (c == (char) 0xA0)  stream.Append ("\\_");

                    // TODO larger unicode characters

                    else
                        stream.Append ("" + c);
                }
                stream.Append ("\"");
            }

            // Simple non-quoted strings
            else
                stream.Append (content);
        }
 /// <summary> Write to YAML </summary>
 protected internal override void Write(WriteStream stream)
 {
     stream.Append (YamlString ());
 }
Beispiel #14
0
 /// <summary> Write to YAML </summary>
 protected internal override void Write(WriteStream stream)
 {
     stream.Append("~");
 }
Beispiel #15
0
 /// <summary>
 ///   Writes a Yaml tree back to a file or stream
 /// </summary>
 /// <remarks>
 ///   should not be called from outside the parser. This method
 ///   is only public from inside the Sequence and Mapping Write
 ///   methods.
 /// </remarks>
 /// <param name="stream">Were the output data go's</param>
 protected internal virtual void Write(WriteStream stream)
 {
 }
 /// <summary> Write to YAML </summary>
 protected internal override void Write(WriteStream stream)
 {
     stream.Append (content.ToString ());
 }
		/// <summary>
		///   Writes a Yaml tree back to a file or stream  
		/// </summary>
		/// <remarks>
		///   should not be called from outside the parser. This method
		///   is only public from inside the Sequence and Mapping Write
		///   methods.
		/// </remarks>
		/// <param name="stream">Were the output data go's</param>
		protected internal virtual void Write (WriteStream stream) {}
		/// <summary>
		///   Write a YAML tree to a file
		/// </summary>
		public void ToFile (string filename, Encoding enc)
		{
			// Open YAML file
			StreamWriter writer = new StreamWriter (filename, false, enc);
			WriteStream writestream = new WriteStream (writer);

			// Write
			Write (writestream);

			// Close YAML file
			writer.Close ();
		}
		/// <summary> Return a Yaml string </summary>
		public string Write ()
		{
			StringWriter stringWriter = new StringWriter ();
			WriteStream writeStream = new WriteStream (stringWriter);

			Write (writeStream);

			stringWriter.Close ();
			return stringWriter.ToString ();
		}
 /// <summary> Write to YAML </summary>
 protected internal override void Write(WriteStream stream)
 {
     stream.Append ("~");
 }
Beispiel #21
0
 /// <summary> Write to YAML </summary>
 protected internal override void Write(WriteStream stream)
 {
     stream.Append(YamlString());
 }
        /// <summary> Write back to a stream </summary>
        protected internal override void Write(WriteStream stream)
        {
            foreach (Node node in childNodes)
            {
                stream.Append ("- ");

                stream.Indent ();
                node.Write (stream);
                stream.UnIndent ();
            }
        }
        /// <summary>
        ///   Write the base64 content to YAML
        /// </summary>
        /// <remarks> The lines are splitted in blocks of 20 bytes </remarks>
        protected internal override void Write(WriteStream stream)
        {
            stream.Append("!!binary |" + "\n" );

            string bin = System.Convert.ToBase64String(content);

            while (bin.Length > 75)
            {
                stream.Append("  " + bin.Substring(0, 75) + "\n");
                bin = bin.Substring(75);
            }
            stream.Append("  " + bin );

            // Old coden, everything on one line
            // stream.Append ("!!binary \"" + System.Convert.ToBase64String (content) + "\"");
        }