diff options
author | xhe <xw897002528@gmail.com> | 2018-12-07 10:51:18 +0800 |
---|---|---|
committer | rofl0r <retnyg@gmx.net> | 2019-01-16 02:38:18 +0000 |
commit | 502b08abdfefe87bed3805dc5ca142165cdd5f72 (patch) | |
tree | c6a99683a4db1d668577ead29fd917f95a666e6e | |
parent | 1274271a37914875fe4f4ca41d63ed17746c0adf (diff) | |
download | gettext-tiny-502b08abdfefe87bed3805dc5ca142165cdd5f72.tar.gz |
poparser: not to skip sysdeps other than %<PRIu32>
follow https://github.com/sabotage-linux/gettext-tiny/issues/39#issuecomment-445036044.
it's obvious that, strstr will search for `%<PRIu32>` first, if there's
one, then we get there and skip all other sysdep strings before the first
`%<PRIu32>`. but what we want is, to search the first sysdep string.
so, our new stragegy is to search for `%` instead. such that, we will
always match the first sysdep string.
-rw-r--r-- | src/poparser.c | 32 |
1 files changed, 18 insertions, 14 deletions
diff --git a/src/poparser.c b/src/poparser.c index dc4cf86..55f9c49 100644 --- a/src/poparser.c +++ b/src/poparser.c @@ -358,20 +358,24 @@ size_t poparser_sysdep(const char *in, char *out, int cnt[]) { outs = out; x = in; - for (n=0; n < st_max;) { - if ((y = strstr(x, sysdep_str[n])) && *(y-1) == '%') { - if (outs) - memcpy(out, x, y-x); - out += y-x; - x = y + strlen(sysdep_str[n]); - - y = sysdep_repl[n][cnt[n]+1]; - if (outs) - memcpy(out, y, strlen(y)); - out += strlen(y); - - n = 0; - } else n++; + while ((y = strchr(x, '%'))) { + y++; + + for (n=0; n < st_max; n++) { + if (!memcmp(y, sysdep_str[n], strlen(sysdep_str[n]))) { + if (outs) + memcpy(out, x, y-x); + out += y-x; + x = y + strlen(sysdep_str[n]); + + y = sysdep_repl[n][cnt[n]+1]; + if (outs) + memcpy(out, y, strlen(y)); + out += strlen(y); + + break; + } + } } if (outs) |