|
8 | 8 | *
|
9 | 9 | *
|
10 | 10 | * IDENTIFICATION
|
11 |
| - * $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-connect.c,v 1.142 2000/10/23 14:50:44 momjian Exp $ |
| 11 | + * $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-connect.c,v 1.143 2000/10/30 10:31:46 ishii Exp $ |
12 | 12 | *
|
13 | 13 | *-------------------------------------------------------------------------
|
14 | 14 | */
|
@@ -2694,3 +2694,70 @@ defaultNoticeProcessor(void *arg, const char *message)
|
2694 | 2694 | /* Note: we expect the supplied string to end with a newline already. */
|
2695 | 2695 | fprintf(stderr, "%s", message);
|
2696 | 2696 | }
|
| 2697 | + |
| 2698 | +#ifdef MULTIBYTE |
| 2699 | +/* |
| 2700 | + * convert an encoding string to encoding symbol value. |
| 2701 | + * case is ignored. |
| 2702 | + * if there's no valid encoding, returns -1 |
| 2703 | + */ |
| 2704 | + |
| 2705 | +typedef struct { |
| 2706 | + int encoding; /* encoding symbol value */ |
| 2707 | + char *name; /* encoding string */ |
| 2708 | +} PQ_encoding_conv_tbl; |
| 2709 | + |
| 2710 | +static PQ_encoding_conv_tbl pq_conv_tbl[] = { |
| 2711 | + {SQL_ASCII, "SQL_ASCII"}, |
| 2712 | + {EUC_JP, "EUC_JP"}, |
| 2713 | + {EUC_CN, "EUC_CN"}, |
| 2714 | + {EUC_KR, "EUC_KR"}, |
| 2715 | + {UNICODE, "UNICODE"}, |
| 2716 | + {MULE_INTERNAL, "MULE_INTERNAL"}, |
| 2717 | + {LATIN1, "LATIN1"}, |
| 2718 | + {LATIN2, "LATIN2"}, |
| 2719 | + {LATIN3, "LATIN3"}, |
| 2720 | + {LATIN4, "LATIN4"}, |
| 2721 | + {LATIN5, "LATIN5"}, |
| 2722 | + {KOI8, "KOI8"}, |
| 2723 | + {WIN, "WIN"}, |
| 2724 | + {ALT, "ALT"}, |
| 2725 | + {SJIS, "SJIS"}, |
| 2726 | + {BIG5, "BIG5"}, |
| 2727 | + {WIN1250, "WIN1250"}, |
| 2728 | + {-1, ""} |
| 2729 | +}; |
| 2730 | + |
| 2731 | +int |
| 2732 | +pg_char_to_encoding(const char *s) |
| 2733 | +{ |
| 2734 | + PQ_encoding_conv_tbl *p = pq_conv_tbl; |
| 2735 | + |
| 2736 | + if (!s) |
| 2737 | + return (-1); |
| 2738 | + |
| 2739 | + for (; p->encoding >= 0; p++) |
| 2740 | + { |
| 2741 | + if (!strcasecmp(s, p->name)) |
| 2742 | + break; |
| 2743 | + } |
| 2744 | + return (p->encoding); |
| 2745 | +} |
| 2746 | + |
| 2747 | +/* |
| 2748 | + * convert encoding symbol to encoding char. |
| 2749 | + * if there's no valid encoding symbol, returns "" |
| 2750 | + */ |
| 2751 | +const char * |
| 2752 | +pg_encoding_to_char(int encoding) |
| 2753 | +{ |
| 2754 | + PQ_encoding_conv_tbl *p = pq_conv_tbl; |
| 2755 | + |
| 2756 | + for (; p->encoding >= 0; p++) |
| 2757 | + { |
| 2758 | + if (p->encoding == encoding) |
| 2759 | + return (p->name); |
| 2760 | + } |
| 2761 | + return (""); |
| 2762 | +} |
| 2763 | +#endif |
0 commit comments