Inheritance: JsonTypeSkeleton, IJsonString
Esempio n. 1
0
 /// <summary>
 /// Returns a value indicating equality with the specified instance.
 /// </summary>
 /// <param name="other">The JsonNumber to compare.</param>
 /// <returns></returns>
 public int CompareTo(JsonString other)
 {
     return other != null ? this.Value.CompareTo(other.Value) : -1;
 }
Esempio n. 2
0
 /// <summary>
 /// Returns a indicating whether this instance is equal to the specified
 /// JsonString.
 /// </summary>
 /// <param name="other">The value to compare.</param>
 /// <returns>True if the specified instance is equal to this instance, otherwise;
 /// false.</returns>
 public bool Equals(JsonString other)
 {
     return other != null && Equals(other.Value);
 }
Esempio n. 3
0
        /// <summary>
        /// Determines if the two <see cref="NetServ.Net.Json.JsonString"/>s are
        /// equal.
        /// </summary>
        /// <param name="a">The first JsonString.</param>
        /// <param name="b">The second JsonString.</param>
        /// <returns>True if the JsonStrings are equal, otherwise; false.</returns>
        public static bool Equals(JsonString a, JsonString b)
        {
            object ao = a;
            object bo = b;

            if(ao == bo)
                return true;
            if(ao == null || bo == null)
                return false;

            return a.Equals(b.Value);
        }
Esempio n. 4
0
        /// <summary>
        /// Encodes the specified <see cref="System.String"/>.
        /// </summary>
        /// <param name="s">The string to encode.</param>
        /// <returns>The encoded string.</returns>
        public static string Encode(string s)
        {
            if (s == null)
            {
                throw new ArgumentNullException("s");
            }

            if (s.Equals(string.Empty) || !JsonString.ShouldEncode(s))
            {
                return(string.Concat("\"", s, "\""));
            }

            char          ch;
            StringBuilder sb = new StringBuilder(s.Length);

            sb.Append('"');
            for (int i = 0; i < s.Length; ++i)
            {
                ch = s[i];
                switch (ch)
                {
                case '"':
                    sb.Append(@"\""");
                    break;

                case '/':
                    sb.Append(@"\/");
                    break;

                case '\\':
                    sb.Append(@"\\");
                    break;

                case '\b':
                    sb.Append(@"\b");
                    break;

                case '\f':
                    sb.Append(@"\f");
                    break;

                case '\n':
                    sb.Append(@"\n");
                    break;

                case '\r':
                    sb.Append(@"\r");
                    break;

                case '\t':
                    sb.Append(@"\t");
                    break;

                default:
                    if (ch > 0x7F)
                    {
                        // TODO: MUST add support for UTF-16.
                        sb.AppendFormat(@"\u{0}", ((int)ch).ToString("X4"));
                    }
                    else
                    {
                        sb.Append(ch);
                    }
                    break;
                }
            }
            sb.Append('"');

            return(sb.ToString());
        }
Esempio n. 5
0
 /// <summary>
 /// Inequality operator.
 /// </summary>
 /// <param name="a">The first JsonString.</param>
 /// <param name="b">The second JsonString.</param>
 /// <returns>True if the JsonStrings are not equal, otherwise; false.</returns>
 public static bool operator !=(JsonString a, JsonString b)
 {
     return(!JsonString.Equals(a, b));
 }
Esempio n. 6
0
 /// <summary>
 /// Returns a value indicating equality with the specified instance.
 /// </summary>
 /// <param name="other">The JsonNumber to compare.</param>
 /// <returns></returns>
 public int CompareTo(JsonString other)
 {
     return(other != null?this.Value.CompareTo(other.Value) : -1);
 }
Esempio n. 7
0
 /// <summary>
 /// Returns a indicating whether this instance is equal to the specified
 /// JsonString.
 /// </summary>
 /// <param name="other">The value to compare.</param>
 /// <returns>True if the specified instance is equal to this instance, otherwise;
 /// false.</returns>
 public bool Equals(JsonString other)
 {
     return(other != null && Equals(other.Value));
 }