select_to_next_word{,_end}: words are [a-zA-Z0-9]

This commit is contained in:
Maxime Coste 2011-09-16 09:20:36 +00:00
parent 3afbbefd9b
commit 49fce28dec

View File

@ -289,13 +289,24 @@ bool is_blank(char c)
return c == ' ' or c == '\t' or c == '\n'; return c == ' ' or c == '\t' or c == '\n';
} }
bool is_word(char c)
{
if (c >= '0' and c <= '9')
return true;
if (c >= 'a' and c <= 'z')
return true;
if (c >= 'A' and c <= 'Z')
return true;
return false;
}
Selection select_to_next_word(const BufferIterator& cursor) Selection select_to_next_word(const BufferIterator& cursor)
{ {
BufferIterator end = cursor; BufferIterator end = cursor;
while (not end.is_end() and not is_blank(*end)) while (not end.is_end() and is_word(*end))
++end; ++end;
while (not end.is_end() and is_blank(*end)) while (not end.is_end() and not is_word(*end))
++end; ++end;
return Selection(cursor, end); return Selection(cursor, end);
@ -304,10 +315,10 @@ Selection select_to_next_word(const BufferIterator& cursor)
Selection select_to_next_word_end(const BufferIterator& cursor) Selection select_to_next_word_end(const BufferIterator& cursor)
{ {
BufferIterator end = cursor; BufferIterator end = cursor;
while (not end.is_end() and is_blank(*end)) while (not end.is_end() and not is_word(*end))
++end; ++end;
while (not end.is_end() and not is_blank(*end)) while (not end.is_end() and is_word(*end))
++end; ++end;
return Selection(cursor, end); return Selection(cursor, end);