Пример #1
0
        /// <summary>
        /// Reads word from string. Returns null if no word is available.
        /// Word reading begins from first char, for example if SP"text", then space is trimmed.
        /// </summary>
        /// <param name="unQuote">Specifies if quoted string word is unquoted.</param>
        /// <param name="wordTerminatorChars">Specifies chars what terminate word.</param>
        /// <param name="removeWordTerminator">Specifies if work terminator is removed.</param>
        /// <returns></returns>
        public string ReadWord(bool unQuote, char[] wordTerminatorChars, bool removeWordTerminator)
        {
            // Always start word reading from first char.
            this.ReadToFirstChar();

            if (this.Available == 0)
            {
                return(null);
            }

            // quoted word can contain any char, " must be escaped with \
            // unqouted word can conatin any char except: SP VTAB HTAB,{}()[]<>

            if (m_SourceString.StartsWith("\""))
            {
                if (unQuote)
                {
                    return(TextUtils.UnQuoteString(QuotedReadToDelimiter(wordTerminatorChars, removeWordTerminator)));
                }
                else
                {
                    return(QuotedReadToDelimiter(wordTerminatorChars, removeWordTerminator));
                }
            }
            else
            {
                int wordLength = 0;
                for (int i = 0; i < m_SourceString.Length; i++)
                {
                    char c = m_SourceString[i];

                    bool isTerminator = false;
                    foreach (char terminator in wordTerminatorChars)
                    {
                        if (c == terminator)
                        {
                            isTerminator = true;
                            break;
                        }
                    }
                    if (isTerminator)
                    {
                        break;
                    }

                    wordLength++;
                }

                string retVal = m_SourceString.Substring(0, wordLength);
                if (removeWordTerminator)
                {
                    if (m_SourceString.Length >= wordLength + 1)
                    {
                        m_SourceString = m_SourceString.Substring(wordLength + 1);
                    }
                }
                else
                {
                    m_SourceString = m_SourceString.Substring(wordLength);
                }

                return(retVal);
            }
        }