示例#1
0
        internal int OpenCloseCount; // keep track of open/close cases, as in the end we should be back at zero

        public string Encode()
        {
            // First, do basic validity checking
            if (string.IsNullOrWhiteSpace(Original))
            {
                return(Original);
            }
            VerifyStartingCharIsValid(Characters.JsonStartMarkers);
            Original = JsonCompressor.Compress(Original);

            // not process each character
            foreach (var currentChar in Original)
            {
                if (OutsideOfQuotes)
                {
                    ProcessOutsideOfQuote(currentChar);
                }
                else
                {
                    ProcessInsideValue(currentChar);
                }

                // remember this char, in case the next character-check needs to know it
                PrevCharacter = currentChar;
            }


            // final error-checking
            if (OpenCloseCount != 0)
            {
                throw new Exception($"Cannot convert json4get, total opening / closing brackets and quotes don't match, got {OpenCloseCount}");
            }

            return(Builder.ToString());
        }
示例#2
0
        internal string Decode()
        {
            // First, do basic validity checking
            if (string.IsNullOrWhiteSpace(Original))
            {
                return(Original);
            }
            Original = Original.Trim();
            VerifyStartingCharIsValid(Characters.Json4GetStartMarkers);

            foreach (var currentChar in Original)
            {
                if (OutsideOfQuotes)
                {
                    ParseOutsideOfQuote(currentChar);
                }
                else
                {
                    ParseInsideQuotes(currentChar);
                }

                PrevChar = currentChar; // remember the char for next checks...
            }
            FlushFragment();
            var result = Builder.ToString();

            return(JsonCompressor.Decompress(result));
        }