Header And Logo

PostgreSQL
| The world's most advanced open source database.

Defines | Functions | Variables

encnames.c File Reference

#include "postgres.h"
#include "utils/builtins.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.

Defines

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

Functions

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)
pg_encnamepg_char_to_encname_struct (const char *name)
int pg_char_to_encoding (const char *name)
Datum PG_char_to_encoding (PG_FUNCTION_ARGS)
const char * pg_encoding_to_char (int encoding)
Datum PG_encoding_to_char (PG_FUNCTION_ARGS)

Variables

pg_encname pg_encname_tbl []
unsigned int pg_encname_tbl_sz
pg_enc2name pg_enc2name_tbl []
pg_enc2gettext pg_enc2gettext_tbl []

Define Documentation

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

Definition at line 303 of file encnames.c.


Function Documentation

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

Definition at line 439 of file encnames.c.

Referenced by pg_char_to_encname_struct().

{
    const char *p;
    char       *np;

    for (p = key, np = newkey; *p != '\0'; p++)
    {
        if (isalnum((unsigned char) *p))
        {
            if (*p >= 'A' && *p <= 'Z')
                *np++ = *p + 'a' - 'A';
            else
                *np++ = *p;
        }
    }
    *np = '\0';
    return newkey;
}

pg_encname* pg_char_to_encname_struct ( const char *  name  ) 

Definition at line 463 of file encnames.c.

References clean_encoding_name(), ereport, errcode(), errmsg(), ERROR, NAMEDATALEN, NULL, and pg_encname_tbl_sz.

Referenced by pg_char_to_encoding().

{
    unsigned int nel = pg_encname_tbl_sz;
    pg_encname *base = pg_encname_tbl,
               *last = base + nel - 1,
               *position;
    int         result;
    char        buff[NAMEDATALEN],
               *key;

    if (name == NULL || *name == '\0')
        return NULL;

    if (strlen(name) >= NAMEDATALEN)
    {
#ifdef FRONTEND
        fprintf(stderr, "encoding name too long\n");
        return NULL;
#else
        ereport(ERROR,
                (errcode(ERRCODE_NAME_TOO_LONG),
                 errmsg("encoding name too long")));
#endif
    }
    key = clean_encoding_name(name, buff);

    while (last >= base)
    {
        position = base + ((last - base) >> 1);
        result = key[0] - position->name[0];

        if (result == 0)
        {
            result = strcmp(key, position->name);
            if (result == 0)
                return position;
        }
        if (result < 0)
            last = position - 1;
        else
            base = position + 1;
    }
    return NULL;
}

int pg_char_to_encoding ( const char *  name  ) 
Datum PG_char_to_encoding ( PG_FUNCTION_ARGS   ) 
Datum PG_encoding_to_char ( PG_FUNCTION_ARGS   ) 

Definition at line 548 of file encnames.c.

References CStringGetDatum, DirectFunctionCall1, encoding, namein(), pg_encoding_to_char(), and PG_GETARG_INT32.

{
    int32       encoding = PG_GETARG_INT32(0);
    const char *encoding_name = pg_encoding_to_char(encoding);

    return DirectFunctionCall1(namein, CStringGetDatum(encoding_name));
}

const char* pg_encoding_to_char ( int  encoding  ) 
int pg_valid_client_encoding ( const char *  name  ) 

Definition at line 401 of file encnames.c.

References enc, pg_char_to_encoding(), and PG_VALID_FE_ENCODING.

Referenced by check_client_encoding().

{
    int         enc;

    if ((enc = pg_char_to_encoding(name)) < 0)
        return -1;

    if (!PG_VALID_FE_ENCODING(enc))
        return -1;

    return enc;
}

int pg_valid_server_encoding ( const char *  name  ) 

Definition at line 415 of file encnames.c.

References enc, pg_char_to_encoding(), and PG_VALID_BE_ENCODING.

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

{
    int         enc;

    if ((enc = pg_char_to_encoding(name)) < 0)
        return -1;

    if (!PG_VALID_BE_ENCODING(enc))
        return -1;

    return enc;
}

int pg_valid_server_encoding_id ( int  encoding  ) 

Definition at line 429 of file encnames.c.

References PG_VALID_BE_ENCODING.

Referenced by setup_locale_encoding().


Variable Documentation

Definition at line 357 of file encnames.c.

Referenced by pg_bind_textdomain_codeset().

Definition at line 32 of file encnames.c.

unsigned int pg_encname_tbl_sz
Initial value:
 
sizeof(pg_encname_tbl) / sizeof(pg_encname_tbl[0]) - 1

Definition at line 294 of file encnames.c.

Referenced by pg_char_to_encname_struct().