Introduction
Introduction Statistics Contact Development Disclaimer Help
tex: support regular expression groups in :s replacement - neatvi - [fork] simp…
git clone git://src.adamsgaard.dk/neatvi
Log
Files
Refs
README
---
commit 9cc9b8bb918f8a581ed57c730a42d4fe85b3152c
parent df9f5a424f9e869ce1367f3c9ee3ceee84683f9f
Author: Ali Gholami Rudi <[email protected]>
Date: Sat, 7 May 2016 21:35:01 +0430
ex: support regular expression groups in :s replacement
Diffstat:
M ex.c | 21 ++++++++++++++++++++-
1 file changed, 20 insertions(+), 1 deletion(-)
---
diff --git a/ex.c b/ex.c
t@@ -660,6 +660,25 @@ static int ec_mark(char *ec)
return 0;
}
+static void replace(struct sbuf *dst, char *rep, char *ln, int *offs)
+{
+ while (rep[0]) {
+ if (rep[0] == '\\' && rep[1]) {
+ if (rep[1] >= '0' && rep[1] <= '9') {
+ int grp = (rep[1] - '0') * 2;
+ int len = offs[grp + 1] - offs[grp];
+ sbuf_mem(dst, ln + offs[grp], len);
+ } else {
+ sbuf_chr(dst, (unsigned char) rep[1]);
+ }
+ rep++;
+ } else {
+ sbuf_chr(dst, (unsigned char) rep[0]);
+ }
+ rep++;
+ }
+}
+
static int ec_substitute(char *ec)
{
char loc[EXLEN];
t@@ -697,7 +716,7 @@ static int ec_substitute(char *ec)
struct sbuf *r = sbuf_make();
while (rset_find(re, ln, LEN(offs) / 2, offs, 0) >= 0) {
sbuf_mem(r, ln, offs[0]);
- sbuf_str(r, rep);
+ replace(r, rep, ln, offs);
ln += offs[1];
if (!strchr(s, 'g'))
break;
You are viewing proxied material from mx1.adamsgaard.dk. The copyright of proxied material belongs to its original authors. Any comments or complaints in relation to proxied material should be directed to the original authors of the content concerned. Please see the disclaimer for more details.