Add function to get the length in characters of a string

SVN revision: 38158
This commit is contained in:
Iván Briano 2008-12-15 22:03:04 +00:00
parent 4615291cc2
commit 140b0a9fca
5 changed files with 31 additions and 3 deletions

View File

@ -602,6 +602,7 @@ extern "C" {
/* string and font handling */
EAPI int evas_string_char_next_get (const char *str, int pos, int *decoded);
EAPI int evas_string_char_prev_get (const char *str, int pos, int *decoded);
EAPI int evas_string_char_len_get (const char *str);
EAPI void evas_font_path_clear (Evas *e);
EAPI void evas_font_path_append (Evas *e, const char *path);

View File

@ -1214,6 +1214,18 @@ evas_string_char_prev_get(const char *str, int pos, int *decoded)
return p;
}
/**
* Get the length in characters of the string.
* @param str The string to get the length of.
* @return The length in characters (not bytes)
*/
EAPI int
evas_string_char_len_get(const char *str)
{
if (!str) return 0;
return evas_common_font_utf8_get_len(str);
}
/**
* Get the minimum padding a style adds to the text.
* @param style The style to determine padding.

View File

@ -1803,11 +1803,10 @@ _layout_text_append(Ctxt *c, Evas_Object_Textblock_Format *fmt, Evas_Object_Text
if ((repch) && (n->text))
{
int i = 0, len = 0, chlen;
int i, len, chlen;
char *ptr;
while (evas_common_font_utf8_get_next(n->text, &i))
len++;
len = evas_common_font_utf8_get_len(n->text);
chlen = strlen(repch);
str = alloca((len * chlen) + 1);
tbase = str;

View File

@ -20,6 +20,7 @@ EAPI int evas_common_font_get_line_advance (RGBA_Font *fn);
EAPI int evas_common_font_utf8_get_next (unsigned char *buf, int *iindex);
EAPI int evas_common_font_utf8_get_prev (unsigned char *buf, int *iindex);
EAPI int evas_common_font_utf8_get_last (unsigned char *buf, int buflen);
EAPI int evas_common_font_utf8_get_len (unsigned char *buf);
/* draw */

View File

@ -271,3 +271,18 @@ evas_common_font_utf8_get_last(unsigned char *buf, int buflen)
}
return 0;
}
EAPI int
evas_common_font_utf8_get_len(unsigned char *buf)
{
/* returns the number of utf8 characters (not bytes) in the string */
int index = 0, len = 0;
while (buf[index])
{
if ((buf[index] & 0xc0) != 0x80)
len++;
index++;
}
return len;
}