*/
int fz_runelen(int rune);
+/**
+ Compute the index of a rune in a string.
+
+ str: Pointer to beginning of a string.
+
+ p: Pointer to a char in str.
+
+ Returns the index of the rune pointed to by p in str.
+*/
+int fz_runeidx(const char *str, const char *p);
+
+/**
+ Obtain a pointer to the char representing the rune
+ at a given index.
+
+ str: Pointer to beginning of a string.
+
+ idx: Index of a rune to return a char pointer to.
+
+ Returns a pointer to the char where the desired rune starts,
+ or NULL if the string ends before the index is reached.
+*/
+const char *fz_runeptr(const char *str, int idx);
+
/**
Count how many runes the UTF-8 encoded string
consists of.
return fz_runetochar(str, c);
}
+int
+fz_runeidx(const char *s, const char *p)
+{
+ int rune;
+ int i = 0;
+ while (s < p) {
+ if (*(unsigned char *)s < Runeself)
+ ++s;
+ else
+ s += fz_chartorune(&rune, s);
+ ++i;
+ }
+ return i;
+}
+
+const char *
+fz_runeptr(const char *s, int i)
+{
+ int rune;
+ while (i-- > 0) {
+ rune = *(unsigned char*)s;
+ if (rune < Runeself) {
+ if (rune == 0)
+ return NULL;
+ ++s;
+ } else
+ s += fz_chartorune(&rune, s);
+ }
+ return s;
+}
+
int
fz_utflen(const char *s)
{