tex: fix s/$/x/g - neatvi - [fork] simple vi-type editor with UTF-8 support
(HTM) git clone git://src.adamsgaard.dk/neatvi
(DIR) Log
(DIR) Files
(DIR) Refs
(DIR) README
---
(DIR) commit 29df1c140f074dbd0a4d61baa7256866ba32051c
(DIR) parent 2c0f3f357bcd4446492330f2313464c3c6348343
(HTM) Author: Ali Gholami Rudi <ali@rudi.ir>
Date: Sat, 20 Nov 2021 22:27:24 +0330
ex: fix s/$/x/g
Diffstat:
M ex.c | 4 ++--
A test/v21.sh | 10 ++++++++++
2 files changed, 12 insertions(+), 2 deletions(-)
---
(DIR) diff --git a/ex.c b/ex.c
t@@ -637,10 +637,10 @@ static int ec_substitute(char *loc, char *cmd, char *arg)
sbuf_mem(r, ln, offs[0]);
replace(r, xrep, ln, offs);
ln += offs[1];
- if (!*ln || !strchr(s, 'g'))
- break;
if (offs[1] <= 0) /* zero-length match */
sbuf_chr(r, (unsigned char) *ln++);
+ if (!*ln || *ln == '\n' || !strchr(s, 'g'))
+ break;
}
if (r) {
sbuf_str(r, ln);
(DIR) diff --git a/test/v21.sh b/test/v21.sh
t@@ -0,0 +1,10 @@
+# vi commands
+echo ":e $1"
+echo "i"
+echo "oa"
+echo ":%s/$/x/g"
+echo ":wq"
+
+# the expected output
+echo "x" >&2
+echo "ax" >&2