Use constant for maximum UTF-8 character size

Introduce a UTF8_MAXLEN constant instead of using the literal value "6"
at various places.

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
This commit is contained in:
Lukas Fleischer 2011-06-07 09:42:39 +02:00
parent c8029a5a13
commit e85501e5ef
4 changed files with 6 additions and 4 deletions

View File

@ -200,6 +200,7 @@
#define TOSTRING(x) STRINGIFY(x) #define TOSTRING(x) STRINGIFY(x)
#define __FILE_POS__ __FILE__ ":" TOSTRING(__LINE__) #define __FILE_POS__ __FILE__ ":" TOSTRING(__LINE__)
#define UTF8_MAXLEN 6
#define UTF8_LENGTH(ch) ((unsigned char)ch >= 0xFC ? 6 : \ #define UTF8_LENGTH(ch) ((unsigned char)ch >= 0xFC ? 6 : \
((unsigned char)ch >= 0xF8 ? 5 : \ ((unsigned char)ch >= 0xF8 ? 5 : \
((unsigned char)ch >= 0xF0 ? 4 : \ ((unsigned char)ch >= 0xF0 ? 4 : \

View File

@ -352,7 +352,7 @@ display_item (int incolor, char *msg, int recur, int note, int width, int y,
{ {
WINDOW *win; WINDOW *win;
int ch_recur, ch_note; int ch_recur, ch_note;
char buf[width * 6]; char buf[width * UTF8_MAXLEN];
int i; int i;
if (width <= 0) if (width <= 0)

View File

@ -186,7 +186,7 @@ getstring (WINDOW *win, char *str, int l, int x, int y)
struct getstr_charinfo ci[l + 1]; struct getstr_charinfo ci[l + 1];
int ch, k; int ch, k;
char c[6]; char c[UTF8_MAXLEN];
getstr_init (&st, str, ci); getstr_init (&st, str, ci);
custom_apply_attr (win, ATTR_HIGHEST); custom_apply_attr (win, ATTR_HIGHEST);
@ -255,7 +255,8 @@ getstring (WINDOW *win, char *str, int l, int x, int y)
return (GETSTRING_ESC); return (GETSTRING_ESC);
break; break;
default: /* insert one character */ default: /* insert one character */
for (c[0] = ch, k = 1; k < MIN (UTF8_LENGTH (c[0]), 6); k++) c[0] = ch;
for (k = 1; k < MIN (UTF8_LENGTH (c[0]), UTF8_MAXLEN); k++)
c[k] = (unsigned char)wgetch (win); c[k] = (unsigned char)wgetch (win);
if (st.ci[st.len].offset + k < l) if (st.ci[st.len].offset + k < l)
{ {

View File

@ -374,7 +374,7 @@ display_todo_item (int incolor, char *msg, int prio, int note, int width, int y,
{ {
WINDOW *w; WINDOW *w;
int ch_note; int ch_note;
char buf[width * 6], priostr[2]; char buf[width * UTF8_MAXLEN], priostr[2];
int i; int i;
w = win[TOD].p; w = win[TOD].p;