Mono.TextEditor.TextDocument.GetCharAt C# (CSharp) Method

GetCharAt() public method

public GetCharAt ( Mono.TextEditor.DocumentLocation location ) : char
location Mono.TextEditor.DocumentLocation
return char
		public char GetCharAt (DocumentLocation location)
		{
			return buffer [LocationToOffset (location)];
		}

Same methods

TextDocument::GetCharAt ( int offset ) : char
TextDocument::GetCharAt ( int line, int column ) : char

Usage Example

        static IEnumerable <KeyValuePair <char, int> > GetTextWithoutCommentsAndStrings(Mono.TextEditor.TextDocument doc, int start, int end)
        {
            bool isInString = false, isInChar = false;
            bool isInLineComment = false, isInBlockComment = false;

            for (int pos = start; pos < end; pos++)
            {
                char ch = doc.GetCharAt(pos);
                switch (ch)
                {
                case '\r':
                case '\n':
                    isInLineComment = false;
                    break;

                case '/':
                    if (isInBlockComment)
                    {
                        if (pos > 0 && doc.GetCharAt(pos - 1) == '*')
                        {
                            isInBlockComment = false;
                        }
                    }
                    else if (!isInString && !isInChar && pos + 1 < doc.TextLength)
                    {
                        char nextChar = doc.GetCharAt(pos + 1);
                        if (nextChar == '/')
                        {
                            isInLineComment = true;
                        }
                        if (!isInLineComment && nextChar == '*')
                        {
                            isInBlockComment = true;
                        }
                    }
                    break;

                case '"':
                    if (!(isInChar || isInLineComment || isInBlockComment))
                    {
                        isInString = !isInString;
                    }
                    break;

                case '\'':
                    if (!(isInString || isInLineComment || isInBlockComment))
                    {
                        isInChar = !isInChar;
                    }
                    break;

                default:
                    if (!(isInString || isInChar || isInLineComment || isInBlockComment))
                    {
                        yield return(new KeyValuePair <char, int> (ch, pos));
                    }
                    break;
                }
            }
        }
All Usage Examples Of Mono.TextEditor.TextDocument::GetCharAt
TextDocument