mirror of
https://github.com/rkd77/elinks.git
synced 2025-01-03 14:57:44 -05:00
Added function utf8_ptr2chars for counting number of characters in string.
This commit is contained in:
parent
8b9d06c977
commit
129bd2f444
@ -299,6 +299,30 @@ utf8_ptr2cells(unsigned char *string, unsigned char *end)
|
|||||||
return cells;
|
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
|
* Count number of bytes from begining of the string needed for displaying
|
||||||
* specified number of cells.
|
* specified number of cells.
|
||||||
|
@ -58,6 +58,7 @@ inline unsigned char *encode_utf_8(unicode_val_T);
|
|||||||
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 *);
|
||||||
|
int utf8_ptr2chars(unsigned char *, unsigned char *);
|
||||||
int utf8_cells2bytes(unsigned char *, int, unsigned char *);
|
int utf8_cells2bytes(unsigned char *, int, unsigned char *);
|
||||||
inline int unicode_to_cell(unicode_val_T);
|
inline int unicode_to_cell(unicode_val_T);
|
||||||
inline int strlen_utf8(unsigned char **);
|
inline int strlen_utf8(unsigned char **);
|
||||||
|
Loading…
Reference in New Issue
Block a user