private bool IsPosition (Position pos, int ptr) {
switch (pos) {
case Position.Start: case Position.StartOfString:
return ptr == 0;
case Position.StartOfLine:
return ptr == 0 || text[ptr - 1] == '\n';
case Position.StartOfScan:
return ptr == scan_ptr;
case Position.End:
return ptr == text_end ||
(ptr == text_end - 1 && text[ptr] == '\n');
case Position.EndOfLine:
return ptr == text_end || text[ptr] == '\n';
case Position.EndOfString:
return ptr == text_end;
case Position.Boundary:
if (text_end == 0)
return false;
if (ptr == 0)
return IsWordChar (text[ptr]);
else if (ptr == text_end)
return IsWordChar (text[ptr - 1]);
else
return IsWordChar (text[ptr]) != IsWordChar (text[ptr - 1]);
case Position.NonBoundary:
if (text_end == 0)
return false;
if (ptr == 0)
return !IsWordChar (text[ptr]);
else if (ptr == text_end)
return !IsWordChar (text[ptr - 1]);
else
return IsWordChar (text[ptr]) == IsWordChar (text[ptr - 1]);
default:
return false;
}
}