예제 #1
0
파일: text-objects.c 프로젝트: 8l/vis
Filerange text_object_word_find_prev(Text *txt, size_t pos, const char *word) {
	size_t len = strlen(word);
	for (;;) {
		size_t match_pos = text_find_prev(txt, pos, word);
		if (match_pos != pos) {
			Filerange match_word = text_object_word(txt, match_pos);
			if (text_range_size(&match_word) == len)
				return match_word;
			pos = match_pos;
		} else {
			return text_range_empty();
		}
	}
}
예제 #2
0
static size_t text_function_end_direction(Text *txt, size_t pos, int direction) {
	size_t start = pos, match;
	if (direction < 0 && pos > 0)
		pos--;
	for (;;) {
		char c[3];
		if (direction > 0)
			match = text_find_next(txt, pos, "\n}");
		else
			match = text_find_prev(txt, pos, "\n}");
		if (text_bytes_get(txt, match, sizeof c, c) != 3 || c[0] != '\n' || c[1] != '}')
			break;
		if (c[2] == '\r' || c[2] == '\n')
			return match+1;
		if (match == pos)
			match += direction;
		pos = match;
	}
	return start;
}