AGS.Editor.ScintillaWrapper.GetPreviousPathedExpression C# (CSharp) Метод

GetPreviousPathedExpression() приватный Метод

private GetPreviousPathedExpression ( int startAtPos, bool skipSpacesBeforeCursor ) : string
startAtPos int
skipSpacesBeforeCursor bool
Результат string
        private string GetPreviousPathedExpression(int startAtPos, bool skipSpacesBeforeCursor)
        {
            bool startedParsingExpression = !skipSpacesBeforeCursor;
            if (startAtPos < 0) startAtPos = 0;
            int cursorPos = startAtPos;

            while (cursorPos > 0)
            {
                int thisChar = scintillaControl1.GetCharAt(cursorPos);
                if (thisChar == ']')
                {
                    int bracketDepth = 1;
                    cursorPos--;
                    while ((bracketDepth > 0) && (cursorPos > 0))
                    {
                        int checkChar = scintillaControl1.GetCharAt(cursorPos);
                        if (checkChar == ']') bracketDepth++;
                        if (checkChar == '[') bracketDepth--;
                        if ((checkChar == '\n') || (checkChar == '\r'))
                        {
                            cursorPos++;
                            break;
                        }
                        cursorPos--;
                    }
                    startedParsingExpression = true;
                }
                else if ((thisChar == '.') || (thisChar == '_') ||
                         (Char.IsLetterOrDigit((char)thisChar)))
                {
                    cursorPos--;
                    startedParsingExpression = true;
                }
                else if ((thisChar == ' ') && (!startedParsingExpression))
                {
                    // if they put a space between function name and parameter
                    // list, skip back over it
                    cursorPos--;
                }
                else
                {
                    cursorPos++;
                    break;
                }

                if (cursorPos < startAtPos - 200)
                {
                    // there is probably some invalid syntax like too many
                    // closing brackets, so abort
                    return string.Empty;
                }
            }
            if (cursorPos == 0)
            {
                // parse error
                return string.Empty;
            }
            if (startAtPos < cursorPos)
            {
                return string.Empty;
            }
            int lineNumber = scintillaControl1.LineFromPosition(cursorPos);
            int startOfLine = scintillaControl1.PositionFromLine(lineNumber);
            string lineText = scintillaControl1.GetLine(lineNumber);
            int startAtIndex = cursorPos - startOfLine;

            if (startAtIndex >= lineText.Length)
            {
                // can happen if the cursor is at the end of the line
                return string.Empty;
            }
            return lineText.Substring(startAtIndex, (startAtPos - cursorPos) + 1).Trim();
        }
ScintillaWrapper