This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.
Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
---|---|---|
Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |
Other format: | [Raw text] |
When calling regexec with the REG_STARTEND flag and providing an end-of-range value in .rm_eo that points to somewhere in the middle of a word, regexec will nevertheless find a match for \> at that offset. The corresponding case for \<, with a start-of-range value in .rm_so that points to the middle of a word, will /not/ find a match for \< there. The latter is what I expected, the former was a surprise. See attached two files for a demonstration of the above two cases. I know that REG_STARTEND is undocmented, but why is that? Because it is not working right? Or because you don't want people to use it? But what is the point of having a function when it can't be used? (Please CC; not subscribed.) Benno -- http://www.fastmail.com - Does exactly what it says on the tin
#include <regex.h> #include <stdio.h> int search_tail_until(int limit, char *string) { regex_t rgx; regmatch_t match[1]; regcomp(&rgx, "\\>", 0); match[0].rm_so = 0; match[0].rm_eo = limit; if (regexec(&rgx, string, 1, match, REG_STARTEND) == 0) return match[0].rm_so; else return -1; } int main() { int index; char *line = " word. "; index = search_tail_until(8, line); if (index >= 0) printf("Found tail at %i: '%c'\n", index, line[index]); index = search_tail_until(4, line); if (index >= 0) printf("Found tail at %i: '%c'\n", index, line[index]); }
#include <regex.h> #include <stdio.h> #include <string.h> int search_head_from(int start, char *string) { regex_t rgx; regmatch_t match[1]; regcomp(&rgx, "\\<", 0); match[0].rm_so = start; match[0].rm_eo = strlen(string); if (regexec(&rgx, string, 1, match, REG_STARTEND) == 0) return match[0].rm_so; else return -1; } int main() { int index; char *line = " word. "; index = search_head_from(0, line); if (index >= 0) printf("Found head at %i: '%c'\n", index, line[index]); index = search_head_from(4, line); if (index >= 0) printf("Found head at %i: '%c'\n", index, line[index]); }
Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
---|---|---|
Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |