diff options
author | Joey Adams | 2011-03-28 16:04:32 +0000 |
---|---|---|
committer | Joey Adams | 2011-03-28 16:04:32 +0000 |
commit | 1722a516c355dcfab126a0db7073f50fd5515d0c (patch) | |
tree | 472b2b687a1c82b01f58a0d766a07bdf0d2ef90d | |
parent | 81e13ebeca3ff11154985eb29ace9e413ee0ca53 (diff) |
Updated compat.c/compat.h for utf8_to_unicode
-rw-r--r-- | Makefile | 2 | ||||
-rw-r--r-- | compat.c | 46 | ||||
-rw-r--r-- | compat.h | 12 | ||||
-rw-r--r-- | json.c | 1 | ||||
-rw-r--r-- | json_op.c | 1 |
5 files changed, 58 insertions, 4 deletions
@@ -1,5 +1,5 @@ MODULE_big = json -OBJS = json.o json_io.o json_op.o +OBJS = json.o json_io.o json_op.o compat.o DATA_built = json.sql DATA = uninstall_json.sql diff --git a/compat.c b/compat.c new file mode 100644 index 0000000..705b7b5 --- /dev/null +++ b/compat.c @@ -0,0 +1,46 @@ +/*------------------------------------------------------------------------- + * + * compat.c + * Compatibility routines to let the JSON module work in PostgreSQL 8.4 + * + * Copyright (c) 2011, PostgreSQL Global Development Group + * Arranged by Joey Adams <[email protected]>. + * + *------------------------------------------------------------------------- + */ + +#include "compat.h" + +#if PG_VERSION_NUM < 90100 + +/* + * Lifted from 9.1devel + * + * Convert a UTF-8 character to a Unicode code point. + * This is a one-character version of pg_utf2wchar_with_len. + * + * No error checks here, c must point to a long-enough string. + */ +pg_wchar +json_compat_utf8_to_unicode(const unsigned char *c) +{ + if ((*c & 0x80) == 0) + return (pg_wchar) c[0]; + else if ((*c & 0xe0) == 0xc0) + return (pg_wchar) (((c[0] & 0x1f) << 6) | + (c[1] & 0x3f)); + else if ((*c & 0xf0) == 0xe0) + return (pg_wchar) (((c[0] & 0x0f) << 12) | + ((c[1] & 0x3f) << 6) | + (c[2] & 0x3f)); + else if ((*c & 0xf8) == 0xf0) + return (pg_wchar) (((c[0] & 0x07) << 18) | + ((c[1] & 0x3f) << 12) | + ((c[2] & 0x3f) << 6) | + (c[3] & 0x3f)); + else + /* that is an invalid code on purpose */ + return 0xffffffff; +} + +#endif @@ -12,11 +12,17 @@ #ifndef JSON_COMPAT_H #define JSON_COMPAT_H -/*** 8.4.3 ***/ +#include "postgres.h" +#include "mb/pg_wchar.h" #ifndef SearchSysCacheList1 - #define SearchSysCacheList1(cacheId, key1) \ - SearchSysCacheList(cacheId, 1, key1, 0, 0, 0) +#define SearchSysCacheList1(cacheId, key1) \ + SearchSysCacheList(cacheId, 1, key1, 0, 0, 0) +#endif + +#if PG_VERSION_NUM < 90100 +#define utf8_to_unicode json_compat_utf8_to_unicode +extern pg_wchar json_compat_utf8_to_unicode(const unsigned char *c); #endif #endif @@ -10,6 +10,7 @@ */ #include "json.h" +#include "compat.h" #define is_space(c) ((c) == '\t' || (c) == '\n' || (c) == '\r' || (c) == ' ') #define is_digit(c) ((c) >= '0' && (c) <= '9') @@ -10,6 +10,7 @@ */ #include "json.h" +#include "compat.h" #include "catalog/namespace.h" #include "catalog/pg_enum.h" |