ref: 218e1b4b3ed517f1440065c6c01df7e2b8bcff1e
parent: c54271a588654289596561104a945100adf917c4
author: cinap_lenrek <cinap_lenrek@felloff.net>
date: Sun Feb 16 13:50:30 EST 2014
mothra: fix unicode rendering for plaintext we did the utf-8 to unicode conversion in pl_nextc(), but the plaintext handler uses pl_readc() which only translates newlines but otherwise returns bytes. move unicode conversion in pl_readc() fixes it.
--- a/sys/src/cmd/mothra/rdhtml.c
+++ b/sys/src/cmd/mothra/rdhtml.c
@@ -172,10 +172,14 @@
}
/*
* Read a character, translating \r\n, \n\r, \r and \n into \n
+ * convert to runes.
*/
int pl_readc(Hglob *g){
- int c;
static int peek=-1;
+ char crune[UTFmax+1];
+ int c, n;
+ Rune r;
+
if(peek!=-1){
c=peek;
peek=-1;
@@ -192,6 +196,21 @@
if(c!='\r') peek=c;
return '\n';
}
+
+ if(c < Runeself)
+ return c;
+
+ crune[0]=c;
+ for (n=1; n<=sizeof(crune); n++){
+ if(fullrune(crune, n)){
+ chartorune(&r, crune);
+ return r;
+ }
+ c=pl_bread(g);
+ if(c==EOF)
+ return EOF;
+ crune[n]=c;
+ }
return c;
}
void pl_putback(Hglob *g, int c){
@@ -202,7 +221,6 @@
int c;
int n;
Rune r;
- char crune[UTFmax+1];
if(g->heof) return EOF;
if(g->npeekc!=0) return g->peekc[--g->npeekc];
c=pl_readc(g);
@@ -220,19 +238,9 @@
return '<';
}
if(c=='>') return ETAG;
- if(c==EOF) return c;
- for (n=1; n<=sizeof(crune); n++){
- crune[n-1]=c;
- if(fullrune(crune, n)){
- chartorune(&r, crune);
- return r;
- }
- c=pl_readc(g);
- if(c==EOF)
- return EOF;
- }
return c;
}
+
char *unquot(char *dst, char *src, int len){
char *e;