ref: e76edc13b0c4d5841efb5c04b5fdf3dfbbc144cc
parent: 02a3e714e60e9340e32502bda6bfe3bfe8ff937f
author: Ali Gholami Rudi <[email protected]>
date: Wed Sep 25 15:16:34 EDT 2013
char: add utf8one() to check if a string is a single utf-8 character
--- a/char.c
+++ b/char.c
@@ -20,6 +20,12 @@
return c != 0;
}
+/* return nonzero if s is a single utf-8 character */
+int utf8one(char *s)
+{
+ return !s[utf8len((unsigned char) *s)];
+}
+
int utf8read(char **s, char *d)
{
int l = utf8len((unsigned char) **s);
@@ -100,7 +106,7 @@
void charnext_str(char *d, char *c)
{
int c0 = (unsigned char) c[0];
- if (c0 == c_ec || c0 == c_ni || !c[1] || utf8len(c0) == strlen(c)) {
+ if (c0 == c_ec || c0 == c_ni || !c[1] || utf8one(c)) {
strcpy(d, c);
return;
}
--- a/out.c
+++ b/out.c
@@ -112,7 +112,7 @@
static void outg(char *c)
{
- if (utf8len((unsigned char) c[0]) == strlen(c))
+ if (utf8one(c))
outnn("c%s%s", c, c[1] ? "\n" : "");
else
out("C%s\n", c[0] == c_ec && c[1] == '(' ? c + 2 : c);
--- a/roff.h
+++ b/roff.h
@@ -327,6 +327,7 @@
int utf8len(int c);
int utf8next(char *s, int (*next)(void));
int utf8read(char **s, char *d);
+int utf8one(char *s);
int charnext(char *c, int (*next)(void), void (*back)(int));
int charread(char **s, char *c);
int charnext_delim(char *c, int (*next)(void), void (*back)(int), char *delim);
--- a/wb.c
+++ b/wb.c
@@ -145,8 +145,7 @@
wb_font(wb);
wb_prevcheck(wb); /* make sure wb->prev_c[] is valid */
ll = sbuf_len(&wb->sbuf); /* sbuf length before inserting c */
- if (!c[1] || c[0] == c_ec || c[0] == c_ni ||
- utf8len((unsigned char) c[0]) == strlen(c)) {
+ if (!c[1] || c[0] == c_ec || c[0] == c_ni || utf8one(c)) {
if (c[0] == c_ni && c[1] == c_ec)
sbuf_printf(&wb->sbuf, "%c%c", c_ec, c_ec);
else