1
0
mirror of https://github.com/rkd77/elinks.git synced 2024-12-04 14:46:47 -05:00

Added utf8_prevchar for moving throught UTF-8 string to left.

This commit is contained in:
Pavol Babincak 2006-05-01 22:58:51 +02:00 committed by Pavol Babincak
parent 7951d7bf22
commit 9d1008c523
2 changed files with 19 additions and 0 deletions

View File

@ -252,6 +252,24 @@ strlen_utf8(unsigned char **str)
return x; return x;
} }
#define utf8_issingle(p) (((p) & 0x80) == 0)
#define utf8_islead(p) (utf8_issingle(p) || ((p) & 0xc0) == 0xc0)
/* Start from @current and move back to @pos char. This pointer return. The
* most left pointer is @start. */
inline unsigned char *
utf8_prevchar(unsigned char *current, int pos, unsigned char *start)
{
if (current == NULL || start == NULL || pos < 0)
return NULL;
while (pos > 0 && current != start) {
current--;
if (utf8_islead(*current))
pos--;
}
return current;
}
/* Count number of standard terminal cells needed for displaying UTF-8 /* Count number of standard terminal cells needed for displaying UTF-8
* character. */ * character. */
int int

View File

@ -55,6 +55,7 @@ int is_cp_special(int);
void free_conv_table(void); void free_conv_table(void);
#ifdef CONFIG_UTF_8 #ifdef CONFIG_UTF_8
inline unsigned char *encode_utf_8(unicode_val_T); inline unsigned char *encode_utf_8(unicode_val_T);
inline unsigned char *utf8_prevchar(unsigned char *, int, unsigned char *);
inline int utf8charlen(const unsigned char *); inline int utf8charlen(const unsigned char *);
int utf8_char2cells(unsigned char *, unsigned char *); int utf8_char2cells(unsigned char *, unsigned char *);
int utf8_ptr2cells(unsigned char *, unsigned char *); int utf8_ptr2cells(unsigned char *, unsigned char *);