Help class for writing a Yaml tree to a string
コード例 #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());
        }
コード例 #2
0
 /// <summary> Write to YAML </summary>
 protected internal override void Write(WriteStream stream)
 {
     if (Content)
     {
         stream.Append("y");
     }
     else
     {
         stream.Append("n");
     }
 }
コード例 #3
0
ファイル: Sequence.cs プロジェクト: paulorades/externals
        /// <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();
            }
        }
コード例 #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();
        }
コード例 #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) + "\"");
        }
コード例 #6
0
ファイル: Mapping.cs プロジェクト: paulorades/externals
        /// <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();
            }
        }
コード例 #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);
            }
        }
コード例 #8
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 ();
            }
        }
コード例 #9
0
 /// <summary> Write to YAML </summary>
 protected internal override void Write(WriteStream stream)
 {
     if (Content)
         stream.Append ("y");
     else
         stream.Append ("n");
 }
コード例 #10
0
ファイル: Integer.cs プロジェクト: paulorades/externals
 /// <summary> Write to YAML </summary>
 protected internal override void Write(WriteStream stream)
 {
     stream.Append(content.ToString());
 }
コード例 #11
0
ファイル: String.cs プロジェクト: paulorades/externals
        /// <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);
            }
        }
コード例 #12
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);
        }
コード例 #13
0
 /// <summary> Write to YAML </summary>
 protected internal override void Write(WriteStream stream)
 {
     stream.Append (YamlString ());
 }
コード例 #14
0
ファイル: Null.cs プロジェクト: paulorades/externals
 /// <summary> Write to YAML </summary>
 protected internal override void Write(WriteStream stream)
 {
     stream.Append("~");
 }
コード例 #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)
 {
 }
コード例 #16
0
 /// <summary> Write to YAML </summary>
 protected internal override void Write(WriteStream stream)
 {
     stream.Append (content.ToString ());
 }
コード例 #17
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) {}
コード例 #18
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 ();
		}
コード例 #19
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 ();
		}
コード例 #20
0
 /// <summary> Write to YAML </summary>
 protected internal override void Write(WriteStream stream)
 {
     stream.Append ("~");
 }
コード例 #21
0
 /// <summary> Write to YAML </summary>
 protected internal override void Write(WriteStream stream)
 {
     stream.Append(YamlString());
 }
コード例 #22
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 ();
            }
        }
コード例 #23
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) + "\"");
        }