PostgreSQL Source Code  git master
encnames.c File Reference
#include "c.h"
#include <ctype.h>
#include <unistd.h>
#include "mb/pg_wchar.h"
Include dependency graph for encnames.c:

Go to the source code of this file.

Data Structures

struct  pg_encname
 

Macros

#define DEF_ENC2NAME(name, codepage)   { #name, PG_##name }
 

Typedefs

typedef struct pg_encname pg_encname
 

Functions

bool is_encoding_supported_by_icu (int encoding)
 
const char * get_encoding_name_for_icu (int encoding)
 
int pg_valid_client_encoding (const char *name)
 
int pg_valid_server_encoding (const char *name)
 
int pg_valid_server_encoding_id (int encoding)
 
static char * clean_encoding_name (const char *key, char *newkey)
 
int pg_char_to_encoding (const char *name)
 
const char * pg_encoding_to_char (int encoding)
 

Variables

static const pg_encname pg_encname_tbl []
 
const pg_enc2name pg_enc2name_tbl []
 
const pg_enc2gettext pg_enc2gettext_tbl []
 
static const char *const pg_enc2icu_tbl []
 

Macro Definition Documentation

◆ DEF_ENC2NAME

#define DEF_ENC2NAME (   name,
  codepage 
)    { #name, PG_##name }

Definition at line 304 of file encnames.c.

Typedef Documentation

◆ pg_encname

typedef struct pg_encname pg_encname

Function Documentation

◆ clean_encoding_name()

static char* clean_encoding_name ( const char *  key,
char *  newkey 
)
static

Definition at line 525 of file encnames.c.

Referenced by pg_char_to_encoding().

526 {
527  const char *p;
528  char *np;
529 
530  for (p = key, np = newkey; *p != '\0'; p++)
531  {
532  if (isalnum((unsigned char) *p))
533  {
534  if (*p >= 'A' && *p <= 'Z')
535  *np++ = *p + 'a' - 'A';
536  else
537  *np++ = *p;
538  }
539  }
540  *np = '\0';
541  return newkey;
542 }

◆ get_encoding_name_for_icu()

const char* get_encoding_name_for_icu ( int  encoding)

Definition at line 470 of file encnames.c.

References pg_encname::encoding, lengthof, pg_enc2icu_tbl, PG_ENCODING_BE_LAST, PG_VALID_BE_ENCODING, and StaticAssertStmt.

Referenced by get_collation_actual_version(), and surrogate_pair_to_codepoint().

471 {
473  "pg_enc2icu_tbl incomplete");
474 
476  return NULL;
477  return pg_enc2icu_tbl[encoding];
478 }
#define lengthof(array)
Definition: c.h:675
#define StaticAssertStmt(condition, errmessage)
Definition: c.h:859
#define PG_ENCODING_BE_LAST
Definition: pg_wchar.h:289
static const char *const pg_enc2icu_tbl[]
Definition: encnames.c:415
#define PG_VALID_BE_ENCODING(_enc)
Definition: pg_wchar.h:295
int32 encoding
Definition: pg_database.h:41

◆ is_encoding_supported_by_icu()

bool is_encoding_supported_by_icu ( int  encoding)

Definition at line 459 of file encnames.c.

References pg_enc2icu_tbl, and PG_VALID_BE_ENCODING.

Referenced by lookup_collation(), and surrogate_pair_to_codepoint().

460 {
462  return false;
463  return (pg_enc2icu_tbl[encoding] != NULL);
464 }
static const char *const pg_enc2icu_tbl[]
Definition: encnames.c:415
#define PG_VALID_BE_ENCODING(_enc)
Definition: pg_wchar.h:295
int32 encoding
Definition: pg_database.h:41

◆ pg_char_to_encoding()

int pg_char_to_encoding ( const char *  name)

Definition at line 550 of file encnames.c.

References clean_encoding_name(), sort-test::key, lengthof, NAMEDATALEN, and pg_encname_tbl.

Referenced by CreateConversionCommand(), length_in_encoding(), main(), PG_char_to_encoding(), pg_convert(), pg_get_utf8_id(), pg_valid_client_encoding(), pg_valid_server_encoding(), PQenv2encoding(), pqSaveParameterStatus(), ProcessCopyOptions(), processEncodingEntry(), surrogate_pair_to_codepoint(), and to_ascii_encname().

