Inheritance: JsonTypeSkeleton, IJsonString
コード例 #1
0
ファイル: JsonString.cs プロジェクト: appcelerator/entourage
 /// <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;
 }
コード例 #2
0
ファイル: JsonString.cs プロジェクト: appcelerator/entourage
 /// <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);
 }
コード例 #3
0
ファイル: JsonString.cs プロジェクト: appcelerator/entourage
        /// <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);
        }
コード例 #4
0
ファイル: JsonString.cs プロジェクト: closer76/karma-booster
        /// <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());
        }
コード例 #5
0
ファイル: JsonString.cs プロジェクト: closer76/karma-booster
 /// <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));
 }
コード例 #6
0
ファイル: JsonString.cs プロジェクト: closer76/karma-booster
 /// <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);
 }
コード例 #7
0
ファイル: JsonString.cs プロジェクト: closer76/karma-booster
 /// <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));
 }