20#include <unicode/uchar.h>
41 n = sscanf(version,
"%d.%d", &major, &minor);
46 return major * 100 + minor;
59 int pg_skipped_codepoints = 0;
60 int icu_skipped_codepoints = 0;
62 for (
pg_wchar code = 0; code <= 0x10ffff; code++)
65 uint8_t icu_category = u_charType(code);
77 bool icu_prop_alphabetic = u_hasBinaryProperty(code, UCHAR_ALPHABETIC);
78 bool icu_prop_lowercase = u_hasBinaryProperty(code, UCHAR_LOWERCASE);
79 bool icu_prop_uppercase = u_hasBinaryProperty(code, UCHAR_UPPERCASE);
80 bool icu_prop_cased = u_hasBinaryProperty(code, UCHAR_CASED);
81 bool icu_prop_case_ignorable = u_hasBinaryProperty(code, UCHAR_CASE_IGNORABLE);
82 bool icu_prop_white_space = u_hasBinaryProperty(code, UCHAR_WHITE_SPACE);
83 bool icu_prop_hex_digit = u_hasBinaryProperty(code, UCHAR_HEX_DIGIT);
84 bool icu_prop_join_control = u_hasBinaryProperty(code, UCHAR_JOIN_CONTROL);
111 bool icu_isalpha = u_isUAlphabetic(code);
112 bool icu_islower = u_isULowercase(code);
113 bool icu_isupper = u_isUUppercase(code);
114 bool icu_ispunct = u_ispunct(code);
115 bool icu_isdigit = u_isdigit(code);
116 bool icu_isxdigit = u_hasBinaryProperty(code,
118 bool icu_isalnum = u_hasBinaryProperty(code,
120 bool icu_isspace = u_isUWhiteSpace(code);
121 bool icu_isblank = u_isblank(code);
123 bool icu_isgraph = u_hasBinaryProperty(code,
125 bool icu_isprint = u_hasBinaryProperty(code,
138 pg_skipped_codepoints++;
146 icu_skipped_codepoints++;
150 if (pg_category != icu_category)
152 printf(
"category_test: FAILURE for codepoint 0x%06x\n", code);
153 printf(
"category_test: Postgres category: %02d %s %s\n", pg_category,
156 printf(
"category_test: ICU category: %02d %s %s\n", icu_category,
163 if (prop_alphabetic != icu_prop_alphabetic ||
164 prop_lowercase != icu_prop_lowercase ||
165 prop_uppercase != icu_prop_uppercase ||
166 prop_cased != icu_prop_cased ||
167 prop_case_ignorable != icu_prop_case_ignorable ||
168 prop_white_space != icu_prop_white_space ||
169 prop_hex_digit != icu_prop_hex_digit ||
170 prop_join_control != icu_prop_join_control)
172 printf(
"category_test: FAILURE for codepoint 0x%06x\n", code);
173 printf(
"category_test: Postgres property alphabetic/lowercase/uppercase/cased/case_ignorable/white_space/hex_digit/join_control: %d/%d/%d/%d/%d/%d/%d/%d\n",
174 prop_alphabetic, prop_lowercase, prop_uppercase,
175 prop_cased, prop_case_ignorable,
176 prop_white_space, prop_hex_digit, prop_join_control);
177 printf(
"category_test: ICU property alphabetic/lowercase/uppercase/cased/case_ignorable/white_space/hex_digit/join_control: %d/%d/%d/%d/%d/%d/%d/%d\n",
178 icu_prop_alphabetic, icu_prop_lowercase, icu_prop_uppercase,
179 icu_prop_cased, icu_prop_case_ignorable,
180 icu_prop_white_space, icu_prop_hex_digit, icu_prop_join_control);
185 if (isalpha != icu_isalpha ||
186 islower != icu_islower ||
187 isupper != icu_isupper ||
188 ispunct != icu_ispunct ||
189 isdigit != icu_isdigit ||
190 isxdigit != icu_isxdigit ||
191 isalnum != icu_isalnum ||
192 isspace != icu_isspace ||
193 isblank != icu_isblank ||
194 iscntrl != icu_iscntrl ||
195 isgraph != icu_isgraph ||
196 isprint != icu_isprint)
198 printf(
"category_test: FAILURE for codepoint 0x%06x\n", code);
199 printf(
"category_test: Postgres class alpha/lower/upper/punct/digit/xdigit/alnum/space/blank/cntrl/graph/print: %d/%d/%d/%d/%d/%d/%d/%d/%d/%d/%d/%d\n",
200 isalpha, islower, isupper, ispunct, isdigit, isxdigit, isalnum, isspace, isblank, iscntrl, isgraph, isprint);
201 printf(
"category_test: ICU class alpha/lower/upper/punct/digit/xdigit/alnum/space/blank/cntrl/graph/print: %d/%d/%d/%d/%d/%d/%d/%d/%d/%d/%d/%d\n",
202 icu_isalpha, icu_islower, icu_isupper, icu_ispunct, icu_isdigit, icu_isxdigit, icu_isalnum, icu_isspace, icu_isblank, icu_iscntrl, icu_isgraph, icu_isprint);
211 if (pg_skipped_codepoints > 0)
212 printf(
"category_test: skipped %d codepoints unassigned in Postgres due to Unicode version mismatch\n",
213 pg_skipped_codepoints);
214 if (icu_skipped_codepoints > 0)
215 printf(
"category_test: skipped %d codepoints unassigned in ICU due to Unicode version mismatch\n",
216 icu_skipped_codepoints);
218 printf(
"category_test: ICU test: %d codepoints successful\n", successful);
230 printf(
"category_test: ICU Unicode version:\t\t%s\n", U_UNICODE_VERSION);
234 printf(
"category_test: ICU not available; skipping\n");
#define PG_USED_FOR_ASSERTS_ONLY
#define Assert(condition)
static int pg_unicode_version
int main(int argc, char **argv)
static int parse_unicode_version(const char *version)
bool pg_u_prop_uppercase(pg_wchar code)
bool pg_u_isspace(pg_wchar code)
bool pg_u_isxdigit(pg_wchar code, bool posix)
bool pg_u_ispunct(pg_wchar code, bool posix)
const char * unicode_category_string(pg_unicode_category category)
bool pg_u_isprint(pg_wchar code)
bool pg_u_islower(pg_wchar code)
const char * unicode_category_abbrev(pg_unicode_category category)
bool pg_u_prop_white_space(pg_wchar code)
bool pg_u_isblank(pg_wchar code)
bool pg_u_prop_cased(pg_wchar code)
bool pg_u_isalpha(pg_wchar code)
bool pg_u_prop_lowercase(pg_wchar code)
bool pg_u_isalnum(pg_wchar code, bool posix)
bool pg_u_isupper(pg_wchar code)
bool pg_u_prop_alphabetic(pg_wchar code)
bool pg_u_isdigit(pg_wchar code, bool posix)
bool pg_u_iscntrl(pg_wchar code)
bool pg_u_prop_join_control(pg_wchar code)
bool pg_u_isgraph(pg_wchar code)
bool pg_u_prop_case_ignorable(pg_wchar code)
bool pg_u_prop_hex_digit(pg_wchar code)
pg_unicode_category unicode_category(pg_wchar code)
#define PG_UNICODE_VERSION
Datum icu_unicode_version(PG_FUNCTION_ARGS)