36 static int utf8_id = -1;
43 #define PG_UTF8 pg_get_utf8_id()
57 else if ((*
c & 0xe0) == 0xc0)
60 else if ((*
c & 0xf0) == 0xe0)
61 return (
pg_wchar) (((
c[0] & 0x0f) << 12) |
62 ((
c[1] & 0x3f) << 6) |
64 else if ((*
c & 0xf8) == 0xf0)
65 return (
pg_wchar) (((
c[0] & 0x07) << 18) |
66 ((
c[1] & 0x3f) << 12) |
67 ((
c[2] & 0x3f) << 6) |
86 else if ((*
c & 0xe0) == 0xc0)
89 if (((
c[1] & 0xc0) == 0x80) && ((
c[0] & 0x1f) > 0x01))
93 else if ((*
c & 0xf0) == 0xe0)
96 if (((
c[1] & 0xc0) == 0x80) &&
97 (((
c[0] & 0x0f) != 0x00) || ((
c[1] & 0x20) == 0x20)) &&
98 ((
c[2] & 0xc0) == 0x80))
101 int yx = ((
c[1] & 0x3f) << 6) | (
c[0] & 0x3f);
106 (((yx & 0xffe) == 0xffe) ||
107 (((yx & 0xf80) == 0xd80) && (lx >= 0x30) && (lx <= 0x4f)))) ||
108 ((z == 0x0d) && ((yx & 0xb00) == 0x800)))
114 else if ((*
c & 0xf8) == 0xf0)
116 int u = ((
c[0] & 0x07) << 2) | ((
c[1] & 0x30) >> 4);
119 if (((
c[1] & 0xc0) == 0x80) &&
120 (u > 0x00) && (u <= 0x10) &&
121 ((
c[2] & 0xc0) == 0x80) && ((
c[3] & 0xc0) == 0x80))
124 if (((
c[1] & 0x0f) == 0x0f) && ((
c[2] & 0x3f) == 0x3f) &&
125 ((
c[3] & 0x3e) == 0x3e))
138 unsigned char *p = pwcs;
187 if (
len < (
size_t) chlen)
212 int *result_width,
int *result_height,
int *result_format_size)
221 for (; *pwcs &&
len > 0; pwcs += chlen)
224 if (
len < (
size_t) chlen)
232 if (linewidth > width)
238 else if (*pwcs ==
'\r')
243 else if (*pwcs ==
'\t')
249 }
while (linewidth % 8 != 0);
270 format_size += chlen;
274 if (linewidth > width)
280 *result_width = width;
282 *result_height = height;
283 if (result_format_size)
284 *result_format_size = format_size;
295 struct lineptr *lines,
int count)
300 unsigned char *ptr = lines->
ptr;
302 for (; *pwcs &&
len > 0; pwcs += chlen)
305 if (
len < (
size_t) chlen)
314 lines->
width = linewidth;
324 else if (*pwcs ==
'\r')
326 strcpy((
char *) ptr,
"\\r");
330 else if (*pwcs ==
'\t')
336 }
while (linewidth % 8 != 0);
340 sprintf((
char *) ptr,
"\\x%02X", *pwcs);
361 sprintf((
char *) ptr,
"\\u????");
370 for (
i = 0;
i < chlen;
i++)
376 lines->
width = linewidth;
382 (lines + 1)->ptr = NULL;
int PQmblen(const char *s, int encoding)
int PQdsplen(const char *s, int encoding)
static void mb_utf_validate(unsigned char *pwcs)
void pg_wcssize(const unsigned char *pwcs, size_t len, int encoding, int *result_width, int *result_height, int *result_format_size)
int pg_wcswidth(const char *pwcs, size_t len, int encoding)
void pg_wcsformat(const unsigned char *pwcs, size_t len, int encoding, struct lineptr *lines, int count)
static int utf_charcheck(const unsigned char *c)
static int pg_get_utf8_id(void)
static pg_wchar utf8_to_unicode(const unsigned char *c)
unsigned char * mbvalidate(unsigned char *pwcs, int encoding)
#define pg_char_to_encoding