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

Added function utf8_ptr2chars for counting number of characters in string.

This commit is contained in:
Pavol Babincak 2006-04-07 22:06:17 +02:00 committed by Pavol Babincak
parent 8b9d06c977
commit 129bd2f444
2 changed files with 25 additions and 0 deletions

View File

@ -299,6 +299,30 @@ utf8_ptr2cells(unsigned char *string, unsigned char *end)
return cells;
}
/* Count number of characters in string. */
int
utf8_ptr2chars(unsigned char *string, unsigned char *end)
{
int charlen, chars = 0;
if (end == NULL)
end = strchr(string, '\0');
if(!string || !end)
return -1;
do {
charlen = utf8charlen(string);
if (string + charlen > end)
break;
chars++;
string += charlen;
} while (1);
return chars;
}
/*
* Count number of bytes from begining of the string needed for displaying
* specified number of cells.

View File

@ -58,6 +58,7 @@ inline unsigned char *encode_utf_8(unicode_val_T);
inline int utf8charlen(const unsigned char *);
int utf8_char2cells(unsigned char *, unsigned char *);
int utf8_ptr2cells(unsigned char *, unsigned char *);
int utf8_ptr2chars(unsigned char *, unsigned char *);
int utf8_cells2bytes(unsigned char *, int, unsigned char *);
inline int unicode_to_cell(unicode_val_T);
inline int strlen_utf8(unsigned char **);