Esempio n. 1
0
        /// <summary>
        /// Writes the property name of a name/value pair on a Json object.
        /// </summary>
        /// <param name="name">The name of the property.</param>
        public override void WritePropertyName(string name)
        {
            base.WritePropertyName(name);

            JavaScriptUtils.WriteEscapedJavaScriptString(_writer, name, _quoteChar, _quoteName);

            _writer.Write(':');
        }
Esempio n. 2
0
        /// <summary>
        /// Writes the property name of a name/value pair on a Json object.
        /// </summary>
        /// <param name="name">The name of the property.</param>
        public override void WritePropertyName(string name)
        {
            InternalWritePropertyName(name);

            JavaScriptUtils.WriteEscapedJavaScriptString(_writer, name, _quoteChar, _quoteName, GetCharEscapeFlags(), StringEscapeHandling);

            _writer.Write(':');
        }
Esempio n. 3
0
 /// <summary>
 /// Writes a <see cref="String"/> value.
 /// </summary>
 /// <param name="value">The <see cref="String"/> value to write.</param>
 public override void WriteValue(string value)
 {
     base.WriteValue(value);
     if (value == null)
     {
         WriteValueInternal(JsonConvert.Null, JsonToken.Null);
     }
     else
     {
         JavaScriptUtils.WriteEscapedJavaScriptString(_writer, value, _quoteChar, true);
     }
 }
Esempio n. 4
0
 public override void WriteValue(string value)
 {
     if (value == null || EscapeWhitespace)
     {
         base.WriteValue(value);
     }
     else
     {
         SetWriteState(JsonToken.String, value);
         JavaScriptUtils.WriteEscapedJavaScriptString(_writer, value, QuoteChar, QuoteNameHandling.Quoted, CharEscapeFlags, StringEscapeHandling);
     }
 }
Esempio n. 5
0
        /// <summary>
        /// Writes a <see cref="String"/> value.
        /// </summary>
        /// <param name="value">The <see cref="String"/> value to write.</param>
        public override void WriteValue(string value)
        {
            InternalWriteValue(JsonToken.String);

            if (value == null)
            {
                WriteValueInternal(JsonConvert.Null, JsonToken.Null);
            }
            else
            {
                JavaScriptUtils.WriteEscapedJavaScriptString(_writer, value, _quoteChar, true, GetCharEscapeFlags(), StringEscapeHandling);
            }
        }
Esempio n. 6
0
        public void WriteEscapedJavaScriptString()
        {
            string text =
                @"The general form of an HTML element is therefore: <tag attribute1=""value1"" attribute2=""value2"">content</tag>.
Some HTML elements are defined as empty elements and take the form <tag attribute1=""value1"" attribute2=""value2"" >.
Empty elements may enclose no content, for instance, the BR tag or the inline IMG tag.
The name of an HTML element is the name used in the tags.
Note that the end tag's name is preceded by a slash character, ""/"", and that in empty elements the end tag is neither required nor allowed.
If attributes are not mentioned, default values are used in each case.

The general form of an HTML element is therefore: <tag attribute1=""value1"" attribute2=""value2"">content</tag>.
Some HTML elements are defined as empty elements and take the form <tag attribute1=""value1"" attribute2=""value2"" >.
Empty elements may enclose no content, for instance, the BR tag or the inline IMG tag.
The name of an HTML element is the name used in the tags.
Note that the end tag's name is preceded by a slash character, ""/"", and that in empty elements the end tag is neither required nor allowed.
If attributes are not mentioned, default values are used in each case.

The general form of an HTML element is therefore: <tag attribute1=""value1"" attribute2=""value2"">content</tag>.
Some HTML elements are defined as empty elements and take the form <tag attribute1=""value1"" attribute2=""value2"" >.
Empty elements may enclose no content, for instance, the BR tag or the inline IMG tag.
The name of an HTML element is the name used in the tags.
Note that the end tag's name is preceded by a slash character, ""/"", and that in empty elements the end tag is neither required nor allowed.
If attributes are not mentioned, default values are used in each case.
";

            using (StringWriter w = StringUtils.CreateStringWriter(text.Length))
            {
                char[] buffer = null;
                JavaScriptUtils.WriteEscapedJavaScriptString(
                    w,
                    text,
                    '"',
                    true,
                    JavaScriptUtils.DoubleQuoteCharEscapeFlags,
                    StringEscapeHandling.Default,
                    null,
                    ref buffer
                    );
            }
        }
Esempio n. 7
0
        internal void WriteTo(StringBuilder sb, ref StringWriter?writer, ref char[]?buffer)
        {
            switch (Type)
            {
            case JsonContainerType.Object:
                var propertyName = PropertyName !;
                if (propertyName.IndexOfAny(SpecialCharacters) != -1)
                {
                    sb.Append(@"['");

                    if (writer == null)
                    {
                        writer = new StringWriter(sb);
                    }

                    JavaScriptUtils.WriteEscapedJavaScriptString(writer, propertyName, '\'', false, JavaScriptUtils.SingleQuoteCharEscapeFlags,
                                                                 StringEscapeHandling.Default, null, ref buffer);

                    sb.Append(@"']");
                }
                else
                {
                    if (sb.Length > 0)
                    {
                        sb.Append('.');
                    }

                    sb.Append(propertyName);
                }
                break;

            case JsonContainerType.Array:
            case JsonContainerType.Constructor:
                sb.Append('[');
                sb.Append(Position);
                sb.Append(']');
                break;
            }
        }
Esempio n. 8
0
 public override void WritePropertyName(string name, bool escape)
 {
     SetWriteState(JsonToken.PropertyName, name);
     if (escape)
     {
         JavaScriptUtils.WriteEscapedJavaScriptString(_writer, name, QuoteChar, QuoteNameHandling, CharEscapeFlags, StringEscapeHandling);
     }
     else
     {
         bool quoteName = QuoteNameHandling == QuoteNameHandling.Quoted ||
                          QuoteNameHandling == QuoteNameHandling.Auto && !JavaScriptUtils.IsValidIdentifier(name);
         if (quoteName)
         {
             _writer.Write(QuoteChar);
         }
         _writer.Write(name);
         if (quoteName)
         {
             _writer.Write(QuoteChar);
         }
     }
     _writer.Write(':');
 }
Esempio n. 9
0
 private void WriteEscapedString(string value, bool quote)
 {
     EnsureWriteBuffer();
     JavaScriptUtils.WriteEscapedJavaScriptString(_writer, value, _quoteChar, quote, _charEscapeFlags, StringEscapeHandling, _arrayPool, ref _writeBuffer);
 }
Esempio n. 10
0
 private void WriteEscapedString(string value, bool quote)
 {
     this.EnsureWriteBuffer();
     JavaScriptUtils.WriteEscapedJavaScriptString(this._writer, value, this._quoteChar, quote, this._charEscapeFlags, this.StringEscapeHandling, this._arrayPool, ref this._writeBuffer);
 }