diff options
author | Thomas Adam <thomas@xteddy.org> | 2019-11-27 22:01:24 +0000 |
---|---|---|
committer | Thomas Adam <thomas@xteddy.org> | 2019-11-27 22:01:24 +0000 |
commit | c13838436e6883d191374f1628e675bfbb8c8aeb (patch) | |
tree | c8052384319cfa74b73ba77fc52ea873097bfd7a | |
parent | d0655f321f5a9f3c478db4b8b513886b7889de33 (diff) | |
parent | eb4d60b1ce0e2dc917bd47b10a3ce89de840448a (diff) | |
download | rtmux-c13838436e6883d191374f1628e675bfbb8c8aeb.tar.gz rtmux-c13838436e6883d191374f1628e675bfbb8c8aeb.tar.bz2 rtmux-c13838436e6883d191374f1628e675bfbb8c8aeb.zip |
Merge branch 'obsd-master'
-rw-r--r-- | regsub.c | 24 |
1 files changed, 12 insertions, 12 deletions
@@ -77,10 +77,7 @@ regsub(const char *pattern, const char *with, const char *text, int flags) end = strlen(text); while (start <= end) { - m[0].rm_so = start; - m[0].rm_eo = end; - - if (regexec(&r, text, nitems(m), m, REG_STARTEND) != 0) { + if (regexec(&r, text + start, nitems(m), m, 0) != 0) { regsub_copy(&buf, &len, text, start, end); break; } @@ -89,22 +86,25 @@ regsub(const char *pattern, const char *with, const char *text, int flags) * Append any text not part of this match (from the end of the * last match). */ - regsub_copy(&buf, &len, text, last, m[0].rm_so); + regsub_copy(&buf, &len, text, last, m[0].rm_so + start); /* * If the last match was empty and this one isn't (it is either * later or has matched text), expand this match. If it is * empty, move on one character and try again from there. */ - if (empty || m[0].rm_so != last || m[0].rm_so != m[0].rm_eo) { - regsub_expand(&buf, &len, with, text, m, nitems(m)); - - last = m[0].rm_eo; - start = m[0].rm_eo; + if (empty || + start + m[0].rm_so != last || + m[0].rm_so != m[0].rm_eo) { + regsub_expand(&buf, &len, with, text + start, m, + nitems(m)); + + last = start + m[0].rm_eo; + start += m[0].rm_eo; empty = 0; } else { - last = m[0].rm_eo; - start = m[0].rm_eo + 1; + last = start + m[0].rm_eo; + start += m[0].rm_eo + 1; empty = 1; } |