static public bool FindCurrentToken()

in src/Editor/Text/Def/Internal/TextData/UnicodeWordExtent.cs [70:156]


        static public bool FindCurrentToken(SnapshotPoint currentPosition, out SnapshotSpan span)
        {
            ITextSnapshotLine textSnapshotLine = currentPosition.GetContainingLine();
            LineBuffer lineText = new LineBuffer(textSnapshotLine);
            int lineLength = textSnapshotLine.LengthIncludingLineBreak;
            int iCol = (currentPosition - textSnapshotLine.Start);

            // handle end of buffer case
            if (iCol >= lineLength)
            {
                span = new SnapshotSpan(currentPosition.Snapshot, textSnapshotLine.End, 0);
                return true;
            }

            // scan left for base char
            while ((iCol > 0) && !IsGraphemeBreak(lineText, iCol))
            {
                iCol--;
            }

            // if it's a word, return the word
            char ch = lineText[iCol];
            if (IsWordChar(ch))
            {
                return FindCurrentWordCoords(new SnapshotPoint(currentPosition.Snapshot, textSnapshotLine.Start + iCol), out span);
            }

            // contiguous whitespace
            int iBeg;
            if (Char.IsWhiteSpace(ch))
            {
                for (iBeg = iCol - 1; iBeg >= 0; --iBeg)
                {
                    if (!Char.IsWhiteSpace(lineText[iBeg]))
                        break;
                }
                iBeg++;

                for (++iCol; iCol < lineLength; ++iCol)
                {
                    if (!Char.IsWhiteSpace(lineText[iCol]))
                        break;
                }
            }

            // contiguous punctuation and math symbols
            else if (Char.IsPunctuation(ch) || IsMathSymbol(ch))
            {
                for (iBeg = iCol - 1; iBeg >= 0; --iBeg)
                {
                    ch = lineText[iBeg];
                    if (!(Char.IsPunctuation(ch) || IsMathSymbol(ch)))
                        break;
                }
                iBeg++;

                for (++iCol; iCol < lineLength; ++iCol)
                {
                    ch = lineText[iCol];
                    if (!(Char.IsPunctuation(ch) || IsMathSymbol(ch)))
                        break;
                }
            }

            //Let's get the whole surrogate pair.
            else if (Char.IsHighSurrogate(ch) && ((iCol + 1) < lineLength) && Char.IsLowSurrogate(lineText[iCol + 1]))
            {
                iBeg = iCol;
                iCol += 2;
            }

            // any other single char
            else
            {
                iBeg = iCol++;
            }

            if (iCol > lineLength)
            {
                iCol = lineLength;
            }

            // Done -- fill in the data
            span = new SnapshotSpan(currentPosition.Snapshot, (textSnapshotLine.Start + iBeg), (iCol - iBeg));

            return true;
        }