MCPcopy Create free account
hub / github.com/apache/cloudberry / UtfToLocal

Function UtfToLocal

src/backend/utils/mb/conv.c:506–689  ·  view source on GitHub ↗

* UTF8 ---> local code * * utf: input string in UTF8 encoding (need not be null-terminated) * len: length of input string (in bytes) * iso: pointer to the output area (must be large enough!) (output string will be null-terminated) * map: conversion map for single characters * cmap: conversion map for combined characters * (optional, pass NULL if none) * cmapsize: number of entries i

Source from the content-addressed store, hash-verified

504 * be less than 'len'.
505 */
506int
507UtfToLocal(const unsigned char *utf, int len,
508 unsigned char *iso,
509 const pg_mb_radix_tree *map,
510 const pg_utf_to_local_combined *cmap, int cmapsize,
511 utf_local_conversion_func conv_func,
512 int encoding, bool noError)
513{
514 uint32 iutf;
515 int l;
516 const pg_utf_to_local_combined *cp;
517 const unsigned char *start = utf;
518
519 if (!PG_VALID_ENCODING(encoding))
520 ereport(ERROR,
521 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
522 errmsg("invalid encoding number: %d", encoding)));
523
524 for (; len > 0; len -= l)
525 {
526 unsigned char b1 = 0;
527 unsigned char b2 = 0;
528 unsigned char b3 = 0;
529 unsigned char b4 = 0;
530
531 /* "break" cases all represent errors */
532 if (*utf == '\0')
533 break;
534
535 l = pg_utf_mblen(utf);
536 if (len < l)
537 break;
538
539 if (!pg_utf8_islegal(utf, l))
540 break;
541
542 if (l == 1)
543 {
544 /* ASCII case is easy, assume it's one-to-one conversion */
545 *iso++ = *utf++;
546 continue;
547 }
548
549 /* collect coded char of length l */
550 if (l == 2)
551 {
552 b3 = *utf++;
553 b4 = *utf++;
554 }
555 else if (l == 3)
556 {
557 b2 = *utf++;
558 b3 = *utf++;
559 b4 = *utf++;
560 }
561 else if (l == 4)
562 {
563 b1 = *utf++;

Callers 15

utf8_to_euc_cnFunction · 0.85
utf8_to_winFunction · 0.85
utf8_to_shift_jis_2004Function · 0.85
utf8_to_koi8rFunction · 0.85
utf8_to_koi8uFunction · 0.85
utf8_to_sjisFunction · 0.85
utf8_to_euc_jis_2004Function · 0.85
utf8_to_gb18030Function · 0.85
utf8_to_euc_jpFunction · 0.85
utf8_to_uhcFunction · 0.85
utf8_to_euc_twFunction · 0.85
utf8_to_iso8859Function · 0.85

Calls 8

pg_utf_mblenFunction · 0.85
pg_utf8_islegalFunction · 0.85
report_invalid_encodingFunction · 0.85
store_coded_charFunction · 0.85
pg_mb_radix_convFunction · 0.85
errcodeFunction · 0.50
errmsgFunction · 0.50

Tested by

no test coverage detected