This repository has been archived by the owner on Nov 9, 2017. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
test.c
70 lines (63 loc) · 1.69 KB
/
test.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/*
* Copyright © 2009 Jakub Wilk <jwilk@jwilk.net>
*
* This library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of the
* License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*/
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include "regex.h"
#define C1 "a"
#define C2 "\xce\xb1" /* GREEK SMALL LETTER ALPHA */
#define C3 "\xe0\xa4\x85" /* DEVANAGARI LETTER A */
#if WCHAR_MAX >= 0x10ffff
#define C4 "\xf4\x80\x80\x80" /* Plane 15 Private Use, First */
#else
#define C4 "\xef\xbc\xa1" /* FULLWIDTH LATIN CAPITAL LETTER A */
#endif
int test_utf8()
{
int rc;
regex_t preg;
const char *string = C1 C2 C3 C4;
const char *regex = "^" C1 "[" C2 "][" C3 "][" C4 "]$";
rc = regcomp(&preg, regex, REG_EXTENDED | REG_NOSUB);
/* A match is expected for UTF-8 encoding *only*. */
if (rc != 0)
{
errno = (rc == REG_ESPACE) ? ENOMEM : EINVAL;
return -1;
}
rc = regexec(&preg, string, 0, NULL, 0);
regfree(&preg);
if (rc != 0)
{
errno = EILSEQ;
return 1;
}
return 0;
}
#undef C1
#undef C2
#undef C3
#undef C4
int main(int argc, char **argv)
{
#if WCHAR_MAX < 0x10ffff
fprintf(stderr, "Warning: this system does not support the full Unicode range.\n");
#endif
int x = test_utf8();
if (x != 0)
perror(NULL);
return x;
}
/* vim:set ts=2 sts=2 sw=2 et: */