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

 StaticAssertDecl (lengthof(pg_enc2icu_tbl)==PG_ENCODING_BE_LAST+1, "pg_enc2icu_tbl incomplete")
 
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 char * 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 303 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 524 of file encnames.c.

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

References sort-test::key.

Referenced by pg_char_to_encoding().

◆ get_encoding_name_for_icu()

const char * get_encoding_name_for_icu ( int  encoding)

Definition at line 472 of file encnames.c.

473{
475 return NULL;
476 return pg_enc2icu_tbl[encoding];
477}
static const char *const pg_enc2icu_tbl[]
Definition: encnames.c:414
int32 encoding
Definition: pg_database.h:41
#define PG_VALID_BE_ENCODING(_enc)
Definition: pg_wchar.h:281

References encoding, pg_enc2icu_tbl, and PG_VALID_BE_ENCODING.

◆ is_encoding_supported_by_icu()

bool is_encoding_supported_by_icu ( int  encoding)

Definition at line 461 of file encnames.c.

462{
464 return false;
465 return (pg_enc2icu_tbl[encoding] != NULL);
466}

References encoding, pg_enc2icu_tbl, and PG_VALID_BE_ENCODING.

Referenced by check_icu_locale_encoding(), createdb(), DefineCollation(), and lookup_collation().

◆ pg_char_to_encoding()

int pg_char_to_encoding ( const char *  name)

Definition at line 549 of file encnames.c.

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

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

Referenced by pg_valid_client_encoding(), and pg_valid_server_encoding().

◆ pg_encoding_to_char()

const char * pg_encoding_to_char ( int  encoding)

Definition at line 587 of file encnames.c.

588{
590 {
592
593 Assert(encoding == p->encoding);
594 return p->name;
595 }
596 return "";
597}
const pg_enc2name pg_enc2name_tbl[]
Definition: encnames.c:308
Assert(PointerIsAligned(start, uint64))
#define PG_VALID_ENCODING(_enc)
Definition: pg_wchar.h:287
pg_enc encoding
Definition: pg_wchar.h:342
const char * name
Definition: pg_wchar.h:341

References Assert(), encoding, pg_enc2name::encoding, pg_enc2name::name, pg_enc2name_tbl, and PG_VALID_ENCODING.

◆ pg_valid_client_encoding()

int pg_valid_client_encoding ( const char *  name)

Definition at line 485 of file encnames.c.

486{
487 int enc;
488
489 if ((enc = pg_char_to_encoding(name)) < 0)
490 return -1;
491
493 return -1;
494
495 return enc;
496}
enc
int pg_char_to_encoding(const char *name)
Definition: encnames.c:549
#define PG_VALID_FE_ENCODING(_enc)
Definition: pg_wchar.h:291

References enc, name, pg_char_to_encoding(), and PG_VALID_FE_ENCODING.

Referenced by check_client_encoding().

◆ pg_valid_server_encoding()

int pg_valid_server_encoding ( const char *  name)

Definition at line 499 of file encnames.c.

500{
501 int enc;
502
503 if ((enc = pg_char_to_encoding(name)) < 0)
504 return -1;
505
507 return -1;
508
509 return enc;
510}

References enc, name, pg_char_to_encoding(), and PG_VALID_BE_ENCODING.

◆ pg_valid_server_encoding_id()

int pg_valid_server_encoding_id ( int  encoding)

Definition at line 513 of file encnames.c.

514{
516}

References encoding, and PG_VALID_BE_ENCODING.

◆ StaticAssertDecl()

StaticAssertDecl ( lengthof(pg_enc2icu_tbl = =PG_ENCODING_BE_LAST+1,
"pg_enc2icu_tbl incomplete"   
)

Variable Documentation

◆ pg_enc2gettext_tbl

const char* pg_enc2gettext_tbl[]

Definition at line 360 of file encnames.c.

◆ pg_enc2icu_tbl

const char* const pg_enc2icu_tbl[]
static

Definition at line 414 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().