diff options
author | June McEnroe <june@causal.agency> | 2022-03-24 18:13:06 -0400 |
---|---|---|
committer | June McEnroe <june@causal.agency> | 2022-03-24 18:13:06 -0400 |
commit | b5ce5d5a326a9a15c2db4950f9daa07935500ffe (patch) | |
tree | f916a54382b5d36effed2a8b0dc5daa5d2b39c01 /bin | |
parent | Add The Invisible Life of Addie LaRue (diff) | |
download | src-b5ce5d5a326a9a15c2db4950f9daa07935500ffe.tar.gz src-b5ce5d5a326a9a15c2db4950f9daa07935500ffe.zip |
Skip matches with ident chars on either side
This fixes, for example, where the link gets placed on static regex_t regex(const char *pattern, int flags) in title.c.
Diffstat (limited to 'bin')
-rw-r--r-- | bin/htagml.c | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/bin/htagml.c b/bin/htagml.c index 32ff1636..1f547be6 100644 --- a/bin/htagml.c +++ b/bin/htagml.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2021 C. McEnroe <june@causal.agency> +/* Copyright (C) 2021 June McEnroe <june@causal.agency> * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -77,6 +77,10 @@ static char *hstrstr(const char *haystack, const char *needle) { return NULL; } +static int isident(int c) { + return isalnum(c) || c == '_'; +} + int main(int argc, char *argv[]) { bool pre = false; bool pipe = false; @@ -190,7 +194,10 @@ int main(int argc, char *argv[]) { size_t mlen = strlen(tag); char *match = (pipe ? hstrstr : strstr)(buf, tag); - while (match > buf && isalnum(match[-1])) { + while ( + match && + ((match > buf && isident(match[-1])) || isident(match[mlen])) + ) { match = (pipe ? hstrstr : strstr)(&match[mlen], tag); } if (!match && tag[0] == 'M') { |