Beispiel #1
0
 public void WriteString(TextWriter writer, string value)
 {
     JsonUtils.WriteString(writer, value);
 }
Beispiel #2
0
 public void WriteObjectString(TextWriter writer, object value)
 {
     JsonUtils.WriteString(writer, value != null ? value.ToString() : null);
 }
Beispiel #3
0
        public void WriteFormattableObjectString(TextWriter writer, object value)
        {
            var formattable = value as IFormattable;

            JsonUtils.WriteString(writer, formattable != null ? formattable.ToString(null, CultureInfo.InvariantCulture) : null);
        }
Beispiel #4
0
        public StringSegment EatValue(StringSegment value, ref int i)
        {
            var buf         = value.Buffer;
            var valueLength = value.Length;
            var offset      = value.Offset;

            if (i == valueLength)
            {
                return(default(StringSegment));
            }

            while (i < valueLength && JsonUtils.IsWhiteSpace(buf[offset + i]))
            {
                i++;                                                                //Whitespace inline
            }
            if (i == valueLength)
            {
                return(default(StringSegment));
            }

            var tokenStartPos = i;
            var valueChar     = buf[offset + i];
            var withinQuotes  = false;
            var endsToEat     = 1;

            switch (valueChar)
            {
            //If we are at the end, return.
            case JsWriter.ItemSeperator:
            case JsWriter.MapEndChar:
                return(default(StringSegment));

            //Is Within Quotes, i.e. "..."
            case JsWriter.QuoteChar:
                return(ParseString(value, ref i));

            //Is Type/Map, i.e. {...}
            case JsWriter.MapStartChar:
                while (++i < valueLength)
                {
                    valueChar = buf[offset + i];

                    if (valueChar == JsonUtils.EscapeChar)
                    {
                        i++;
                        continue;
                    }

                    if (valueChar == JsWriter.QuoteChar)
                    {
                        withinQuotes = !withinQuotes;
                    }

                    if (withinQuotes)
                    {
                        continue;
                    }

                    if (valueChar == JsWriter.MapStartChar)
                    {
                        endsToEat++;
                    }

                    if (valueChar == JsWriter.MapEndChar && --endsToEat == 0)
                    {
                        i++;
                        break;
                    }
                }
                return(value.Subsegment(tokenStartPos, i - tokenStartPos));

            //Is List, i.e. [...]
            case JsWriter.ListStartChar:
                while (++i < valueLength)
                {
                    valueChar = buf[offset + i];

                    if (valueChar == JsonUtils.EscapeChar)
                    {
                        i++;
                        continue;
                    }

                    if (valueChar == JsWriter.QuoteChar)
                    {
                        withinQuotes = !withinQuotes;
                    }

                    if (withinQuotes)
                    {
                        continue;
                    }

                    if (valueChar == JsWriter.ListStartChar)
                    {
                        endsToEat++;
                    }

                    if (valueChar == JsWriter.ListEndChar && --endsToEat == 0)
                    {
                        i++;
                        break;
                    }
                }
                return(value.Subsegment(tokenStartPos, i - tokenStartPos));
            }

            //Is Value
            while (++i < valueLength)
            {
                valueChar = buf[offset + i];

                if (valueChar == JsWriter.ItemSeperator ||
                    valueChar == JsWriter.MapEndChar
                    //If it doesn't have quotes it's either a keyword or number so also has a ws boundary
                    || JsonUtils.IsWhiteSpace(valueChar)
                    )
                {
                    break;
                }
            }

            var strValue = value.Subsegment(tokenStartPos, i - tokenStartPos);

            return(strValue == new StringSegment(JsonUtils.Null) ? default(StringSegment) : strValue);
        }
Beispiel #5
0
 public void WriteObjectString(TextWriter writer, object value)
 {
     JsonUtils.WriteString(writer, value?.ToString());
 }