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:
Jim Warner 2017-10-06 00:00:00 -05:00 committed by Craig Small
parent 3afadf56e4
commit 474f4da5d1

View File

@ -507,16 +507,16 @@ static char UTF8_tab[] = {
* Determine difference between total bytes versus printable * Determine difference between total bytes versus printable
* characters in that passed, potentially multi-byte, string */ * characters in that passed, potentially multi-byte, string */
static int utf8_delta (const char *str) { static int utf8_delta (const char *str) {
const unsigned char *p = (const unsigned char *)str; const unsigned char *p = (const unsigned char *)str;
int clen, cnum = 0; int clen, cnum = 0;
while (*p) { while (*p) {
// -1 represents a decoding error, pretend it's untranslated ... // -1 represents a decoding error, pretend it's untranslated ...
if (0 > (clen = UTF8_tab[*p])) return 0; if (0 > (clen = UTF8_tab[*p])) return 0;
p += clen; p += clen;
++cnum; ++cnum;
} }
return (int)((const char *)p - str) - cnum; return (int)((const char *)p - str) - cnum;
} // end: utf8_delta } // end: utf8_delta
@ -524,16 +524,18 @@ static int utf8_delta (const char *str) {
* Determine a physical end within a potential multi-byte string * Determine a physical end within a potential multi-byte string
* where maximum printable chars could be accommodated in width */ * where maximum printable chars could be accommodated in width */
static int utf8_embody (const char *str, int width) { static int utf8_embody (const char *str, int width) {
const unsigned char *p = (const unsigned char *)str; const unsigned char *p = (const unsigned char *)str;
int clen, cnum = 0; int clen, cnum = 0;
while (*p) { if (width > 0) {
// -1 represents a decoding error, pretend it's untranslated ... while (*p) {
if (0 > (clen = UTF8_tab[*p])) return width; // -1 represents a decoding error, pretend it's untranslated ...
p += clen; if (0 > (clen = UTF8_tab[*p])) return width;
if (++cnum >= width) break; p += clen;
} if (++cnum >= width) break;
return (int)((const char *)p - str); }
}
return (int)((const char *)p - str);
} // end: utf8_embody } // end: utf8_embody
@ -556,19 +558,19 @@ static const char *utf8_justify (const char *str, int width, int justr) {
* Returns a physical or logical column number given a * Returns a physical or logical column number given a
* multi-byte string and a target column value */ * multi-byte string and a target column value */
static int utf8_proper_col (const char *str, int col, int tophysical) { static int utf8_proper_col (const char *str, int col, int tophysical) {
const unsigned char *p = (const unsigned char *)str; const unsigned char *p = (const unsigned char *)str;
int clen, tlen = 0, cnum = 0; int clen, tlen = 0, cnum = 0;
while (*p) { while (*p) {
// -1 represents a decoding error, don't encourage repositioning ... // -1 represents a decoding error, don't encourage repositioning ...
if (0 > (clen = UTF8_tab[*p])) return col; if (0 > (clen = UTF8_tab[*p])) return col;
if (cnum + 1 > col && tophysical) break; if (cnum + 1 > col && tophysical) break;
p += clen; p += clen;
tlen += clen; tlen += clen;
if (tlen > col && !tophysical) break; if (tlen > col && !tophysical) break;
++cnum; ++cnum;
} }
return tophysical ? tlen : cnum; return tophysical ? tlen : cnum;
} // end: utf8_proper_col } // end: utf8_proper_col
/*###### Misc Color/Display support ####################################*/ /*###### Misc Color/Display support ####################################*/