private static IEnumerable<Loc> Process(string source) { var buffer = new CharBuffer(source); var sb = new StringBuilder(source); while (buffer.MoveNext()) { var c = buffer.GetCurrent(); if ((c == KS || c == BS || c == IS) && IsStart(buffer)) { var type = c == KS ? ItemType.Keyword : c == BS ? ItemType.Bold : c == IS ? ItemType.Italic : ItemType.Italic; var a = buffer.SetAnchor(); var rc = c; while (!EndSym(rc, buffer.GetNext())) buffer.MoveNext(); if (buffer.GetNext() != rc) buffer.BackToAnchor(); else { yield return new Loc(a, buffer.Offset - a + 2, type); buffer.MoveNext(); } } } }
private static bool IsStart(CharBuffer buffer) { if (buffer.Offset == 1) return true; var c = buffer.GetPrevious(); return !Char.IsLetterOrDigit(c); }