From bf00bbb0c4940b80b46b7e5b379cd64184f2262f Mon Sep 17 00:00:00 2001 From: "Marc G. Fournier" Date: Fri, 24 Jul 1998 03:32:46 +0000 Subject: I really hope that I haven't missed anything in this one... From: t-ishii@sra.co.jp Attached are patches to enhance the multi-byte support. (patches are against 7/18 snapshot) * determine encoding at initdb/createdb rather than compile time Now initdb/createdb has an option to specify the encoding. Also, I modified the syntax of CREATE DATABASE to accept encoding option. See README.mb for more details. For this purpose I have added new column "encoding" to pg_database. Also pg_attribute and pg_class are changed to catch up the modification to pg_database. Actually I haved added pg_database_mb.h, pg_attribute_mb.h and pg_class_mb.h. These are used only when MB is enabled. The reason having separate files is I couldn't find a way to use ifdef or whatever in those files. I have to admit it looks ugly. No way. * support for PGCLIENTENCODING when issuing COPY command commands/copy.c modified. * support for SQL92 syntax "SET NAMES" See gram.y. * support for LATIN2-5 * add UNICODE regression test case * new test suite for MB New directory test/mb added. * clean up source files Basic idea is to have MB's own subdirectory for easier maintenance. These are include/mb and backend/utils/mb. --- src/backend/utils/mb/common.c | 67 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 src/backend/utils/mb/common.c (limited to 'src/backend/utils/mb/common.c') diff --git a/src/backend/utils/mb/common.c b/src/backend/utils/mb/common.c new file mode 100644 index 00000000000..c4e796e79ee --- /dev/null +++ b/src/backend/utils/mb/common.c @@ -0,0 +1,67 @@ +/* + * This file contains some public functions + * usable for both the backend and the frontend. + * Tatsuo Ishii + * $Id: common.c,v 1.1 1998/07/24 03:31:56 scrappy Exp $ */ + +#include +#include + +#include "mb/pg_wchar.h" + +/* + * convert encoding char to encoding symbol value. + * case is ignored. + * if there's no valid encoding, returns -1 + */ +int pg_char_to_encoding(const char *s) +{ + pg_encoding_conv_tbl *p = pg_conv_tbl; + + for(;p->encoding >= 0;p++) { + if (!strcasecmp(s, p->name)) { + break; + } + } + return(p->encoding); +} + +/* + * check to see if encoding name is valid + */ +int pg_valid_client_encoding(const char *name) +{ + return(pg_char_to_encoding(name)); +} + +/* + * find encoding table entry by encoding + */ +pg_encoding_conv_tbl *pg_get_encent_by_encoding(int encoding) +{ + pg_encoding_conv_tbl *p = pg_conv_tbl; + for(;p->encoding >= 0;p++) { + if (p->encoding == encoding) { + return(p); + } + } + return(0); +} + +/* + * convert encoding symbol to encoding char. + * if there's no valid encoding symbol, returns "" + */ +const char *pg_encoding_to_char(int encoding) +{ + pg_encoding_conv_tbl *p = pg_get_encent_by_encoding(encoding); + + if (!p) return(""); + return(p->name); +} + +/* returns the byte length of a multi-byte word for an encoding */ +int pg_encoding_mblen(int encoding, const unsigned char *mbstr) +{ + return((*pg_wchar_table[encoding].mblen)(mbstr)); +} -- cgit v1.2.3