コード例 #1
0
        internal override void Emit(Emitter emitter)
        {
            base.Emit(emitter);

            switch (Style)
            {
            case ScalarStyle.Hex:
            case ScalarStyle.Plain:
                ToString(emitter);
                break;

            case ScalarStyle.SingleQuoted:
                emitter.Write('\'');
                ToString(emitter);
                emitter.Write('\'');
                break;

            case ScalarStyle.DoubleQuoted:
                emitter.Write('"');
                ToString(emitter);
                emitter.Write('"');
                break;

            default:
                throw new Exception($"Unsupported scalar style {Style}");
            }
        }
コード例 #2
0
ファイル: YAMLSequenceNode.cs プロジェクト: zbx91/UtinyRipper
        private void EndChildren(Emitter emitter)
        {
            switch (Style)
            {
            case SequenceStyle.Block:
                if (m_children.Count == 0)
                {
                    emitter.Write(']');
                }
                emitter.WriteLine();
                break;

            case SequenceStyle.BlockCurve:
                if (m_children.Count == 0)
                {
                    emitter.WriteClose('}');
                }
                emitter.WriteLine();
                break;

            case SequenceStyle.Flow:
                emitter.WriteClose(']');
                break;

            case SequenceStyle.Raw:
                if (m_children.Count == 0)
                {
                    emitter.Write(']');
                }
                emitter.WriteLine();
                break;
            }
        }
コード例 #3
0
ファイル: YAMLSequenceNode.cs プロジェクト: zbx91/UtinyRipper
        private void StartChildren(Emitter emitter)
        {
            switch (Style)
            {
            case SequenceStyle.Block:
                if (m_children.Count == 0)
                {
                    emitter.Write('[');
                }
                break;

            case SequenceStyle.BlockCurve:
                if (m_children.Count == 0)
                {
                    emitter.Write('{');
                }
                break;

            case SequenceStyle.Flow:
                emitter.Write('[');
                break;

            case SequenceStyle.Raw:
                if (m_children.Count == 0)
                {
                    emitter.Write('[');
                }
                break;
            }
        }
コード例 #4
0
ファイル: YAMLMappingNode.cs プロジェクト: yaoya/UtinyRipper
 private void StartChildren(Emitter emitter)
 {
     if (Style == MappingStyle.Block)
     {
         if (m_children.Count == 0)
         {
             emitter.Write('{');
         }
     }
     else if (Style == MappingStyle.Flow)
     {
         emitter.Write('{');
     }
 }
コード例 #5
0
        internal void Emit(Emitter emitter, bool isSeparator)
        {
            if (isSeparator)
            {
                emitter.Write("---").WriteWhitespace();
            }

            Root.Emit(emitter);
        }
コード例 #6
0
        internal Emitter ToString(Emitter emitter)
        {
            if (Style == ScalarStyle.Hex)
            {
                switch (m_objectType)
                {
                case ScalarType.Byte:
                    return(emitter.WriteHex((byte)m_value));

                case ScalarType.Int16:
                    return(emitter.WriteHex((short)m_value));

                case ScalarType.UInt16:
                    return(emitter.WriteHex((ushort)m_value));

                case ScalarType.Int32:
                    return(emitter.WriteHex((int)m_value));

                case ScalarType.UInt32:
                    return(emitter.WriteHex((uint)m_value));

                case ScalarType.Int64:
                    return(emitter.WriteHex(m_value));

                case ScalarType.UInt64:
                    return(emitter.WriteHex(unchecked ((ulong)m_value)));

                case ScalarType.Single:
                    return(emitter.WriteHex((float)m_double));

                case ScalarType.Double:
                    return(emitter.WriteHex(m_double));

                case ScalarType.String:
                    return(emitter.Write(m_string));

                default:
                    throw new NotImplementedException(m_objectType.ToString());
                }
            }

            switch (m_objectType)
            {
            case ScalarType.UInt64:
                return(emitter.Write(unchecked ((ulong)m_value)));

            case ScalarType.Single:
                return(emitter.Write((float)m_double));

            case ScalarType.Double:
                return(emitter.Write(m_double));

            case ScalarType.String:
                return(emitter.Write(m_string));

            default:
                return(emitter.Write(m_value));
            }
        }
コード例 #7
0
ファイル: YAMLMappingNode.cs プロジェクト: yaoya/UtinyRipper
 private void StartTransition(Emitter emitter, YAMLNode next)
 {
     emitter.Write(':').WriteWhitespace();
     if (Style == MappingStyle.Block)
     {
         if (next.IsMultiline)
         {
             emitter.WriteLine();
         }
     }
     if (next.IsIndent)
     {
         emitter.IncreaseIntent();
     }
 }
コード例 #8
0
ファイル: YAMLMappingNode.cs プロジェクト: yaoya/UtinyRipper
 private void EndChildren(Emitter emitter)
 {
     if (Style == MappingStyle.Block)
     {
         if (m_children.Count == 0)
         {
             emitter.Write('}');
         }
         emitter.WriteLine();
     }
     else if (Style == MappingStyle.Flow)
     {
         emitter.WriteClose('}');
     }
 }
コード例 #9
0
ファイル: YAMLSequenceNode.cs プロジェクト: zbx91/UtinyRipper
        private void StartChild(Emitter emitter, YAMLNode next)
        {
            if (Style == SequenceStyle.Block || Style == SequenceStyle.BlockCurve)
            {
                emitter.Write('-').WriteWhitespace();

                if (next.NodeType == NodeType)
                {
                    emitter.IncreaseIntent();
                }
            }
            if (next.IsIndent)
            {
                emitter.IncreaseIntent();
            }
        }
コード例 #10
0
        private void StartChild(Emitter emitter, YAMLNode next)
        {
            if (Style.IsAnyBlock())
            {
                emitter.Write('-').Write(' ');

                if (next.NodeType == NodeType)
                {
                    emitter.IncreaseIndent();
                }
            }
            if (next.IsIndent)
            {
                emitter.IncreaseIndent();
            }
        }
コード例 #11
0
        private Emitter WriteString(Emitter emitter)
        {
            if (Style == ScalarStyle.Plain)
            {
                emitter.Write(m_string);
            }
            else if (Style == ScalarStyle.SingleQuoted)
            {
                emitter.WriteDelayed();
                for (int i = 0; i < m_string.Length; i++)
                {
                    char c = m_string[i];
                    emitter.WriteRaw(c);
                    if (c == '\'')
                    {
                        emitter.WriteRaw(c);
                    }
                    else if (c == '\n')
                    {
                        emitter.WriteRaw("\n    ");
                    }
                }
            }
            else if (Style == ScalarStyle.DoubleQuoted)
            {
                emitter.WriteDelayed();
                int lineLimit = MaxLineLength;
                for (int i = 0; i < m_string.Length; i++)
                {
                    if (i >= lineLimit)
                    {
                        emitter.WriteRaw('\\').WriteRaw('\n');
                        lineLimit += MaxLineLength;
                    }

                    char c = m_string[i];
                    switch (c)
                    {
                    case '\n':
                        emitter.WriteRaw('\\').WriteRaw('n');
                        break;

                    case '\r':
                        emitter.WriteRaw('\\').WriteRaw('r');
                        break;

                    case '\t':
                        emitter.WriteRaw('\\').WriteRaw('t');
                        break;

                    case '"':
                        emitter.WriteRaw('\\').WriteRaw('"');
                        break;

                    default:
                        emitter.WriteRaw(c);
                        break;
                    }
                }
            }
            else
            {
                throw new NotSupportedException(Style.ToString());
            }
            return(emitter);
        }