top: utf8 utils should observe indentation conventions
Gosh, all this time we used indents of 4 spaces, not 3 spaces which were always the top standard indentation. [ and we made our 'utf8_embody' a little more robust ] Signed-off-by: Jim Warner <james.warner@comcast.net>
This commit is contained in:
parent
fba7a919fb
commit
ac76afee36
62
top/top.c
62
top/top.c
@ -668,16 +668,16 @@ static char UTF8_tab[] = {
|
||||
* Determine difference between total bytes versus printable
|
||||
* characters in that passed, potentially multi-byte, string */
|
||||
static int utf8_delta (const char *str) {
|
||||
const unsigned char *p = (const unsigned char *)str;
|
||||
int clen, cnum = 0;
|
||||
const unsigned char *p = (const unsigned char *)str;
|
||||
int clen, cnum = 0;
|
||||
|
||||
while (*p) {
|
||||
// -1 represents a decoding error, pretend it's untranslated ...
|
||||
if (0 > (clen = UTF8_tab[*p])) return 0;
|
||||
p += clen;
|
||||
++cnum;
|
||||
}
|
||||
return (int)((const char *)p - str) - cnum;
|
||||
while (*p) {
|
||||
// -1 represents a decoding error, pretend it's untranslated ...
|
||||
if (0 > (clen = UTF8_tab[*p])) return 0;
|
||||
p += clen;
|
||||
++cnum;
|
||||
}
|
||||
return (int)((const char *)p - str) - cnum;
|
||||
} // end: utf8_delta
|
||||
|
||||
|
||||
@ -685,16 +685,18 @@ static int utf8_delta (const char *str) {
|
||||
* Determine a physical end within a potential multi-byte string
|
||||
* where maximum printable chars could be accommodated in width */
|
||||
static int utf8_embody (const char *str, int width) {
|
||||
const unsigned char *p = (const unsigned char *)str;
|
||||
int clen, cnum = 0;
|
||||
const unsigned char *p = (const unsigned char *)str;
|
||||
int clen, cnum = 0;
|
||||
|
||||
while (*p) {
|
||||
// -1 represents a decoding error, pretend it's untranslated ...
|
||||
if (0 > (clen = UTF8_tab[*p])) return width;
|
||||
p += clen;
|
||||
if (++cnum >= width) break;
|
||||
}
|
||||
return (int)((const char *)p - str);
|
||||
if (width > 0) {
|
||||
while (*p) {
|
||||
// -1 represents a decoding error, pretend it's untranslated ...
|
||||
if (0 > (clen = UTF8_tab[*p])) return width;
|
||||
p += clen;
|
||||
if (++cnum >= width) break;
|
||||
}
|
||||
}
|
||||
return (int)((const char *)p - str);
|
||||
} // end: utf8_embody
|
||||
|
||||
|
||||
@ -717,19 +719,19 @@ static const char *utf8_justify (const char *str, int width, int justr) {
|
||||
* Returns a physical or logical column number given a
|
||||
* multi-byte string and a target column value */
|
||||
static int utf8_proper_col (const char *str, int col, int tophysical) {
|
||||
const unsigned char *p = (const unsigned char *)str;
|
||||
int clen, tlen = 0, cnum = 0;
|
||||
const unsigned char *p = (const unsigned char *)str;
|
||||
int clen, tlen = 0, cnum = 0;
|
||||
|
||||
while (*p) {
|
||||
// -1 represents a decoding error, don't encourage repositioning ...
|
||||
if (0 > (clen = UTF8_tab[*p])) return col;
|
||||
if (cnum + 1 > col && tophysical) break;
|
||||
p += clen;
|
||||
tlen += clen;
|
||||
if (tlen > col && !tophysical) break;
|
||||
++cnum;
|
||||
}
|
||||
return tophysical ? tlen : cnum;
|
||||
while (*p) {
|
||||
// -1 represents a decoding error, don't encourage repositioning ...
|
||||
if (0 > (clen = UTF8_tab[*p])) return col;
|
||||
if (cnum + 1 > col && tophysical) break;
|
||||
p += clen;
|
||||
tlen += clen;
|
||||
if (tlen > col && !tophysical) break;
|
||||
++cnum;
|
||||
}
|
||||
return tophysical ? tlen : cnum;
|
||||
} // end: utf8_proper_col
|
||||
|
||||
/*###### Misc Color/Display support ####################################*/
|
||||
|
Loading…
Reference in New Issue
Block a user