aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto E. Vargas Caballero <k0ga@shike2.com>2014-08-24 16:25:33 +0200
committerRoberto E. Vargas Caballero <k0ga@shike2.com>2014-09-26 19:25:06 +0200
commit23af75fc752f703299921b5a4e866a3ac83b5479 (patch)
treedd84082dae58e7007fd1675c0af2a80d70e85667
parentc7a945c4086ab913cd8a05997bfbc1906645eff4 (diff)
downloadst-23af75fc752f703299921b5a4e866a3ac83b5479.tar.gz
st-23af75fc752f703299921b5a4e866a3ac83b5479.tar.bz2
Simplify utf8decodebyte using some locals
These local variables help to make expressions simpler and avoid use a pointer as induction variable in a for loop.
-rw-r--r--st.c19
1 files changed, 13 insertions, 6 deletions
diff --git a/st.c b/st.c
index 83293f4..455f7f4 100644
--- a/st.c
+++ b/st.c
@@ -453,7 +453,7 @@ static void getbuttoninfo(XEvent *);
static void mousereport(XEvent *);
static size_t utf8decode(char *, long *, size_t);
-static long utf8decodebyte(char, size_t *);
+static long utf8decodebyte(uchar, size_t *);
static size_t utf8encode(long, char *, size_t);
static char utf8encodebyte(long, size_t);
static size_t utf8len(char *);
@@ -590,11 +590,18 @@ utf8decode(char *c, long *u, size_t clen) {
}
long
-utf8decodebyte(char c, size_t *i) {
- for(*i = 0; *i < LEN(utfmask); ++(*i))
- if(((uchar)c & utfmask[*i]) == utfbyte[*i])
- return (uchar)c & ~utfmask[*i];
- return 0;
+utf8decodebyte(uchar c, size_t *len) {
+ size_t i;
+ long ret = 0;
+
+ for(i = 0; i < LEN(utfmask); ++i) {
+ if((c & utfmask[i]) == utfbyte[i]) {
+ ret = c & ~utfmask[i];
+ break;
+ }
+ }
+ *len = i;
+ return ret;
}
size_t