Parser.ParserBase.ReadWordOrSeparator C# (CSharp) Method

ReadWordOrSeparator() public static method

Reads a single word or separator at the specified position.
public static ReadWordOrSeparator ( string text, int &position, bool treatWhiteSpaceAsSeparator ) : string
text string
position int
treatWhiteSpaceAsSeparator bool
return string
        public static string ReadWordOrSeparator(string text, ref int position, bool treatWhiteSpaceAsSeparator)
        {
            #region Check the parameters

            CheckTextAndPositionArguments(text, position);

            #endregion

            int myStartPosition = position;

            while (position < text.Length)
            {
                #region Check is white space

                if (char.IsWhiteSpace(text, position))
                {
                    if (position == myStartPosition && treatWhiteSpaceAsSeparator)
                    {
                        if (position + cNewLine.Length <= text.Length && text.Substring(position, cNewLine.Length) == cNewLine)
                            position += cNewLine.Length;
                        else
                            position += 1;
                    }
                    break;
                }

                #endregion

                #region Check is separator

                if (!char.IsLetterOrDigit(text, position) && text[position] != '_')
                {
                    if (position == myStartPosition)
                        position++;
                    break;
                }

                #endregion

                position++;
            }

            if (position == myStartPosition)
                return string.Empty;

            return text.Substring(myStartPosition, position - myStartPosition);
        }