Playtomic.JSON.ParseString C# (CSharp) Method

ParseString() protected method

protected ParseString ( char json, int &index ) : string
json char
index int
return string
        protected string ParseString(char[] json, ref int index)
        {
            string s = "";
            char c;

            EatWhitespace(json, ref index);

            // "
            c = json[index++];

            bool complete = false;
            while (!complete) {

                if (index == json.Length) {
                    break;
                }

                c = json[index++];
                if (c == '"') {
                    complete = true;
                    break;
                } else if (c == '\\') {

                    if (index == json.Length) {
                        break;
                    }
                    c = json[index++];
                    if (c == '"') {
                        s += '"';
                    } else if (c == '\\') {
                        s += '\\';
                    } else if (c == '/') {
                        s += '/';
                    } else if (c == 'b') {
                        s += '\b';
                    } else if (c == 'f') {
                        s += '\f';
                    } else if (c == 'n') {
                        s += '\n';
                    } else if (c == 'r') {
                        s += '\r';
                    } else if (c == 't') {
                        s += '\t';
                    } else if (c == 'u') {
                        int remainingLength = json.Length - index;
                        if (remainingLength >= 4) {
                            // fetch the next 4 chars
                            char[] unicodeCharArray = new char[4];
                            Array.Copy(json, index, unicodeCharArray, 0, 4);
                            // parse the 32 bit hex into an integer codepoint
                            uint codePoint = UInt32.Parse(new string(unicodeCharArray), NumberStyles.HexNumber);
                            // convert the integer codepoint to a unicode char and add to string
                            s += Char.ConvertFromUtf32((int)codePoint);
                            // skip 4 chars
                            index += 4;
                        } else {
                            break;
                        }
                    }

                } else {
                    s += c;
                }

            }

            if (!complete) {
                return null;
            }

            return s;
        }