forked from enlightenment/efl
Add function to get the length in characters of a string
SVN revision: 38158
This commit is contained in:
parent
4615291cc2
commit
140b0a9fca
|
@ -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);
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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 */
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue