#include "postgres.h"
#include "utils/builtins.h"
#include <ctype.h>
#include <unistd.h>
#include "mb/pg_wchar.h"
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_encname * | pg_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 [] |
Definition at line 303 of file encnames.c.
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 | ) |
Definition at line 512 of file encnames.c.
References pg_encname::encoding, and pg_char_to_encname_struct().
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(), and to_ascii_encname().
{ pg_encname *p; if (!name) return -1; p = pg_char_to_encname_struct(name); return p ? p->encoding : -1; }
Datum PG_char_to_encoding | ( | PG_FUNCTION_ARGS | ) |
Definition at line 525 of file encnames.c.
References NameStr, pg_char_to_encoding(), PG_GETARG_NAME, and PG_RETURN_INT32.
{ Name s = PG_GETARG_NAME(0); PG_RETURN_INT32(pg_char_to_encoding(NameStr(*s))); }
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 | ) |
Definition at line 534 of file encnames.c.
References Assert, pg_enc2name::encoding, pg_enc2name::name, and PG_VALID_ENCODING.
Referenced by _doSetFixedOutputState(), check_client_encoding(), check_encoding_locale_matches(), check_locale_encoding(), CloneArchive(), CollationCreate(), connectOptions2(), ConversionCreate(), createdb(), dumpEncoding(), exec_command(), main(), pg_do_encoding_conversion(), PG_encoding_to_char(), pg_to_ascii(), PQsetClientEncoding(), SendQuery(), setup_locale_encoding(), and SyncVariables().
{ if (PG_VALID_ENCODING(encoding)) { pg_enc2name *p = &pg_enc2name_tbl[encoding]; Assert(encoding == p->encoding); return p->name; } return ""; }
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().
{ return PG_VALID_BE_ENCODING(encoding); }
Definition at line 357 of file encnames.c.
Referenced by pg_bind_textdomain_codeset().
Definition at line 307 of file encnames.c.
Referenced by check_encoding_conversion_args(), GetPlatformEncoding(), InitializeClientEncoding(), pg_any_to_server(), report_invalid_encoding(), report_untranslatable_char(), SetClientEncoding(), and SetDatabaseEncoding().
Definition at line 32 of file encnames.c.
unsigned int pg_encname_tbl_sz |
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().