string-util: add strstrafter()
strstrafter() is like strstr() but returns a pointer to the first character *after* the found substring, not on the substring itself. Quite often this is what we actually want. Inspired by #27267 I think it makes sense to add a helper for this, to avoid the potentially fragile manual pointer increment afterwards.
This commit is contained in:
+6
-6
@@ -87,26 +87,26 @@ int xml_tokenize(const char **p, char **name, void **state, unsigned *line) {
|
||||
|
||||
if (startswith(b, "!--")) {
|
||||
/* A comment */
|
||||
e = strstr(b + 3, "-->");
|
||||
e = strstrafter(b + 3, "-->");
|
||||
if (!e)
|
||||
return -EINVAL;
|
||||
|
||||
inc_lines(line, b, e + 3 - b);
|
||||
inc_lines(line, b, e - b);
|
||||
|
||||
c = e + 3;
|
||||
c = e;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (*b == '?') {
|
||||
/* Processing instruction */
|
||||
|
||||
e = strstr(b + 1, "?>");
|
||||
e = strstrafter(b + 1, "?>");
|
||||
if (!e)
|
||||
return -EINVAL;
|
||||
|
||||
inc_lines(line, b, e + 2 - b);
|
||||
inc_lines(line, b, e - b);
|
||||
|
||||
c = e + 2;
|
||||
c = e;
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user