Mercurial > hg
comparison mercurial/cext/charencode.h @ 33758:0f4ac3b6dee4
cext: factor out header for charencode.c
This merges a part of util.h with the header which should exist for
charencode.c.
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Sun, 21 May 2017 14:23:22 +0900 |
parents | mercurial/cext/util.h@5866ba5e9c48 |
children | a22339d389d4 |
comparison
equal
deleted
inserted
replaced
33757:e9996bd7203f | 33758:0f4ac3b6dee4 |
---|---|
1 /* | |
2 charencode.h - miscellaneous character encoding | |
3 | |
4 This software may be used and distributed according to the terms of | |
5 the GNU General Public License, incorporated herein by reference. | |
6 */ | |
7 | |
8 #ifndef _HG_CHARENCODE_H_ | |
9 #define _HG_CHARENCODE_H_ | |
10 | |
11 #include <Python.h> | |
12 #include "compat.h" | |
13 | |
14 /* This should be kept in sync with normcasespecs in encoding.py. */ | |
15 enum normcase_spec { | |
16 NORMCASE_LOWER = -1, | |
17 NORMCASE_UPPER = 1, | |
18 NORMCASE_OTHER = 0 | |
19 }; | |
20 | |
21 PyObject *unhexlify(const char *str, int len); | |
22 PyObject *asciilower(PyObject *self, PyObject *args); | |
23 PyObject *asciiupper(PyObject *self, PyObject *args); | |
24 PyObject *make_file_foldmap(PyObject *self, PyObject *args); | |
25 | |
26 static const int8_t hextable[256] = { | |
27 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, | |
28 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, | |
29 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, | |
30 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, -1, -1, -1, -1, -1, -1, /* 0-9 */ | |
31 -1, 10, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* A-F */ | |
32 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, | |
33 -1, 10, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* a-f */ | |
34 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, | |
35 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, | |
36 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, | |
37 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, | |
38 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, | |
39 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, | |
40 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, | |
41 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, | |
42 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 | |
43 }; | |
44 | |
45 static inline int hexdigit(const char *p, Py_ssize_t off) | |
46 { | |
47 int8_t val = hextable[(unsigned char)p[off]]; | |
48 | |
49 if (val >= 0) { | |
50 return val; | |
51 } | |
52 | |
53 PyErr_SetString(PyExc_ValueError, "input contains non-hex character"); | |
54 return 0; | |
55 } | |
56 | |
57 #endif /* _HG_CHARENCODE_H_ */ |