/* *pg_wcssizetakesthegivenstringinthegivenencodingandreturnsthree *values: *result_width:Widthindisplaycharactersofthelongestlineinstring *result_height:Numberoflinesindisplayoutput *result_format_size:Numberofbytesrequiredtostoreformatted *representationofstring * *ThisMUSTbekeptinsyncwithpg_wcsformat!
*/ void
pg_wcssize(constunsignedchar *pwcs, size_t len, int encoding, int *result_width, int *result_height, int *result_format_size)
{ int w,
chlen = 0,
linewidth = 0; int width = 0; int height = 1; int format_size = 0;
for (; *pwcs && len > 0; pwcs += chlen)
{
chlen = PQmblen((constchar *) pwcs, encoding); if (len < (size_t) chlen) break;
w = PQdsplen((constchar *) pwcs, encoding);
if (chlen == 1) /* single-byte char */
{ if (*pwcs == '\n') /* Newline */
{ if (linewidth > width)
width = linewidth;
linewidth = 0;
height += 1;
format_size += 1; /* For NUL char */
} elseif (*pwcs == '\r') /* Linefeed */
{
linewidth += 2;
format_size += 2;
} elseif (*pwcs == '\t') /* Tab */
{ do
{
linewidth++;
format_size++;
} while (linewidth % 8 != 0);
} elseif (w < 0) /* Other control char */
{
linewidth += 4;
format_size += 4;
} else/* Output it as-is */
{
linewidth += w;
format_size += 1;
}
} elseif (w < 0) /* Non-ascii control char */
{
linewidth += 6; /* \u0000 */
format_size += 6;
} else/* All other chars */
{
linewidth += w;
format_size += chlen;
}
len -= chlen;
} if (linewidth > width)
width = linewidth;
format_size += 1; /* For NUL char */
/* Set results */ if (result_width)
*result_width = width; if (result_height)
*result_height = height; if (result_format_size)
*result_format_size = format_size;
}
/* *Formatastringintooneormore"structlineptr"lines. *lines[i].ptr==NULLindicatestheendofthearray. * *ThisMUSTbekeptinsyncwithpg_wcssize!
*/ void
pg_wcsformat(constunsignedchar *pwcs, size_t len, int encoding, struct lineptr *lines, int count)
{ int w,
chlen = 0; int linewidth = 0; unsignedchar *ptr = lines->ptr; /* Pointer to data area */
for (; *pwcs && len > 0; pwcs += chlen)
{
chlen = PQmblen((constchar *) pwcs, encoding); if (len < (size_t) chlen) break;
w = PQdsplen((constchar *) pwcs, encoding);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.