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(
78 code, UCHAR_ALPHABETIC);
79 bool icu_prop_lowercase = u_hasBinaryProperty(
80 code, UCHAR_LOWERCASE);
81 bool icu_prop_uppercase = u_hasBinaryProperty(
82 code, UCHAR_UPPERCASE);
83 bool icu_prop_cased = u_hasBinaryProperty(
85 bool icu_prop_case_ignorable = u_hasBinaryProperty(
86 code, UCHAR_CASE_IGNORABLE);
87 bool icu_prop_white_space = u_hasBinaryProperty(
88 code, UCHAR_WHITE_SPACE);
89 bool icu_prop_hex_digit = u_hasBinaryProperty(
90 code, UCHAR_HEX_DIGIT);
91 bool icu_prop_join_control = u_hasBinaryProperty(
92 code, UCHAR_JOIN_CONTROL);
119 bool icu_isalpha = u_isUAlphabetic(code);
120 bool icu_islower = u_isULowercase(code);
121 bool icu_isupper = u_isUUppercase(code);
122 bool icu_ispunct = u_ispunct(code);
123 bool icu_isdigit = u_isdigit(code);
124 bool icu_isxdigit = u_hasBinaryProperty(code,
126 bool icu_isalnum = u_hasBinaryProperty(code,
128 bool icu_isspace = u_isUWhiteSpace(code);
129 bool icu_isblank = u_isblank(code);
131 bool icu_isgraph = u_hasBinaryProperty(code,
133 bool icu_isprint = u_hasBinaryProperty(code,
146 pg_skipped_codepoints++;
154 icu_skipped_codepoints++;
158 if (pg_category != icu_category)
160 printf(
"category_test: FAILURE for codepoint 0x%06x\n", code);
161 printf(
"category_test: Postgres category: %02d %s %s\n", pg_category,
164 printf(
"category_test: ICU category: %02d %s %s\n", icu_category,
171 if (prop_alphabetic != icu_prop_alphabetic ||
172 prop_lowercase != icu_prop_lowercase ||
173 prop_uppercase != icu_prop_uppercase ||
174 prop_cased != icu_prop_cased ||
175 prop_case_ignorable != icu_prop_case_ignorable ||
176 prop_white_space != icu_prop_white_space ||
177 prop_hex_digit != icu_prop_hex_digit ||
178 prop_join_control != icu_prop_join_control)
180 printf(
"category_test: FAILURE for codepoint 0x%06x\n", code);
181 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",
182 prop_alphabetic, prop_lowercase, prop_uppercase,
183 prop_cased, prop_case_ignorable,
184 prop_white_space, prop_hex_digit, prop_join_control);
185 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",
186 icu_prop_alphabetic, icu_prop_lowercase, icu_prop_uppercase,
187 icu_prop_cased, icu_prop_case_ignorable,
188 icu_prop_white_space, icu_prop_hex_digit, icu_prop_join_control);
193 if (isalpha != icu_isalpha ||
194 islower != icu_islower ||
195 isupper != icu_isupper ||
196 ispunct != icu_ispunct ||
197 isdigit != icu_isdigit ||
198 isxdigit != icu_isxdigit ||
199 isalnum != icu_isalnum ||
200 isspace != icu_isspace ||
201 isblank != icu_isblank ||
202 iscntrl != icu_iscntrl ||
203 isgraph != icu_isgraph ||
204 isprint != icu_isprint)
206 printf(
"category_test: FAILURE for codepoint 0x%06x\n", code);
207 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",
208 isalpha, islower, isupper, ispunct, isdigit, isxdigit, isalnum, isspace, isblank, iscntrl, isgraph, isprint);
209 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",
210 icu_isalpha, icu_islower, icu_isupper, icu_ispunct, icu_isdigit, icu_isxdigit, icu_isalnum, icu_isspace, icu_isblank, icu_iscntrl, icu_isgraph, icu_isprint);
219 if (pg_skipped_codepoints > 0)
220 printf(
"category_test: skipped %d codepoints unassigned in Postgres due to Unicode version mismatch\n",
221 pg_skipped_codepoints);
222 if (icu_skipped_codepoints > 0)
223 printf(
"category_test: skipped %d codepoints unassigned in ICU due to Unicode version mismatch\n",
224 icu_skipped_codepoints);
226 printf(
"category_test: ICU test: %d codepoints successful\n", successful);
238 printf(
"category_test: ICU Unicode version:\t\t%s\n", U_UNICODE_VERSION);
242 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)
bool pg_u_isprint(pg_wchar code)
const char * unicode_category_string(pg_unicode_category category)
bool pg_u_islower(pg_wchar code)
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)
const char * unicode_category_abbrev(pg_unicode_category category)
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)