Insure correct UTF-8 encoding: asc( chr( 0x800)) == 0x800.

buffer-position displays unicode value of character under cursor instead of first byte of unicode sequence.
This commit is contained in:
Renaud 2015-02-06 13:20:51 +08:00
parent 4cbf1e9ae1
commit 2cef071492
2 changed files with 7 additions and 4 deletions

View File

@ -73,7 +73,7 @@ int showcpos(int f, int n)
int numlines; /* # of lines in file */ int numlines; /* # of lines in file */
long predchars; /* # chars preceding point */ long predchars; /* # chars preceding point */
int predlines; /* # lines preceding point */ int predlines; /* # lines preceding point */
int curchar; /* character under cursor */ unicode_t curchar ; /* character under cursor */
int ratio; int ratio;
int col; int col;
int savepos; /* temp save for current offset */ int savepos; /* temp save for current offset */
@ -91,12 +91,15 @@ int showcpos(int f, int n)
while (lp != curbp->b_linep) { while (lp != curbp->b_linep) {
/* if we are on the current line, record it */ /* if we are on the current line, record it */
if (lp == curwp->w_dotp) { if (lp == curwp->w_dotp) {
int len ;
predlines = numlines; predlines = numlines;
predchars = numchars + curwp->w_doto; predchars = numchars + curwp->w_doto;
if ((curwp->w_doto) == llength(lp)) len = llength( lp) ;
if( (curwp->w_doto) == len)
curchar = '\n'; curchar = '\n';
else else
curchar = lgetc(lp, curwp->w_doto); (void) utf8_to_unicode( lp->l_text, curwp->w_doto, len, &curchar) ;
} }
/* on to the next line */ /* on to the next line */
++numlines; ++numlines;

2
utf8.c
View File

@ -97,7 +97,7 @@ unsigned unicode_to_utf8(unsigned int c, char *utf8)
bytes++; bytes++;
prefix >>= 1; prefix >>= 1;
c >>= 6; c >>= 6;
} while (c > prefix); } while( c >= prefix) ;
*p = c - 2*prefix; *p = c - 2*prefix;
reverse_string(utf8, p); reverse_string(utf8, p);
} }