551 {
552  unsigned int nel = lengthof(pg_encname_tbl);
553  const pg_encname *base = pg_encname_tbl,
554  *last = base + nel - 1,
555  *position;
556  int result;
557  char buff[NAMEDATALEN],
558  *key;
559 
560  if (name == NULL || *name == '\0')
561  return -1;
562 
563  if (strlen(name) >= NAMEDATALEN)
564  return -1; /* it's certainly not in the table */
565 
566  key = clean_encoding_name(name, buff);
567 
568  while (last >= base)
569  {
570  position = base + ((last - base) >> 1);
571  result = key[0] - position->name[0];
572 
573  if (result == 0)
574  {
575  result = strcmp(key, position->name);
576  if (result == 0)
577  return position->encoding;
578  }
579  if (result < 0)
580  last = position - 1;
581  else
582  base = position + 1;
583  }
584  return -1;
585 }
#define lengthof(array)
Definition: c.h:675
#define NAMEDATALEN
static const pg_encname pg_encname_tbl[]
Definition: encnames.c:39
const char * name
Definition: encode.c:561
static char * clean_encoding_name(const char *key, char *newkey)
Definition: encnames.c:525

◆ pg_encoding_to_char()

◆ pg_valid_client_encoding()

int pg_valid_client_encoding ( const char *  name)

Definition at line 486 of file encnames.c.

References enc, pg_char_to_encoding(), and PG_VALID_FE_ENCODING.

Referenced by check_client_encoding(), and surrogate_pair_to_codepoint().

487 {
488  int enc;
489 
490  if ((enc = pg_char_to_encoding(name)) < 0)
491  return -1;
492 
493  if (!PG_VALID_FE_ENCODING(enc))
494  return -1;
495 
496  return enc;
497 }
int pg_char_to_encoding(const char *name)
Definition: encnames.c:550
struct pg_encoding enc
Definition: encode.c:562
#define PG_VALID_FE_ENCODING(_enc)
Definition: pg_wchar.h:305
const char * name
Definition: encode.c:561

◆ pg_valid_server_encoding()

int pg_valid_server_encoding ( const char *  name)

Definition at line 500 of file encnames.c.

References enc, pg_char_to_encoding(), and PG_VALID_BE_ENCODING.

Referenced by createdb(), get_encoding_id(), parse_extension_control_file(), and surrogate_pair_to_codepoint().

501 {
502  int enc;
503 
504  if ((enc = pg_char_to_encoding(name)) < 0)
505  return -1;
506 
507  if (!PG_VALID_BE_ENCODING(enc))
508  return -1;
509 
510  return enc;
511 }
int pg_char_to_encoding(const char *name)
Definition: encnames.c:550
struct pg_encoding enc
Definition: encode.c:562
#define PG_VALID_BE_ENCODING(_enc)
Definition: pg_wchar.h:295
const char * name
Definition: encode.c:561

◆ pg_valid_server_encoding_id()

int pg_valid_server_encoding_id ( int  encoding)

Definition at line 514 of file encnames.c.

References PG_VALID_BE_ENCODING.

Referenced by setup_locale_encoding(), and surrogate_pair_to_codepoint().

515 {
517 }
#define PG_VALID_BE_ENCODING(_enc)
Definition: pg_wchar.h:295
int32 encoding
Definition: pg_database.h:41

Variable Documentation

◆ pg_enc2gettext_tbl

const pg_enc2gettext pg_enc2gettext_tbl[]

Definition at line 361 of file encnames.c.

Referenced by SetMessageEncoding().

◆ pg_enc2icu_tbl

const char* const pg_enc2icu_tbl[]
static

Definition at line 415 of file encnames.c.

Referenced by get_encoding_name_for_icu(), and is_encoding_supported_by_icu().

◆ pg_enc2name_tbl

◆ pg_encname_tbl

const pg_encname pg_encname_tbl[]
static

Definition at line 39 of file encnames.c.

Referenced by pg_char_to_encoding().