/* 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);
}
/**
+ * 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.
* @param l Pointer to the current left padding value
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;
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 */
}
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;
+}