ref: 48e6bc334af6e703e721a7a414c4224a9e7e9720
parent: a06edd054d362c277dbbe6e6cdcddd232ec0fe10
author: cinap_lenrek <cinap_lenrek@gmx.de>
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);
--
⑨