summaryrefslogtreecommitdiffstats
path: root/smenu.c
diff options
context:
space:
mode:
authorpgen <p.gen.progs@gmail.com>2018-06-16 00:00:06 +0200
committerpgen <p.gen.progs@gmail.com>2018-07-08 11:57:31 +0200
commit099d756c28e51980dba3d29b94802e8f0fc0d7ff (patch)
tree2562470d3e61c7d76850f9aa4990fb7cbc8dab73 /smenu.c
parent652156702692f29cade1079c230a09d19e9755ef (diff)
Add mb_next and mb_prev helper functions
Diffstat (limited to 'smenu.c')
-rw-r--r--smenu.c39
1 files changed, 39 insertions, 0 deletions
diff --git a/smenu.c b/smenu.c
index b47d8df..680a047 100644
--- a/smenu.c
+++ b/smenu.c
@@ -217,6 +217,12 @@ mb_interpret(char * s, langinfo_t * langinfo);
static int
mb_validate(const char * str, int length);
+char *
+mb_prev(const char * str, const char * p);
+
+char *
+mb_next(char * p);
+
static int
#ifdef __sun
outch(char c);
@@ -3163,6 +3169,39 @@ mb_offset(char * s, int n)
return i;
}
+/* ================================================== */
+/* Points to the previous multibyte glyph in a string */
+/* from the given position */
+/* ================================================== */
+char *
+mb_prev(const char * str, const char * p)
+{
+ while ((*p & 0xc0) == 0x80)
+ p--;
+
+ for (--p; p >= str; --p)
+ {
+ if ((*p & 0xc0) != 0x80)
+ return (char *)p;
+ }
+ return NULL;
+}
+
+/* ============================================== */
+/* Points to the next multibyte glyph in a string */
+/* from the current position */
+/* ============================================== */
+char *
+mb_next(char * p)
+{
+ if (*p)
+ {
+ for (++p; (*p & 0xc0) == 0x80; ++p)
+ ;
+ }
+ return (*p == '\0' ? NULL : p);
+}
+
/* =========================================================== */
/* Replace any multibyte present in s by a dot inplace */
/* s will be modified but its address in meory will not change */