From 099d756c28e51980dba3d29b94802e8f0fc0d7ff Mon Sep 17 00:00:00 2001
From: pgen
Date: Sat, 16 Jun 2018 00:00:06 +0200
Subject: Add mb_next and mb_prev helper functions
---
smenu.c | 39 +++++++++++++++++++++++++++++++++++++++
1 file changed, 39 insertions(+)
(limited to 'smenu.c')
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 */
--
cgit v1.2.3