Microsoft.Zing.Scanner.ScanString C# (CSharp) Méthode

ScanString() private méthode

private ScanString ( char closingQuote ) : void
closingQuote char
Résultat void
        private void ScanString(char closingQuote)
        {
            char ch;
            int start = this.endPos;
            this.unescapedString = null;
            StringBuilder unescapedSB = null;
            do
            {
                ch = this.GetChar(this.endPos++);
                if (ch == '\\')
                {
                    // Got an escape of some sort. Have to use the StringBuilder
                    if (unescapedSB == null) unescapedSB = new StringBuilder(128);
                    // start points to the first position that has not been written to the StringBuilder.
                    // The first time we get in here that position is the beginning of the string, after that
                    // it is the character immediately following the escape sequence
                    int len = this.endPos - start - 1;
                    if (len > 0) // append all the non escaped chars to the string builder
                        if (this.sourceString != null)
                            unescapedSB.Append(this.sourceString, start, len);
                        else
                            unescapedSB.Append(this.sourceText.Substring(start, len));
                    int savedEndPos = this.endPos - 1;
                    this.ScanEscapedChar(unescapedSB); //might be a 32-bit unicode character
                    if (closingQuote == (char)0 && unescapedSB.Length > 0 && unescapedSB[unescapedSB.Length - 1] == (char)0)
                    {
                        unescapedSB.Length -= 1;
                        this.endPos = savedEndPos;
                        start = this.endPos;
                        break;
                    }
                    start = this.endPos;
                }
                else
                {
                    // This is the common non escaped case
                    if (this.IsLineTerminator(ch, 0) || (ch == 0 && this.endPos >= this.maxPos))
                    {
                        this.FindGoodRecoveryPoint(closingQuote);
                        break;
                    }
                }
            } while (ch != closingQuote);
            // update this.unescapedString using the StringBuilder
            if (unescapedSB != null)
            {
                int len = this.endPos - start - 1;
                if (len > 0)
                {
                    // append all the non escape chars to the string builder
                    if (this.sourceString != null)
                        unescapedSB.Append(this.sourceString, start, len);
                    else
                        unescapedSB.Append(this.sourceText.Substring(start, len));
                }
                this.unescapedString = unescapedSB.ToString();
            }
            else
            {
                if (closingQuote == (char)0)
                    this.unescapedString = this.Substring(this.startPos, this.endPos - this.startPos);
                else if (closingQuote == '\'' && (this.startPos == this.endPos - 1 || this.GetChar(this.endPos - 1) != '\''))
                    this.unescapedString = this.Substring(this.startPos + 1, 1); //suppres further errors
                else if (this.endPos <= this.startPos + 2)
                    this.unescapedString = "";
                else
                    this.unescapedString = this.Substring(this.startPos + 1, this.endPos - this.startPos - 2);
            }
        }