ref: 4c2c62ee964782607aecf8317290e01348d65149
parent: 739c04e572098f05e801d9ae44e9f797195acf93
author: cinap_lenrek <[email protected]>
date: Mon Jul 16 01:32:16 EDT 2012
uhtml: use first match
--- a/sys/src/cmd/uhtml.c
+++ b/sys/src/cmd/uhtml.c
@@ -39,8 +39,8 @@
continue;
break;
}
- if(e - s > 1)
- return smprint("%.*s", (int)(e-s), s);
+ if((e - s) > 1)
+ return smprint("%.*s", (int)(e - s), s);
return nil;
}
@@ -78,18 +78,21 @@
if(nbuf == n){
if(memcmp(p, "\xEF\xBB\xBF", 3)==0){
p += 3;
+ nbuf -= 3;
cset = "utf";
- break;
+ goto Found;
}
if(memcmp(p, "\xFE\xFF", 2) == 0){
p += 2;
+ nbuf -= 2;
cset = "unicode-be";
- break;
+ goto Found;
}
if(memcmp(p, "\xFF\xFE", 2) == 0){
p += 2;
+ nbuf -= 2;
cset = "unicode-le";
- break;
+ goto Found;
}
}
s = g;
@@ -114,28 +117,24 @@
t = *e;
*e = 0;
if((a = attr(g, "encoding")) || (a = attr(g, "charset"))){
- cset = a;
*e = t;
- break;
+ cset = a;
+ goto Found;
}
*e = t;
s = ++e;
} while(t);
}
- nbuf -= p - buf;
-
- if(cset == nil){
- cset = "utf";
- s = p;
- while(s+UTFmax < p+nbuf){
- s += chartorune(&r, s);
- if(r == Runeerror){
- cset = "latin1";
- break;
- }
+ s = p;
+ while(s+UTFmax < p+nbuf){
+ s += chartorune(&r, s);
+ if(r == Runeerror){
+ cset = "latin1";
+ goto Found;
}
}
-
+ cset = "utf";
+Found:
if(pflag){
print("%s\n", cset);
exits(0);