+2003-02-01 Peter Verthez <Peter.Verthez@advalvas.be>
+
+ * utf8tools.h, utf8.c: New functions next_utf8_char and nth_utf8_char.
+
2002-12-30 Peter Verthez <Peter.Verthez@advalvas.be>
* release 0.1.0
/* $Name$ */
#include "utf8tools.h"
+#include <string.h>
int is_utf8_string(const char* str)
{
if (!str) return 0;
while (*str) {
- if ((*str & 0x80) == 0 || (*str & 0xC0) == 0xC0)
- num_char++;
+ if ((*str & 0xC0) != 0xC0) num_char++;
str++;
}
return num_char;
}
+char* next_utf8_char(char* str)
+{
+ if (!str) return NULL;
+
+ if (*str) {
+ str++;
+ while (*str && (*str & 0xC0) == 0x80)
+ str++;
+ }
+ return str;
+}
+
+char* nth_utf8_char(char* str, int n)
+{
+ int num_char = 0;
+ if (!str) return NULL;
+
+ if (*str) {
+ str++;
+ while (*str) {
+ if ((*str & 0xC0) != 0x80) num_char++;
+ if (num_char == n) break;
+ str++;
+ }
+ }
+ return str;
+}
/* Returns 1 if string is valid UTF-8 string, 0 otherwise */
int is_utf8_string(const char* input);
+ /* Returns respectively a pointer to the next or the nth UTF-8 character.
+ The value n = 0 is the first character of the input, i.e.
+ next_utf8_char(input) is the same as nth_utf8_char(input, 1) */
+char* next_utf8_char(char* input);
+char* nth_utf8_char(char* input, int n);
+
/* Functions for creating and freeing conversion buffers yourself */
conv_buffer_t create_conv_buffer(int size);
void free_conv_buffer(conv_buffer_t buf);