public void SkipWhiteSpaces()
        {
            string text   = "0    12    3";
            var    reader = new StringReader(text);

            Assert.AreEqual('0', (char)reader.Peek());

            JsonFormatUtility.SkipWhiteSpaces(reader);

            Assert.AreEqual('0', (char)reader.Peek());

            reader.Read();
            JsonFormatUtility.SkipWhiteSpaces(reader);

            Assert.AreEqual('1', (char)reader.Peek());

            reader.Read();

            Assert.AreEqual('2', (char)reader.Peek());

            reader.Read();
            JsonFormatUtility.SkipWhiteSpaces(reader);

            Assert.AreEqual('3', (char)reader.Peek());

            reader.Read();

            Assert.AreEqual(-1, reader.Peek());
        }
        public void Escape()
        {
            string result0 = JsonFormatUtility.Escape(m_unescaped);
            string result1 = JsonFormatUtility.Escape("http://placehold.it/32x32");

            Assert.AreEqual(m_escaped, result0);
            Assert.AreEqual("http://placehold.it/32x32", result1);
        }
        public void ParseUnicode()
        {
            char   ch   = 'a';
            string text = ((int)ch).ToString("x4");
            int    code = JsonFormatUtility.ParseUnicode(text[0], text[1], text[2], text[3]);

            Assert.AreEqual(ch, (char)code);
        }
        /// <summary>
        /// Gets value as unescaped string.
        /// </summary>
        public string GetString()
        {
            if (Type != JsonValueType.String)
            {
                throw new InvalidOperationException($"The type of this value not a string: '{Type}'");
            }

            return(JsonFormatUtility.Unescape(Raw));
        }
        public void ToCompact()
        {
            string result0 = JsonFormatUtility.ToCompact(m_readable);
            string result1 = JsonFormatUtility.ToCompact(m_compact);
            string result2 = JsonFormatUtility.ToCompact(m_readable_c1);

            Assert.AreEqual(m_compact, result0);
            Assert.AreEqual(m_compact, result1);
            Assert.AreEqual(m_compact_c1, result2);
        }
        public void ClearComments()
        {
            string result0 = JsonFormatUtility.ClearComments(m_readable_c1);
            string result1 = JsonFormatUtility.ClearComments(m_readable_c2);
            string result2 = JsonFormatUtility.ClearComments(m_readable_c3);
            string result3 = JsonFormatUtility.ClearComments(m_compact_c1);

            Assert.AreEqual(m_readable, result0);
            Assert.AreEqual(m_readable, result1);
            Assert.AreEqual(m_readable, result2);
            Assert.AreEqual(m_compact, result3);
        }
 public void IsDigit()
 {
     Assert.True(JsonFormatUtility.IsDigit('0'));
     Assert.True(JsonFormatUtility.IsDigit('1'));
     Assert.True(JsonFormatUtility.IsDigit('2'));
     Assert.True(JsonFormatUtility.IsDigit('3'));
     Assert.True(JsonFormatUtility.IsDigit('4'));
     Assert.True(JsonFormatUtility.IsDigit('5'));
     Assert.True(JsonFormatUtility.IsDigit('6'));
     Assert.True(JsonFormatUtility.IsDigit('7'));
     Assert.True(JsonFormatUtility.IsDigit('8'));
     Assert.True(JsonFormatUtility.IsDigit('9'));
     Assert.False(JsonFormatUtility.IsDigit('a'));
 }
        public override void OnImportAsset(AssetImportContext context)
        {
            string text = File.ReadAllText(context.assetPath);

            if (m_compact)
            {
                text = JsonFormatUtility.ToCompact(text);
            }

            if (!m_comments)
            {
                text = JsonFormatUtility.ClearComments(text);
            }

            var textAsset = new TextAsset(text);

            context.AddObjectToAsset("main", textAsset);
            context.SetMainObject(textAsset);
        }
        /// <summary>
        /// Creates string from the specified value.
        /// <para>
        /// The specified value will be escaped.
        /// </para>
        /// </summary>
        /// <param name="value">The value.</param>
        public static JsonValue CreateString(string value)
        {
            value = JsonFormatUtility.Escape(value);

            return(new JsonValue(JsonValueType.String, value));
        }