diff options
author | NIIBE Yutaka <[email protected]> | 2020-04-03 06:30:08 +0000 |
---|---|---|
committer | NIIBE Yutaka <[email protected]> | 2020-04-03 06:30:08 +0000 |
commit | ba247a114c75a84473c11c1484013b09fbb9bcd1 (patch) | |
tree | a76cedce73621da0142ceb7d71ae51cad8696ec3 /regexp/utf8.h | |
parent | scd:p15: Implement do_with_keygrip and capabilities. (diff) | |
download | gnupg-ba247a114c75a84473c11c1484013b09fbb9bcd1.tar.gz gnupg-ba247a114c75a84473c11c1484013b09fbb9bcd1.zip |
gpg: Add regular expression support.
* AUTHORS, COPYING.other: Update.
* Makefile.am (SUBDIRS): Add regexp sub directory.
* configure.ac (DISABLE_REGEX): Remove.
* g10/Makefile.am (needed_libs): Add libregexp.a.
* g10/trustdb.c: Remove DISABLE_REGEX support.
* regexp/LICENSE, regexp/jimregexp.c, regexp/jimregexp.h,
regexp/utf8.c, regexp/utf8.h: New from Jim Tcl.
* regexp/UnicodeData.txt: New from Unicode.
* regexp/Makefile.am, regexp/parse-unidata.awk: New.
* tests/openpgp/Makefile.am: Remove DISABLE_REGEX support.
* tools/Makefile.am: Remove DISABLE_REGEX support.
GnuPG-bug-id: 4843
Signed-off-by: NIIBE Yutaka <[email protected]>
Diffstat (limited to 'regexp/utf8.h')
-rw-r--r-- | regexp/utf8.h | 90 |
1 files changed, 90 insertions, 0 deletions
diff --git a/regexp/utf8.h b/regexp/utf8.h new file mode 100644 index 000000000..7b62d5539 --- /dev/null +++ b/regexp/utf8.h @@ -0,0 +1,90 @@ +#ifndef UTF8_UTIL_H +#define UTF8_UTIL_H + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * UTF-8 utility functions + * + * (c) 2010-2016 Steve Bennett <[email protected]> + * + * See LICENCE for licence details. + */ + +/* Currently we support unicode points up to 2^22-1 */ +#define MAX_UTF8_LEN 4 + +/** + * Converts the given unicode codepoint (0 - 0x1fffff) to utf-8 + * and stores the result at 'p'. + * + * Returns the number of utf-8 characters (up to MAX_UTF8_LEN). + */ +int utf8_fromunicode(char *p, unsigned uc); + +#ifndef JIM_UTF8 +#include <ctype.h> + +/* No utf-8 support. 1 byte = 1 char */ +#define utf8_tounicode(S, CP) (*(CP) = (unsigned char)*(S), 1) +#define utf8_getchars(CP, C) (*(CP) = (C), 1) +#define utf8_upper(C) toupper(C) +#define utf8_index(C, I) (I) +#define utf8_charlen(C) 1 + +#else +#if !defined(JIM_BOOTSTRAP) + +#define utf8_getchars utf8_fromunicode + +/** + * Returns the length of the utf-8 sequence starting with 'c'. + * + * Returns 1-4. + * If 'c' is not a valid start byte, returns 1. + */ +int utf8_charlen(int c); + +/** + * Returns the byte index of the given character in the utf-8 string. + * + * The string *must* be null terminated. + * + * This will return the byte length of a utf-8 string + * if given the char length. + */ +int utf8_index(const char *str, int charindex); + +/** + * Returns the unicode codepoint corresponding to the + * utf-8 sequence 'str'. + * + * Stores the result in *uc and returns the number of bytes + * consumed. + * + * If 'str' is null terminated, then an invalid utf-8 sequence + * at the end of the string will be returned as individual bytes. + * + * If it is not null terminated, the length *must* be checked first. + * + * Does not support unicode code points > \u1fffff + */ +int utf8_tounicode(const char *str, int *uc); + +/** + * Returns the upper-case variant of the given unicode codepoint. + * + * Unicode code points > \uffff are returned unchanged. + */ +int utf8_upper(int uc); +#endif /* JIM_BOOTSTRAP */ + +#endif + +#ifdef __cplusplus +} +#endif + +#endif |