diff options
author | Thomas Voss <mail@thomasvoss.com> | 2024-01-21 04:00:09 +0100 |
---|---|---|
committer | Thomas Voss <mail@thomasvoss.com> | 2024-01-21 04:00:09 +0100 |
commit | ce356e22db97a05982f3b8beacf22cc6d479f933 (patch) | |
tree | 52988a8b4375977427319eee6d047cc2f98ac562 | |
parent | 9f209bb06cfd171a21f222c966e42d813f5f2dc6 (diff) |
Move common code out into islbrk()
-rw-r--r-- | src/grab.c | 22 |
1 files changed, 14 insertions, 8 deletions
@@ -71,17 +71,17 @@ static void cmdy(struct sv, struct ops, size_t, const char *); static void putm(struct sv, regmatch_t *, const char *); static void putm_nc(struct sv, regmatch_t *, const char *); -static void grab(struct ops, FILE *, const char *); -static bool sgrvalid(const char *); -static regex_t mkregex(char *, size_t); -static struct ops comppat(char *); -static char *env_or_default(const char *, const char *); #if GIT_GRAB static FILE *getfstream(int n, char *v[n]); #endif - +static void grab(struct ops, FILE *, const char *); +static struct ops comppat(char *); +static regex_t mkregex(char *, size_t); +static bool islbrk(struct u8view); +static bool sgrvalid(const char *); static bool xisspace(char); static char *xstrchrnul(const char *, char); +static char *env_or_default(const char *, const char *); static int filecnt, rv; static bool bflag, cflag, nflag, sflag, Uflag, zflag; @@ -499,7 +499,7 @@ putm(struct sv sv, regmatch_t *rm, const char *filename) len = (char8_t *)sv.p - pos.p; while (u8gnext(&v, &pos.p, &len)) { - if (*v.p == '\n' || memeq(v.p, "\r\n", 2)) { + if (islbrk(v)) { pos.col = 1; pos.row++; } else @@ -552,7 +552,7 @@ putm_nc(struct sv sv, regmatch_t *rm, const char *filename) len = (char8_t *)sv.p - pos.p; while (u8gnext(&v, &pos.p, &len)) { - if (*v.p == '\n' || memeq(v.p, "\r\n", 2)) { + if (islbrk(v)) { pos.col = 1; pos.row++; } else @@ -568,6 +568,12 @@ putm_nc(struct sv sv, regmatch_t *rm, const char *filename) } bool +islbrk(struct u8view v) +{ + return *v.p == '\n' || (v.len == 2 && memeq(v.p, "\r\n", 2)); +} + +bool sgrvalid(const char *s) { if (!s || !*s) |