Move subline() to use String type
This commit is contained in:
parent
77fe371fe4
commit
3ce26f33c6
31
ed.c
31
ed.c
@ -970,26 +970,26 @@ getnth(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
addpre(char **s, size_t *cap, size_t *siz)
|
addpre(String *s)
|
||||||
{
|
{
|
||||||
char *p;
|
char *p;
|
||||||
|
|
||||||
for (p = lastmatch; p < lastmatch + matchs[0].rm_so; ++p)
|
for (p = lastmatch; p < lastmatch + matchs[0].rm_so; ++p)
|
||||||
*s = addchar(*p, *s, cap, siz);
|
addchar_(*p, s);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
addpost(char **s, size_t *cap, size_t *siz)
|
addpost(String *s)
|
||||||
{
|
{
|
||||||
char c, *p;
|
char c, *p;
|
||||||
|
|
||||||
for (p = lastmatch + matchs[0].rm_eo; (c = *p); ++p)
|
for (p = lastmatch + matchs[0].rm_eo; (c = *p); ++p)
|
||||||
*s = addchar(c, *s, cap, siz);
|
addchar_(c, s);
|
||||||
*s = addchar('\0', *s, cap, siz);
|
addchar_('\0', s);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
addsub(char **s, size_t *cap, size_t *siz, int nth, int nmatch)
|
addsub(String *s, int nth, int nmatch)
|
||||||
{
|
{
|
||||||
char *end, *q, *p, c;
|
char *end, *q, *p, c;
|
||||||
int sub;
|
int sub;
|
||||||
@ -998,7 +998,7 @@ addsub(char **s, size_t *cap, size_t *siz, int nth, int nmatch)
|
|||||||
q = lastmatch + matchs[0].rm_so;
|
q = lastmatch + matchs[0].rm_so;
|
||||||
end = lastmatch + matchs[0].rm_eo;
|
end = lastmatch + matchs[0].rm_eo;
|
||||||
while (q < end)
|
while (q < end)
|
||||||
*s = addchar(*q++, *s, cap, siz);
|
addchar_(*q++, s);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1017,11 +1017,11 @@ addsub(char **s, size_t *cap, size_t *siz, int nth, int nmatch)
|
|||||||
q = lastmatch + matchs[sub].rm_so;
|
q = lastmatch + matchs[sub].rm_so;
|
||||||
end = lastmatch + matchs[sub].rm_eo;
|
end = lastmatch + matchs[sub].rm_eo;
|
||||||
while (q < end)
|
while (q < end)
|
||||||
*s = addchar(*q++, *s, cap, siz);
|
addchar_(*q++, s);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
copy_char:
|
copy_char:
|
||||||
*s = addchar(c, *s, cap, siz);
|
addchar_(c, s);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1032,22 +1032,21 @@ static void
|
|||||||
subline(int num, int nth)
|
subline(int num, int nth)
|
||||||
{
|
{
|
||||||
int i, m, changed;
|
int i, m, changed;
|
||||||
static char *s;
|
static String s;
|
||||||
static size_t siz, cap;
|
|
||||||
|
|
||||||
i = changed = siz = 0;
|
i = changed = s.siz = 0;
|
||||||
for (m = match(num); m; m = rematch(num)) {
|
for (m = match(num); m; m = rematch(num)) {
|
||||||
addpre(&s, &cap, &siz);
|
addpre(&s);
|
||||||
changed |= addsub(&s, &cap, &siz, nth, ++i);
|
changed |= addsub(&s, nth, ++i);
|
||||||
if (eol || bol)
|
if (eol || bol)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (!changed)
|
if (!changed)
|
||||||
return;
|
return;
|
||||||
addpost(&s, &cap, &siz);
|
addpost(&s);
|
||||||
delete(num, num);
|
delete(num, num);
|
||||||
curln = prevln(num);
|
curln = prevln(num);
|
||||||
inject(s, 0);
|
inject(s.str, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
Loading…
Reference in New Issue
Block a user