diff options
author | pgen <p.gen.progs@gmail.com> | 2018-06-16 00:00:06 +0200 |
---|---|---|
committer | pgen <p.gen.progs@gmail.com> | 2018-07-08 11:57:31 +0200 |
commit | 099d756c28e51980dba3d29b94802e8f0fc0d7ff (patch) | |
tree | 2562470d3e61c7d76850f9aa4990fb7cbc8dab73 /smenu.c | |
parent | 652156702692f29cade1079c230a09d19e9755ef (diff) |
Add mb_next and mb_prev helper functions
Diffstat (limited to 'smenu.c')
-rw-r--r-- | smenu.c | 39 |
1 files changed, 39 insertions, 0 deletions
@@ -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 */ |