114 #define TEXTBUFLEN 1024
116 #define DatumGetVarStringP(X) ((VarString *) PG_DETOAST_DATUM(X))
117 #define DatumGetVarStringPP(X) ((VarString *) PG_DETOAST_DATUM_PACKED(X))
132 bool length_not_specified);
147 bool length_not_specified);
156 const char *fldsep,
const char *null_string);
162 int *argpos,
int *widthpos,
163 int *flags,
int *width);
167 int flags,
int width);
169 int flags,
int width);
257 if (dst_len >= src_len)
265 if (srcunpacked != src)
275 #define VAL(CH) ((CH) - '0')
276 #define DIG(VAL) ((VAL) + '0')
293 Node *escontext = fcinfo->context;
300 if (inputText[0] ==
'\\' && inputText[1] ==
'x')
302 size_t len = strlen(inputText);
314 for (bc = 0, tp = inputText; *tp !=
'\0'; bc++)
318 else if ((tp[0] ==
'\\') &&
319 (tp[1] >=
'0' && tp[1] <=
'3') &&
320 (tp[2] >=
'0' && tp[2] <=
'7') &&
321 (tp[3] >=
'0' && tp[3] <=
'7'))
323 else if ((tp[0] ==
'\\') &&
332 (
errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
333 errmsg(
"invalid input syntax for type %s",
"bytea")));
348 else if ((tp[0] ==
'\\') &&
349 (tp[1] >=
'0' && tp[1] <=
'3') &&
350 (tp[2] >=
'0' && tp[2] <=
'7') &&
351 (tp[3] >=
'0' && tp[3] <=
'7'))
357 *rp++ = bc +
VAL(tp[3]);
361 else if ((tp[0] ==
'\\') &&
373 (
errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
374 errmsg(
"invalid input syntax for type %s",
"bytea")));
415 else if ((
unsigned char) *vp < 0x20 || (
unsigned char) *vp > 0x7e)
428 (
errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
440 else if ((
unsigned char) *vp < 0x20 || (
unsigned char) *vp > 0x7e)
459 elog(
ERROR,
"unrecognized bytea_output setting: %d",
477 nbytes =
buf->len -
buf->cursor;
508 bool isfirst =
false;
817 for (s = p; n > 0; n--)
902 if (length_not_specified)
909 (
errcode(ERRCODE_SUBSTRING_ERROR),
910 errmsg(
"negative substring length not allowed")));
965 if (length_not_specified)
967 slice_size = L1 = -1;
972 (
errcode(ERRCODE_SUBSTRING_ERROR),
973 errmsg(
"negative substring length not allowed")));
974 slice_size = L1 = -1;
982 slice_size = L1 = -1;
1035 if (S1 > slice_strlen)
1047 E1 =
Min(S1 + L1, slice_start + 1 + slice_strlen);
1049 E1 = slice_start + 1 + slice_strlen;
1055 for (
i = 0;
i < S1 - 1;
i++)
1065 for (
i = S1;
i < E1;
i++)
1070 memcpy(
VARDATA(ret), s, (p - s));
1078 elog(
ERROR,
"invalid backend encoding: encoding max length < 1");
1129 (
errcode(ERRCODE_SUBSTRING_ERROR),
1130 errmsg(
"negative substring length not allowed")));
1133 (
errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
1134 errmsg(
"integer out of range")));
1228 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1229 errmsg(
"nondeterministic collations are not supported for substring searches")));
1244 state->is_multibyte_char_in_char =
false;
1246 state->is_multibyte_char_in_char =
false;
1248 state->is_multibyte_char_in_char =
true;
1254 state->last_match = NULL;
1268 if (len1 >= len2 && len2 > 1)
1270 int searchlength = len1 - len2;
1274 const char *str2 =
state->str2;
1288 if (searchlength < 16)
1290 else if (searchlength < 64)
1292 else if (searchlength < 128)
1294 else if (searchlength < 512)
1296 else if (searchlength < 2048)
1298 else if (searchlength < 4096)
1299 skiptablemask = 127;
1301 skiptablemask = 255;
1302 state->skiptablemask = skiptablemask;
1309 for (
i = 0;
i <= skiptablemask;
i++)
1310 state->skiptable[
i] = len2;
1321 for (
i = 0;
i < last;
i++)
1322 state->skiptable[(
unsigned char) str2[
i] & skiptablemask] = last -
i;
1337 int needle_len =
state->len2;
1341 if (needle_len <= 0)
1345 if (
state->last_match)
1346 start_ptr =
state->last_match + needle_len;
1348 start_ptr =
state->str1;
1362 if (
state->is_multibyte_char_in_char)
1369 while (
state->refpoint < matchptr)
1381 if (
state->refpoint > matchptr)
1383 start_ptr =
state->refpoint;
1389 state->last_match = matchptr;
1401 int haystack_len =
state->len1;
1402 int needle_len =
state->len2;
1403 int skiptablemask =
state->skiptablemask;
1404 const char *haystack =
state->str1;
1405 const char *needle =
state->str2;
1406 const char *haystack_end = &haystack[haystack_len];
1409 Assert(start_ptr >= haystack && start_ptr <= haystack_end);
1411 if (needle_len == 1)
1414 char nchar = *needle;
1417 while (hptr < haystack_end)
1420 return (
char *) hptr;
1426 const char *needle_last = &needle[needle_len - 1];
1429 hptr = start_ptr + needle_len - 1;
1430 while (hptr < haystack_end)
1454 hptr +=
state->skiptable[(
unsigned char) *hptr & skiptablemask];
1469 return state->last_match;
1484 return state->refpos + 1;
1496 state->last_match = NULL;
1518 (
errcode(ERRCODE_INDETERMINATE_COLLATION),
1519 errmsg(
"could not determine which collation to use for string comparison"),
1520 errhint(
"Use the COLLATE clause to set the collation explicitly.")));
1552 result = memcmp(arg1, arg2,
Min(len1, len2));
1553 if ((result == 0) && (len1 != len2))
1554 result = (len1 < len2) ? -1 : 1;
1571 if (len1 == len2 && memcmp(arg1, arg2, len1) == 0)
1574 result =
pg_strncoll(arg1, len1, arg2, len2, mylocale);
1579 result = memcmp(arg1, arg2,
Min(len1, len2));
1580 if ((result == 0) && (len1 != len2))
1581 result = (len1 < len2) ? -1 : 1;
1621 bool locale_is_c =
false;
1680 bool locale_is_c =
false;
1807 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1808 errmsg(
"nondeterministic collations are not supported for substring searches")));
1875 bool collate_c =
false;
1896 if (typid == BPCHAROID)
1898 else if (typid == NAMEOID)
1921 if (typid == NAMEOID)
1956 if (abbreviate || !collate_c)
2027 result = memcmp(a1p, a2p,
Min(len1, len2));
2028 if ((result == 0) && (len1 != len2))
2029 result = (len1 < len2) ? -1 : 1;
2064 result = memcmp(a1p, a2p,
Min(len1, len2));
2065 if ((result == 0) && (len1 != len2))
2066 result = (len1 < len2) ? -1 : 1;
2145 if (len1 == len2 && memcmp(a1p, a2p, len1) == 0)
2163 if (sss->
typid == BPCHAROID)
2192 if (len1 != sss->
last_len1 || memcmp(sss->
buf1, a1p, len1) != 0)
2195 memcpy(sss->
buf1, a1p, len1);
2196 sss->
buf1[len1] =
'\0';
2206 if (len2 != sss->
last_len2 || memcmp(sss->
buf2, a2p, len2) != 0)
2208 memcpy(sss->
buf2, a2p, len2);
2209 sss->
buf2[len2] =
'\0';
2222 result = strcmp(sss->
buf1, sss->
buf2);
2240 const size_t max_prefix_bytes =
sizeof(
Datum);
2243 char *authoritative_data =
VARDATA_ANY(authoritative);
2251 pres = (
char *) &
res;
2253 memset(pres, 0, max_prefix_bytes);
2257 if (sss->
typid == BPCHAROID)
2288 memcpy(pres, authoritative_data,
Min(
len, max_prefix_bytes));
2307 memcmp(sss->
buf1, authoritative_data,
len) == 0)
2314 memcpy(sss->
buf1, authoritative_data,
len);
2324 if (sss->
buflen2 < max_prefix_bytes)
2332 max_prefix_bytes, sss->
locale);
2350 if (bsize < sss->buflen2)
2371 memcpy(pres, sss->
buf2,
Min(max_prefix_bytes, bsize));
2394 #if SIZEOF_DATUM == 8
2421 res = DatumBigEndianToNative(
res);
2425 pfree(authoritative);
2439 double abbrev_distinct,
2445 if (memtupcount < 100)
2456 if (abbrev_distinct <= 1.0)
2457 abbrev_distinct = 1.0;
2459 if (key_distinct <= 1.0)
2470 double norm_abbrev_card = abbrev_distinct / (double) memtupcount;
2472 elog(
LOG,
"varstr_abbrev: abbrev_distinct after %d: %f "
2473 "(key_distinct: %f, norm_abbrev_card: %f, prop_card: %f)",
2474 memtupcount, abbrev_distinct, key_distinct, norm_abbrev_card,
2495 if (abbrev_distinct > key_distinct * sss->
prop_card)
2522 if (memtupcount > 10000)
2541 elog(
LOG,
"varstr_abbrev: aborted abbreviation at %d "
2542 "(abbrev_distinct: %f, key_distinct: %f, prop_card: %f)",
2543 memtupcount, abbrev_distinct, key_distinct, sss->
prop_card);
2562 collid == DEFAULT_COLLATION_OID ||
2603 size_t len1 = strlen(
NameStr(*arg1));
2610 if (
collid == C_COLLATION_OID)
2611 result = (len1 == len2 &&
2629 size_t len2 = strlen(
NameStr(*arg2));
2635 if (
collid == C_COLLATION_OID)
2636 result = (len1 == len2 &&
2653 size_t len1 = strlen(
NameStr(*arg1));
2660 if (
collid == C_COLLATION_OID)
2661 result = !(len1 == len2 &&
2679 size_t len2 = strlen(
NameStr(*arg2));
2685 if (
collid == C_COLLATION_OID)
2686 result = !(len1 == len2 &&
2730 #define CmpCall(cmpfunc) \
2731 DatumGetInt32(DirectFunctionCall2Coll(cmpfunc, \
2732 PG_GET_COLLATION(), \
2733 PG_GETARG_DATUM(0), \
2734 PG_GETARG_DATUM(1)))
2808 else if (len1 < len2)
2810 else if (len1 > len2)
2985 #define PG_STR_GET_BYTEA(str_) \
2986 DatumGetByteaPP(DirectFunctionCall1(byteain, CStringGetDatum(str_)))
3030 bool length_not_specified)
3041 if (length_not_specified)
3053 (
errcode(ERRCODE_SUBSTRING_ERROR),
3054 errmsg(
"negative substring length not allowed")));
3131 (
errcode(ERRCODE_SUBSTRING_ERROR),
3132 errmsg(
"negative substring length not allowed")));
3135 (
errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
3136 errmsg(
"integer out of range")));
3187 for (p = 0; p <=
px; p++)
3189 if ((*
p2 == *p1) && (memcmp(p1,
p2, len2) == 0))
3217 if (n < 0 || n >=
len)
3219 (
errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),
3220 errmsg(
"index %d out of valid range, 0..%d",
3248 if (n < 0 || n >= (int64)
len * 8)
3250 (
errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),
3251 errmsg(
"index %lld out of valid range, 0..%lld",
3252 (
long long) n, (
long long)
len * 8 - 1)));
3255 byteNo = (int) (n / 8);
3256 bitNo = (int) (n % 8);
3258 byte = ((
unsigned char *)
VARDATA_ANY(v))[byteNo];
3260 if (
byte & (1 << bitNo))
3284 if (n < 0 || n >=
len)
3286 (
errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),
3287 errmsg(
"index %d out of valid range, 0..%d",
3293 ((
unsigned char *)
VARDATA(
res))[n] = newByte;
3320 if (n < 0 || n >= (int64)
len * 8)
3322 (
errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),
3323 errmsg(
"index %lld out of valid range, 0..%lld",
3324 (
long long) n, (
long long)
len * 8 - 1)));
3327 byteNo = (int) (n / 8);
3328 bitNo = (int) (n % 8);
3333 if (newBit != 0 && newBit != 1)
3335 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
3336 errmsg(
"new bit must be 0 or 1")));
3341 oldByte = ((
unsigned char *)
VARDATA(
res))[byteNo];
3344 newByte = oldByte & (~(1 << bitNo));
3346 newByte = oldByte | (1 << bitNo);
3348 ((
unsigned char *)
VARDATA(
res))[byteNo] = newByte;
3411 (
errcode(ERRCODE_INVALID_NAME),
3412 errmsg(
"invalid name syntax")));
3414 if (namelist ==
NIL)
3416 (
errcode(ERRCODE_INVALID_NAME),
3417 errmsg(
"invalid name syntax")));
3419 foreach(l, namelist)
3421 char *curname = (
char *)
lfirst(l);
3459 char *nextp = rawstring;
3479 curname = nextp + 1;
3482 endp = strchr(nextp + 1,
'"');
3488 memmove(endp, endp + 1, strlen(endp));
3505 if (curname == nextp)
3517 len = endp - curname;
3520 strncpy(curname, downname,
len);
3534 else if (*nextp ==
'\0')
3548 *namelist =
lappend(*namelist, curname);
3586 char *nextp = rawstring;
3606 curname = nextp + 1;
3609 endp = strchr(nextp + 1,
'"');
3615 memmove(endp, endp + 1, strlen(endp));
3624 curname = endp = nextp;
3632 if (curname == endp)
3646 else if (*nextp ==
'\0')
3663 *namelist =
lappend(*namelist, curname);
3707 char *nextp = rawstring;
3727 curname = nextp + 1;
3730 endp = strchr(nextp + 1,
'"');
3736 memmove(endp, endp + 1, strlen(endp));
3750 if (curname == nextp)
3764 else if (*nextp ==
'\0')
3775 *namelist =
lappend(*namelist, curname);
3949 if ((
cmp == 0) && (len1 != len2))
3950 cmp = (len1 < len2) ? -1 : 1;
4001 int from_sub_text_len;
4014 if (src_text_len < 1 || from_sub_text_len < 1)
4039 chunk_len = curr_ptr - start_ptr;
4044 start_ptr = curr_ptr + from_sub_text_len;
4053 chunk_len = ((
char *) src_text +
VARSIZE_ANY(src_text)) - start_ptr;
4081 p = memchr(p,
'\\', p_end - p);
4088 if (*p >=
'1' && *p <=
'9')
4107 char *start_ptr,
int data_pos)
4114 const char *chunk_start = p;
4119 p = memchr(p,
'\\', p_end - p);
4124 if (p > chunk_start)
4139 if (*p >=
'1' && *p <=
'9')
4151 so = pmatch[0].
rm_so;
4152 eo = pmatch[0].
rm_eo;
4155 else if (*p ==
'\\')
4173 if (so >= 0 && eo >= 0)
4183 chunk_start = start_ptr;
4207 int cflags,
Oid collation,
4208 int search_start,
int n)
4233 if (escape_status < 2)
4247 while (search_start <= data_len)
4269 pg_regerror(regexec_result, re, errMsg,
sizeof(errMsg));
4271 (
errcode(ERRCODE_INVALID_REGULAR_EXPRESSION),
4272 errmsg(
"regular expression failed: %s", errMsg)));
4279 if (n > 0 && nmatches != n)
4286 search_start = pmatch[0].
rm_eo;
4287 if (pmatch[0].rm_so == pmatch[0].rm_eo)
4296 if (pmatch[0].rm_so - data_pos > 0)
4301 pmatch[0].rm_so - data_pos);
4308 start_ptr += chunk_len;
4309 data_pos = pmatch[0].
rm_so;
4315 if (escape_status > 0)
4317 start_ptr, data_pos);
4323 pmatch[0].rm_eo - data_pos);
4324 data_pos = pmatch[0].
rm_eo;
4338 search_start = data_pos;
4339 if (pmatch[0].rm_so == pmatch[0].rm_eo)
4346 if (data_pos < data_len)
4350 chunk_len = ((
char *) src_text +
VARSIZE_ANY(src_text)) - start_ptr;
4372 int inputstring_len;
4383 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
4384 errmsg(
"field position must not be zero")));
4390 if (inputstring_len < 1)
4397 if (fldnum == 1 || fldnum == -1)
4413 if (fldnum == 1 || fldnum == -1)
4435 end_ptr =
VARDATA_ANY(inputstring) + inputstring_len;
4438 end_ptr - start_ptr));
4442 fldnum += numfields + 1;
4461 while (found && --fldnum > 0)
4464 start_ptr = end_ptr + fldsep_len;
4478 int last_len = start_ptr -
VARDATA_ANY(inputstring);
4481 inputstring_len - last_len);
4518 memset(&tstate, 0,
sizeof(tstate));
4523 if (tstate.
astate == NULL)
4558 tstate.tupdesc = rsi->
setDesc;
4596 int inputstring_len;
4631 if (inputstring_len < 1)
4638 null_string, collation);
4658 chunk_len = ((
char *) inputstring +
VARSIZE_ANY(inputstring)) - start_ptr;
4665 chunk_len = end_ptr - start_ptr;
4673 null_string, collation);
4680 start_ptr = end_ptr + fldsep_len;
4696 while (inputstring_len > 0)
4698 int chunk_len =
pg_mblen(start_ptr);
4707 null_string, collation);
4711 start_ptr += chunk_len;
4712 inputstring_len -= chunk_len;
4731 bool is_null =
false;
4733 if (null_string &&
text_isequal(field_value, null_string, collation))
4808 const char *fldsep,
const char *null_string)
4819 bool printed =
false;
4843 if (my_extra == NULL)
4864 typlen = my_extra->
typlen;
4878 if (bitmap && (*bitmap & bitmask) == 0)
4881 if (null_string != NULL)
4892 itemvalue =
fetch_att(p, typbyval, typlen);
4910 if (bitmask == 0x100)
4928 static inline text *
4931 const char *
digits =
"0123456789abcdef";
4935 char *
const end =
buf +
sizeof(
buf);
5020 if (fcinfo->flinfo->fn_extra == NULL)
5027 elog(
ERROR,
"cache lookup failed for type %u", argtypeid);
5031 *((
int *) fcinfo->flinfo->fn_extra) = typlen;
5034 typlen = *((
int *) fcinfo->flinfo->fn_extra);
5041 else if (typlen == -2)
5067 if (fcinfo->flinfo->fn_extra == NULL)
5074 elog(
ERROR,
"cache lookup failed for type %u", argtypeid);
5078 *((
int *) fcinfo->flinfo->fn_extra) = typlen;
5081 typlen = *((
int *) fcinfo->flinfo->fn_extra);
5102 elog(
ERROR,
"invalid compression method id %d", cmid);
5120 if (fcinfo->flinfo->fn_extra == NULL)
5127 elog(
ERROR,
"cache lookup failed for type %u", argtypeid);
5131 *((
int *) fcinfo->flinfo->fn_extra) = typlen;
5134 typlen = *((
int *) fcinfo->flinfo->fn_extra);
5170 elog(
ERROR,
"string_agg_transfn called in non-aggregate context");
5195 bool isfirst =
false;
5247 elog(
ERROR,
"aggregate function called in non-aggregate context");
5274 else if (state2->
len > 0)
5400 elog(
ERROR,
"could not determine data type of concat() input");
5427 bool first_arg =
true;
5470 if (foutcache == NULL)
5587 const char *endp = p +
len;
5622 #define TEXT_FORMAT_FLAG_MINUS 0x0001
5624 #define ADVANCE_PARSE_POINTER(ptr,end_ptr) \
5626 if (++(ptr) >= (end_ptr)) \
5628 (errcode(ERRCODE_INVALID_PARAMETER_VALUE), \
5629 errmsg("unterminated format() type specifier"), \
5630 errhint("For a single \"%%\" use \"%%%%\"."))); \
5642 const char *start_ptr;
5643 const char *end_ptr;
5648 Datum *elements = NULL;
5692 &elmlen, &elmbyval, &elmalign);
5696 &elements, &nulls, &
nitems);
5700 funcvariadic =
true;
5706 funcvariadic =
false;
5717 for (cp = start_ptr; cp < end_ptr; cp++)
5759 if (strchr(
"sIL", *cp) == NULL)
5761 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
5762 errmsg(
"unrecognized format() type specifier \"%.*s\"",
5764 errhint(
"For a single \"%%\" use \"%%%%\".")));
5774 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
5775 errmsg(
"too few arguments for format()")));
5787 isNull = nulls[
arg - 1];
5788 typid = element_type;
5791 elog(
ERROR,
"could not determine data type of format() input");
5798 else if (typid == INT4OID)
5800 else if (typid == INT2OID)
5807 if (typid != prev_width_type)
5813 fmgr_info(typoutputfunc, &typoutputinfo_width);
5814 prev_width_type = typid;
5831 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
5832 errmsg(
"too few arguments for format()")));
5844 isNull = nulls[
arg - 1];
5845 typid = element_type;
5848 elog(
ERROR,
"could not determine data type of format() input");
5857 if (typid != prev_type)
5863 fmgr_info(typoutputfunc, &typoutputfinfo);
5882 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
5883 errmsg(
"unrecognized format() type specifier \"%.*s\"",
5885 errhint(
"For a single \"%%\" use \"%%%%\".")));
5891 if (elements != NULL)
5917 const char *cp = *ptr;
5920 while (*cp >=
'0' && *cp <=
'9')
5922 int8 digit = (*cp -
'0');
5927 (
errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
5928 errmsg(
"number is out of range")));
5964 int *argpos,
int *widthpos,
5965 int *flags,
int *width)
5967 const char *cp = start_ptr;
5990 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
5991 errmsg(
"format specifies argument 0, but arguments are numbered from 1")));
6011 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
6012 errmsg(
"width argument position must be ended by \"$\"")));
6018 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
6019 errmsg(
"format specifies argument 0, but arguments are numbered from 1")));
6043 int flags,
int width)
6050 if (conversion ==
's')
6052 else if (conversion ==
'L')
6054 else if (conversion ==
'I')
6056 (
errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),
6057 errmsg(
"null values cannot be formatted as an SQL identifier")));
6065 if (conversion ==
'I')
6070 else if (conversion ==
'L')
6090 int flags,
int width)
6092 bool align_to_left =
false;
6105 align_to_left =
true;
6107 if (width <= INT_MIN)
6109 (
errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
6110 errmsg(
"number is out of range")));
6114 align_to_left =
true;
6164 #define LEVENSHTEIN_LESS_EQUAL
6194 state->max_d = max_d;
6195 state->match = NULL;
6213 if (
state->source == NULL ||
state->source[0] ==
'\0' ||
6214 candidate == NULL || candidate[0] ==
'\0')
6226 candidate, strlen(candidate), 1, 1, 1,
6227 state->max_d,
true);
6228 if (dist <= state->max_d &&
6229 dist <= strlen(
state->source) / 2 &&
6230 (
state->min_d == -1 || dist < state->min_d))
6232 state->min_d = dist;
6233 state->match = candidate;
6246 return state->match;
6264 (
errcode(ERRCODE_SYNTAX_ERROR),
6265 errmsg(
"Unicode normalization can only be performed if server encoding is UTF8")));
6277 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
6278 errmsg(
"invalid normalization form: %s", formstr)));
6323 (
errmsg(
"Unicode categorization can only be performed if server encoding is UTF8")));
6328 for (
int i = 0;
i <
size;
i++)
6374 for (
pg_wchar *wp = output_chars; *wp; wp++)
6376 unsigned char buf[4];
6386 for (
pg_wchar *wp = output_chars; *wp; wp++)
6448 for (
pg_wchar *wp = output_chars; *wp; wp++)
6451 result = (
size == output_size) &&
6452 (memcmp(input_chars, output_chars,
size *
sizeof(
pg_wchar)) == 0);
6463 for (
size_t i = 0;
i < n;
i++)
6464 if (!isxdigit((
unsigned char) instr[
i]))
6473 if (
c >=
'0' &&
c <=
'9')
6475 if (
c >=
'a' &&
c <=
'f')
6476 return c -
'a' + 0xA;
6477 if (
c >=
'A' &&
c <=
'F')
6478 return c -
'A' + 0xA;
6479 elog(
ERROR,
"invalid hexadecimal digit");
6489 unsigned int result = 0;
6491 for (
size_t i = 0;
i < n;
i++)
6492 result +=
hexval(instr[
i]) << (4 * (n -
i - 1));
6518 if (instr[0] ==
'\\')
6533 int offset = instr[1] ==
'u' ? 2 : 1;
6535 unicode =
hexval_n(instr + offset, 4);
6539 errcode(ERRCODE_INVALID_PARAMETER_VALUE),
6540 errmsg(
"invalid Unicode code point: %04X", unicode));
6556 pair_first = unicode;
6563 instr += 4 + offset;
6566 else if (
len >= 8 && instr[1] ==
'+' &&
isxdigits_n(instr + 2, 6))
6574 errcode(ERRCODE_INVALID_PARAMETER_VALUE),
6575 errmsg(
"invalid Unicode code point: %04X", unicode));
6591 pair_first = unicode;
6601 else if (
len >= 10 && instr[1] ==
'U' &&
isxdigits_n(instr + 2, 8))
6609 errcode(ERRCODE_INVALID_PARAMETER_VALUE),
6610 errmsg(
"invalid Unicode code point: %04X", unicode));
6626 pair_first = unicode;
6638 (
errcode(ERRCODE_SYNTAX_ERROR),
6639 errmsg(
"invalid Unicode escape"),
6640 errhint(
"Unicode escapes must be \\XXXX, \\+XXXXXX, \\uXXXX, or \\UXXXXXXXX.")));
6663 (
errcode(ERRCODE_SYNTAX_ERROR),
6664 errmsg(
"invalid Unicode surrogate pair")));
Datum idx(PG_FUNCTION_ARGS)
#define PG_GETARG_ARRAYTYPE_P(n)
#define ARR_NULLBITMAP(a)
#define PG_RETURN_ARRAYTYPE_P(x)
ArrayBuildState * accumArrayResult(ArrayBuildState *astate, Datum dvalue, bool disnull, Oid element_type, MemoryContext rcontext)
ArrayType * construct_empty_array(Oid elmtype)
void deconstruct_array(ArrayType *array, Oid elmtype, int elmlen, bool elmbyval, char elmalign, Datum **elemsp, bool **nullsp, int *nelemsp)
Datum makeArrayResult(ArrayBuildState *astate, MemoryContext rcontext)
int ArrayGetNItems(int ndim, const int *dims)
static Datum values[MAXATTR]
#define TextDatumGetCString(d)
#define unconstify(underlying_type, expr)
#define OidIsValid(objectId)
static void PGresult const char * p2
static void PGresult * res
Size toast_datum_size(Datum value)
Size toast_raw_datum_size(Datum value)
#define VARATT_EXTERNAL_GET_POINTER(toast_pointer, attr)
int errmsg_internal(const char *fmt,...)
int errhint(const char *fmt,...)
int errcode(int sqlerrcode)
int errmsg(const char *fmt,...)
#define ereturn(context, dummy_value,...)
#define ereport(elevel,...)
uint64 hex_decode_safe(const char *src, size_t len, char *dst, Node *escontext)
uint64 hex_encode(const char *src, size_t len, char *dst)
struct varlena * pg_detoast_datum_packed(struct varlena *datum)
void fmgr_info(Oid functionId, FmgrInfo *finfo)
Datum DirectFunctionCall2Coll(PGFunction func, Oid collation, Datum arg1, Datum arg2)
void fmgr_info_cxt(Oid functionId, FmgrInfo *finfo, MemoryContext mcxt)
bool get_fn_expr_variadic(FmgrInfo *flinfo)
Oid get_fn_expr_argtype(FmgrInfo *flinfo, int argnum)
char * OutputFunctionCall(FmgrInfo *flinfo, Datum val)
#define PG_FREE_IF_COPY(ptr, n)
#define DatumGetByteaPSlice(X, m, n)
#define PG_GETARG_BYTEA_PP(n)
#define PG_GETARG_TEXT_PP(n)
#define PG_RETURN_BYTEA_P(x)
#define DatumGetByteaPP(X)
#define DatumGetTextPP(X)
#define DatumGetBpCharPP(X)
#define PG_GETARG_POINTER(n)
#define PG_RETURN_CSTRING(x)
#define PG_RETURN_INT64(x)
#define PG_GETARG_DATUM(n)
#define PG_GETARG_CSTRING(n)
#define PG_GETARG_INT64(n)
#define PG_GETARG_NAME(n)
#define PG_RETURN_TEXT_P(x)
#define DatumGetTextPSlice(X, m, n)
#define PG_RETURN_INT32(x)
#define PG_RETURN_NAME(x)
#define PG_GETARG_INT32(n)
#define PG_RETURN_DATUM(x)
#define PG_RETURN_POINTER(x)
#define PG_GET_COLLATION()
#define PG_GETARG_BYTEA_P_COPY(n)
#define PG_RETURN_BOOL(x)
void InitMaterializedSRF(FunctionCallInfo fcinfo, bits32 flags)
#define MAT_SRF_USE_EXPECTED_DESC
void px(PlannerInfo *root, Gene *tour1, Gene *tour2, Gene *offspring, int num_gene, City *city_table)
static Datum hash_uint32(uint32 k)
static Datum hash_any(const unsigned char *k, int keylen)
void initHyperLogLog(hyperLogLogState *cState, uint8 bwidth)
double estimateHyperLogLog(hyperLogLogState *cState)
void addHyperLogLog(hyperLogLogState *cState, uint32 hash)
static bool pg_mul_s32_overflow(int32 a, int32 b, int32 *result)
static bool pg_add_s32_overflow(int32 a, int32 b, int32 *result)
if(TABLE==NULL||TABLE_index==NULL)
#define MAX_LEVENSHTEIN_STRLEN
static void const char * fmt
Assert(fmt[strlen(fmt) - 1] !='\n')
List * lappend(List *list, void *datum)
void list_free(List *list)
void getTypeOutputInfo(Oid type, Oid *typOutput, bool *typIsVarlena)
void get_typlenbyvalalign(Oid typid, int16 *typlen, bool *typbyval, char *typalign)
bool get_collation_isdeterministic(Oid colloid)
void get_type_io_data(Oid typid, IOFuncSelector which_func, int16 *typlen, bool *typbyval, char *typalign, char *typdelim, Oid *typioparam, Oid *func)
int16 get_typlen(Oid typid)
Oid get_base_element_type(Oid typid)
int GetDatabaseEncoding(void)
int pg_mbstrlen_with_len(const char *mbstr, int limit)
int pg_mbcharcliplen(const char *mbstr, int len, int limit)
int pg_mbstrlen(const char *mbstr)
int pg_mbcliplen(const char *mbstr, int len, int limit)
void pg_unicode_to_server(pg_wchar c, unsigned char *s)
int pg_database_encoding_max_length(void)
int pg_mb2wchar_with_len(const char *from, pg_wchar *to, int len)
int pg_mblen(const char *mbstr)
char * pstrdup(const char *in)
void pfree(void *pointer)
void * palloc0(Size size)
MemoryContext CurrentMemoryContext
void * repalloc(void *pointer, Size size)
void * MemoryContextAlloc(MemoryContext context, Size size)
#define CHECK_FOR_INTERRUPTS()
int AggCheckCallContext(FunctionCallInfo fcinfo, MemoryContext *aggcontext)
int32 pg_strtoint32(const char *s)
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
uint64 pg_popcount(const char *buf, int bytes)
#define PG_CACHE_LINE_SIZE
bool pg_strxfrm_enabled(pg_locale_t locale)
int pg_strncoll(const char *arg1, size_t len1, const char *arg2, size_t len2, pg_locale_t locale)
bool lc_collate_is_c(Oid collation)
pg_locale_t pg_newlocale_from_collation(Oid collid)
bool pg_locale_deterministic(pg_locale_t locale)
int pg_strcoll(const char *arg1, const char *arg2, pg_locale_t locale)
bool pg_strxfrm_prefix_enabled(pg_locale_t locale)
size_t pg_strxfrm(char *dest, const char *src, size_t destsize, pg_locale_t locale)
size_t pg_strxfrm_prefix(char *dest, const char *src, size_t destsize, pg_locale_t locale)
static rewind_source * source
#define MAX_UNICODE_EQUIVALENT_STRING
static bool is_valid_unicode_codepoint(pg_wchar c)
static pg_wchar surrogate_pair_to_codepoint(pg_wchar first, pg_wchar second)
static bool is_utf16_surrogate_first(pg_wchar c)
static bool is_utf16_surrogate_second(pg_wchar c)
int pg_strcasecmp(const char *s1, const char *s2)
void canonicalize_path(char *path)
static uint32 DatumGetUInt32(Datum X)
static bool DatumGetBool(Datum X)
static Datum PointerGetDatum(const void *X)
static Name DatumGetName(Datum X)
static char * DatumGetCString(Datum X)
static Pointer DatumGetPointer(Datum X)
static int16 DatumGetInt16(Datum X)
static int32 DatumGetInt32(Datum X)
char * quote_literal_cstr(const char *rawstr)
static int cmp(const chr *x, const chr *y, size_t len)
static unsigned hash(unsigned *uv, int n)
size_t pg_regerror(int errcode, const regex_t *preg, char *errbuf, size_t errbuf_size)
int pg_regexec(regex_t *re, const chr *string, size_t len, size_t search_start, rm_detail_t *details, size_t nmatch, regmatch_t pmatch[], int flags)
regex_t * RE_compile_and_cache(text *text_re, int cflags, Oid collation)
const char * quote_identifier(const char *ident)
void truncate_identifier(char *ident, int len, bool warn)
bool scanner_isspace(char ch)
char * downcase_truncate_identifier(const char *ident, int len, bool warn)
static pg_noinline void Size size
struct SortSupportData * SortSupport
StringInfo makeStringInfo(void)
void appendStringInfo(StringInfo str, const char *fmt,...)
void appendBinaryStringInfo(StringInfo str, const void *data, int datalen)
void appendStringInfoSpaces(StringInfo str, int count)
void appendStringInfoString(StringInfo str, const char *s)
void appendStringInfoChar(StringInfo str, char ch)
void initStringInfo(StringInfo str)
StringInfoData * StringInfo
#define appendStringInfoCharMacro(str, ch)
static void initReadOnlyStringInfo(StringInfo str, char *data, int len)
Tuplestorestate * setResult
int(* comparator)(Datum x, Datum y, SortSupport ssup)
Datum(* abbrev_converter)(Datum original, SortSupport ssup)
int(* abbrev_full_comparator)(Datum x, Datum y, SortSupport ssup)
bool(* abbrev_abort)(int memtupcount, SortSupport ssup)
Tuplestorestate * tupstore
bool is_multibyte_char_in_char
hyperLogLogState full_card
hyperLogLogState abbr_card
ToastCompressionId toast_get_compression_id(struct varlena *attr)
@ TOAST_INVALID_COMPRESSION_ID
@ TOAST_LZ4_COMPRESSION_ID
@ TOAST_PGLZ_COMPRESSION_ID
int ssup_datum_unsigned_cmp(Datum x, Datum y, SortSupport ssup)
void tuplestore_putvalues(Tuplestorestate *state, TupleDesc tdesc, const Datum *values, const bool *isnull)
#define att_align_nominal(cur_offset, attalign)
#define att_addlength_pointer(cur_offset, attlen, attptr)
static Datum fetch_att(const void *T, bool attbyval, int attlen)
pg_unicode_category unicode_category(pg_wchar code)
UnicodeNormalizationQC unicode_is_normalized_quickcheck(UnicodeNormalizationForm form, const pg_wchar *input)
pg_wchar * unicode_normalize(UnicodeNormalizationForm form, const pg_wchar *input)
#define PG_UNICODE_VERSION
String * makeString(char *str)
#define VARATT_IS_EXTERNAL_ONDISK(PTR)
#define VARATT_IS_COMPRESSED(PTR)
#define SET_VARSIZE(PTR, len)
#define VARATT_IS_EXTERNAL(PTR)
#define VARSIZE_ANY_EXHDR(PTR)
int bpchartruelen(char *s, int len)
static int varstrfastcmp_locale(char *a1p, int len1, char *a2p, int len2, SortSupport ssup)
static text * convert_to_base(uint64 value, int base)
Datum byteacat(PG_FUNCTION_ARGS)
List * textToQualifiedNameList(text *textval)
Datum unknownrecv(PG_FUNCTION_ARGS)
Datum array_to_text(PG_FUNCTION_ARGS)
Datum byteaoverlay(PG_FUNCTION_ARGS)
static int text_cmp(text *arg1, text *arg2, Oid collid)
Datum textsend(PG_FUNCTION_ARGS)
Datum textoverlay_no_len(PG_FUNCTION_ARGS)
static void text_format_string_conversion(StringInfo buf, char conversion, FmgrInfo *typOutputInfo, Datum value, bool isNull, int flags, int width)
const char * getClosestMatch(ClosestMatchState *state)
static text * text_overlay(text *t1, text *t2, int sp, int sl)
Datum text_format(PG_FUNCTION_ARGS)
Datum textlen(PG_FUNCTION_ARGS)
Datum pg_column_toast_chunk_id(PG_FUNCTION_ARGS)
static void text_position_setup(text *t1, text *t2, Oid collid, TextPositionState *state)
static int32 text_length(Datum str)
static bool varstr_abbrev_abort(int memtupcount, SortSupport ssup)
Datum byteaeq(PG_FUNCTION_ARGS)
Datum text_left(PG_FUNCTION_ARGS)
Datum byteagt(PG_FUNCTION_ARGS)
Datum string_agg_transfn(PG_FUNCTION_ARGS)
static bool text_isequal(text *txt1, text *txt2, Oid collid)
static void text_position_cleanup(TextPositionState *state)
static text * text_catenate(text *t1, text *t2)
static void appendStringInfoText(StringInfo str, const text *t)
Datum textgtname(PG_FUNCTION_ARGS)
Datum textout(PG_FUNCTION_ARGS)
Datum textcat(PG_FUNCTION_ARGS)
Datum text_substr(PG_FUNCTION_ARGS)
Datum bytea_string_agg_finalfn(PG_FUNCTION_ARGS)
Datum text_smaller(PG_FUNCTION_ARGS)
static text * text_substring(Datum str, int32 start, int32 length, bool length_not_specified)
static int check_replace_text_has_escape(const text *replace_text)
Datum text_concat_ws(PG_FUNCTION_ARGS)
static int internal_text_pattern_compare(text *arg1, text *arg2)
Datum string_agg_serialize(PG_FUNCTION_ARGS)
Datum text_ge(PG_FUNCTION_ARGS)
static int varlenafastcmp_locale(Datum x, Datum y, SortSupport ssup)
Datum array_to_text_null(PG_FUNCTION_ARGS)
static const char * text_format_parse_format(const char *start_ptr, const char *end_ptr, int *argpos, int *widthpos, int *flags, int *width)
Datum text_larger(PG_FUNCTION_ARGS)
Datum byteapos(PG_FUNCTION_ARGS)
Datum unicode_assigned(PG_FUNCTION_ARGS)
static bytea * bytea_overlay(bytea *t1, bytea *t2, int sp, int sl)
int varstr_cmp(const char *arg1, int len1, const char *arg2, int len2, Oid collid)
static char * text_position_get_match_ptr(TextPositionState *state)
static int bpcharfastcmp_c(Datum x, Datum y, SortSupport ssup)
Datum text_to_array_null(PG_FUNCTION_ARGS)
static unsigned int hexval_n(const char *instr, size_t n)
Datum byteane(PG_FUNCTION_ARGS)
static bool rest_of_char_same(const char *s1, const char *s2, int len)
Datum byteage(PG_FUNCTION_ARGS)
Datum byteacmp(PG_FUNCTION_ARGS)
Datum text_to_table_null(PG_FUNCTION_ARGS)
Datum text_right(PG_FUNCTION_ARGS)
Datum textne(PG_FUNCTION_ARGS)
Datum textrecv(PG_FUNCTION_ARGS)
Datum byteaGetBit(PG_FUNCTION_ARGS)
static void text_format_append_string(StringInfo buf, const char *str, int flags, int width)
static int text_position(text *t1, text *t2, Oid collid)
bool SplitDirectoriesString(char *rawstring, char separator, List **namelist)
Datum bytea_bit_count(PG_FUNCTION_ARGS)
Datum unicode_normalize_func(PG_FUNCTION_ARGS)
Datum bttext_pattern_sortsupport(PG_FUNCTION_ARGS)
static void split_text_accum_result(SplitTextOutputData *tstate, text *field_value, text *null_string, Oid collation)
Datum byteaSetBit(PG_FUNCTION_ARGS)
Datum split_part(PG_FUNCTION_ARGS)
Datum texteqname(PG_FUNCTION_ARGS)
static FmgrInfo * build_concat_foutcache(FunctionCallInfo fcinfo, int argidx)
Datum text_substr_no_len(PG_FUNCTION_ARGS)
Datum text_name(PG_FUNCTION_ARGS)
Datum byteaSetByte(PG_FUNCTION_ARGS)
Datum text_le(PG_FUNCTION_ARGS)
static void text_position_reset(TextPositionState *state)
Datum text_to_table(PG_FUNCTION_ARGS)
#define ADVANCE_PARSE_POINTER(ptr, end_ptr)
Datum textnename(PG_FUNCTION_ARGS)
static char * text_position_next_internal(char *start_ptr, TextPositionState *state)
Datum to_hex64(PG_FUNCTION_ARGS)
Datum text_to_array(PG_FUNCTION_ARGS)
Datum bytea_substr_no_len(PG_FUNCTION_ARGS)
Datum unicode_is_normalized(PG_FUNCTION_ARGS)
#define TEXT_FORMAT_FLAG_MINUS
static void check_collation_set(Oid collid)
bool SplitGUCList(char *rawstring, char separator, List **namelist)
char * text_to_cstring(const text *t)
Datum textoverlay(PG_FUNCTION_ARGS)
static void appendStringInfoRegexpSubstr(StringInfo str, text *replace_text, regmatch_t *pmatch, char *start_ptr, int data_pos)
bool SplitIdentifierString(char *rawstring, char separator, List **namelist)
static text * array_to_text_internal(FunctionCallInfo fcinfo, ArrayType *v, const char *fldsep, const char *null_string)
Datum to_hex32(PG_FUNCTION_ARGS)
Datum text_starts_with(PG_FUNCTION_ARGS)
Datum byteale(PG_FUNCTION_ARGS)
Datum text_gt(PG_FUNCTION_ARGS)
Datum text_reverse(PG_FUNCTION_ARGS)
Datum to_bin64(PG_FUNCTION_ARGS)
Datum texteq(PG_FUNCTION_ARGS)
Datum to_oct64(PG_FUNCTION_ARGS)
Datum text_pattern_gt(PG_FUNCTION_ARGS)
static int charlen_to_bytelen(const char *p, int n)
void varstr_sortsupport(SortSupport ssup, Oid typid, Oid collid)
static int namefastcmp_c(Datum x, Datum y, SortSupport ssup)
#define PG_STR_GET_BYTEA(str_)
static StringInfo makeStringAggState(FunctionCallInfo fcinfo)
Datum textlename(PG_FUNCTION_ARGS)
Datum icu_unicode_version(PG_FUNCTION_ARGS)
static int namefastcmp_locale(Datum x, Datum y, SortSupport ssup)
Datum bytearecv(PG_FUNCTION_ARGS)
static Datum varstr_abbrev_convert(Datum original, SortSupport ssup)
Datum text_concat(PG_FUNCTION_ARGS)
text * cstring_to_text_with_len(const char *s, int len)
Datum text_pattern_lt(PG_FUNCTION_ARGS)
Datum text_pattern_ge(PG_FUNCTION_ARGS)
Datum btvarstrequalimage(PG_FUNCTION_ARGS)
Datum nameletext(PG_FUNCTION_ARGS)
Datum namenetext(PG_FUNCTION_ARGS)
static int text_position_get_match_pos(TextPositionState *state)
void text_to_cstring_buffer(const text *src, char *dst, size_t dst_len)
Datum to_bin32(PG_FUNCTION_ARGS)
Datum bytea_sortsupport(PG_FUNCTION_ARGS)
static bytea * bytea_substring(Datum str, int S, int L, bool length_not_specified)
Datum to_oct32(PG_FUNCTION_ARGS)
Datum namegttext(PG_FUNCTION_ARGS)
Datum unicode_version(PG_FUNCTION_ARGS)
Datum namegetext(PG_FUNCTION_ARGS)
static UnicodeNormalizationForm unicode_norm_form_from_string(const char *formstr)
static bytea * bytea_catenate(bytea *t1, bytea *t2)
static bool text_position_next(TextPositionState *state)
Datum textoctetlen(PG_FUNCTION_ARGS)
Datum textltname(PG_FUNCTION_ARGS)
Datum byteaoverlay_no_len(PG_FUNCTION_ARGS)
static text * concat_internal(const char *sepstr, int argidx, FunctionCallInfo fcinfo)
text * replace_text_regexp(text *src_text, text *pattern_text, text *replace_text, int cflags, Oid collation, int search_start, int n)
text * cstring_to_text(const char *s)
Datum bttextsortsupport(PG_FUNCTION_ARGS)
Datum text_format_nv(PG_FUNCTION_ARGS)
Datum textpos(PG_FUNCTION_ARGS)
static int varstrfastcmp_c(Datum x, Datum y, SortSupport ssup)
Datum bttext_pattern_cmp(PG_FUNCTION_ARGS)
Datum string_agg_finalfn(PG_FUNCTION_ARGS)
Datum byteaoctetlen(PG_FUNCTION_ARGS)
Datum unistr(PG_FUNCTION_ARGS)
static unsigned int hexval(unsigned char c)
static bool text_format_parse_digits(const char **ptr, const char *end_ptr, int *value)
Datum unknownin(PG_FUNCTION_ARGS)
static bool isxdigits_n(const char *instr, size_t n)
Datum string_agg_deserialize(PG_FUNCTION_ARGS)
Datum byteaout(PG_FUNCTION_ARGS)
Datum namelttext(PG_FUNCTION_ARGS)
Datum pg_column_size(PG_FUNCTION_ARGS)
Datum byteain(PG_FUNCTION_ARGS)
#define DatumGetVarStringPP(X)
Datum pg_column_compression(PG_FUNCTION_ARGS)
Datum name_text(PG_FUNCTION_ARGS)
Datum bytea_string_agg_transfn(PG_FUNCTION_ARGS)
Datum nameeqtext(PG_FUNCTION_ARGS)
Datum bttextnamecmp(PG_FUNCTION_ARGS)
void initClosestMatch(ClosestMatchState *state, const char *source, int max_d)
Datum textin(PG_FUNCTION_ARGS)
Datum string_agg_combine(PG_FUNCTION_ARGS)
Datum byteaGetByte(PG_FUNCTION_ARGS)
Datum btnametextcmp(PG_FUNCTION_ARGS)
Datum unknownsend(PG_FUNCTION_ARGS)
Datum text_pattern_le(PG_FUNCTION_ARGS)
void updateClosestMatch(ClosestMatchState *state, const char *candidate)
Datum bttextcmp(PG_FUNCTION_ARGS)
Datum unknownout(PG_FUNCTION_ARGS)
Datum replace_text(PG_FUNCTION_ARGS)
Datum textgename(PG_FUNCTION_ARGS)
static bool split_text(FunctionCallInfo fcinfo, SplitTextOutputData *tstate)
Datum bytea_substr(PG_FUNCTION_ARGS)
Datum bytealt(PG_FUNCTION_ARGS)
Datum byteasend(PG_FUNCTION_ARGS)
Datum text_lt(PG_FUNCTION_ARGS)
int varstr_levenshtein_less_equal(const char *source, int slen, const char *target, int tlen, int ins_c, int del_c, int sub_c, int max_d, bool trusted)
unsigned char * unicode_to_utf8(pg_wchar c, unsigned char *utf8string)
pg_wchar utf8_to_unicode(const unsigned char *c)