summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWormHeamer2026-01-02 03:15:52 -0500
committerWormHeamer2026-01-02 03:15:52 -0500
commitedfd74e9688eaaf75dac601961c1d4164bf022c9 (patch)
tree7ded60dafe74a2f9e1bca2a479c73bc127aa6fef
parent44d71549612a5224e201495393ded27f43f1f9ea (diff)
move some char/byte next/prev stuff into txt.h, as inline
-rw-r--r--txt.c42
-rw-r--r--txt.h51
2 files changed, 44 insertions, 49 deletions
diff --git a/txt.c b/txt.c
index 7d86f25..7f15300 100644
--- a/txt.c
+++ b/txt.c
@@ -441,48 +441,6 @@ TxtLoc txt_end(Txt *t) {
return (TxtLoc) { t, t->ptbl.n-1, t->ptbl.v[t->ptbl.n-1].n };
}
-TxtLoc bnext(TxtLoc l) {
- TxtPiece *p = &l.t->ptbl.v[l.p];
- if (l.p + 1 < l.t->ptbl.n) {
- if (l.i + 1 < p->n) l.i++;
- else l.p++, l.i = 0;
- } else {
- l.i++;
- if (l.i > p->n) l.i = p->n;
- }
- return l;
-}
-
-TxtLoc bprev(TxtLoc l) {
- if (l.i > 0) {
- return (TxtLoc) { l.t, l.p, l.i - 1 };
- } else if (l.p > 0 && l.t->ptbl.v[l.p - 1].n > 0) {
- return (TxtLoc) { l.t, l.p - 1, l.t->ptbl.v[l.p - 1].n - 1 };
- } else {
- return (TxtLoc) { l.t, 0, 0 };
- }
-}
-
-TxtLoc cnext(TxtLoc l) {
- l = bnext(l);
- while ((txt_byte(l) & 0xc0) == 0x80) l = bnext(l);
- return l;
-}
-
-TxtLoc cprev(TxtLoc l) {
- l = bprev(l);
- while ((txt_byte(l) & 0xc0) == 0x80) l = bprev(l);
- return l;
-}
-
-int at_start(TxtLoc l) {
- return l.p == 0 && l.i == 0;
-}
-
-int at_end(TxtLoc l) {
- return l.p + 1 == l.t->ptbl.n && l.i == l.t->ptbl.v[l.p].n;
-}
-
/* TODO: make these use memchr() or equivalent */
TxtLoc next_newline(TxtLoc l) {
diff --git a/txt.h b/txt.h
index a6e92eb..09d1c61 100644
--- a/txt.h
+++ b/txt.h
@@ -85,13 +85,6 @@ int txt_after(TxtLoc a, TxtLoc b);
TxtLoc txt_start(Txt *t);
TxtLoc txt_end(Txt *t);
-TxtLoc bnext(TxtLoc l);
-TxtLoc bprev(TxtLoc l);
-TxtLoc cnext(TxtLoc l);
-TxtLoc cprev(TxtLoc l);
-int at_start(TxtLoc l);
-int at_end(TxtLoc l);
-
TxtLoc next_newline(TxtLoc l);
TxtLoc prev_newline(TxtLoc l);
TxtLoc start_of_line(TxtLoc l);
@@ -109,4 +102,48 @@ u32 txt_chr(TxtLoc l);
u8 txt_byte(TxtLoc l);
u32 txt_chr_next(TxtLoc *l);
+/* inline funcs */
+
+static inline int at_start(TxtLoc l) {
+ return l.p == 0 && l.i == 0;
+}
+
+static inline int at_end(TxtLoc l) {
+ return l.p + 1 == l.t->ptbl.n && l.i == l.t->ptbl.v[l.p].n;
+}
+
+static inline TxtLoc bnext(TxtLoc l) {
+ TxtPiece *p = &l.t->ptbl.v[l.p];
+ if (l.p + 1 < l.t->ptbl.n) {
+ if (l.i + 1 < p->n) l.i++;
+ else l.p++, l.i = 0;
+ } else {
+ l.i++;
+ if (l.i > p->n) l.i = p->n;
+ }
+ return l;
+}
+
+static inline TxtLoc bprev(TxtLoc l) {
+ if (l.i > 0) {
+ return (TxtLoc) { l.t, l.p, l.i - 1 };
+ } else if (l.p > 0 && l.t->ptbl.v[l.p - 1].n > 0) {
+ return (TxtLoc) { l.t, l.p - 1, l.t->ptbl.v[l.p - 1].n - 1 };
+ } else {
+ return (TxtLoc) { l.t, 0, 0 };
+ }
+}
+
+static inline TxtLoc cnext(TxtLoc l) {
+ l = bnext(l);
+ while ((txt_byte(l) & 0xc0) == 0x80) l = bnext(l);
+ return l;
+}
+
+static inline TxtLoc cprev(TxtLoc l) {
+ l = bprev(l);
+ while ((txt_byte(l) & 0xc0) == 0x80) l = bprev(l);
+ return l;
+}
+
#endif