Example #1
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);
        }