mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-07 10:14:46 -04:00
Merge branch 'py3-unicode_names' of https://github.com/flaviut/calibre
This commit is contained in:
commit
1f980f7097
@ -31,6 +31,7 @@ def html_entities():
|
|||||||
|
|
||||||
|
|
||||||
def points_for_word(w):
|
def points_for_word(w):
|
||||||
|
"""Returns the set of all codepoints that contain ``word`` in their names"""
|
||||||
w = w.lower()
|
w = w.lower()
|
||||||
ans = points_for_word.cache.get(w)
|
ans = points_for_word.cache.get(w)
|
||||||
if ans is None:
|
if ans is None:
|
||||||
|
@ -7,18 +7,6 @@
|
|||||||
|
|
||||||
#include "names.h"
|
#include "names.h"
|
||||||
|
|
||||||
static PyObject*
|
|
||||||
all_words(PYNOARG) {
|
|
||||||
PyObject *ans = PyTuple_New(arraysz(all_words_map));
|
|
||||||
if (!ans) return NULL;
|
|
||||||
for (size_t i = 0; i < arraysz(all_words_map); i++) {
|
|
||||||
PyObject *w = PyUnicode_FromString(all_words_map[i]);
|
|
||||||
if (w == NULL) { Py_DECREF(ans); return NULL; }
|
|
||||||
PyTuple_SET_ITEM(ans, i, w);
|
|
||||||
}
|
|
||||||
return ans;
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline void
|
static inline void
|
||||||
add_matches(const word_trie *wt, char_type *codepoints, size_t *pos, const size_t sz) {
|
add_matches(const word_trie *wt, char_type *codepoints, size_t *pos, const size_t sz) {
|
||||||
size_t num = mark_groups[wt->match_offset];
|
size_t num = mark_groups[wt->match_offset];
|
||||||
@ -84,38 +72,39 @@ nfc(PyObject *self UNUSED, PyObject *args) {
|
|||||||
return PyUnicode_FromString(n);
|
return PyUnicode_FromString(n);
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyMethodDef module_methods[] = {
|
static PyMethodDef unicode_names_methods[] = {
|
||||||
{"all_words", (PyCFunction)all_words, METH_NOARGS, ""},
|
{"codepoints_for_word", (PyCFunction)cfw, METH_VARARGS,
|
||||||
{"codepoints_for_word", (PyCFunction)cfw, METH_VARARGS, ""},
|
"Return a set of integer codepoints for where each codepoint's name "
|
||||||
{"name_for_codepoint", (PyCFunction)nfc, METH_VARARGS, ""},
|
"contains ``word``,"},
|
||||||
|
{"name_for_codepoint", (PyCFunction)nfc, METH_VARARGS,
|
||||||
|
"Returns the given codepoint's name"},
|
||||||
{NULL, NULL, 0, NULL} /* Sentinel */
|
{NULL, NULL, 0, NULL} /* Sentinel */
|
||||||
};
|
};
|
||||||
|
|
||||||
#if PY_VERSION_HEX >= 0x03000000
|
#if PY_MAJOR_VERSION >= 3
|
||||||
static struct PyModuleDef module = {
|
#define INITERROR return NULL
|
||||||
.m_base = PyModuleDef_HEAD_INIT,
|
static struct PyModuleDef unicode_names_module = {
|
||||||
.m_name = "unicode_names", /* name of module */
|
/* m_base */ PyModuleDef_HEAD_INIT,
|
||||||
.m_doc = NULL,
|
/* m_name */ "unicode_names",
|
||||||
.m_size = -1,
|
/* m_doc */ "A library to assist with selecting special characters",
|
||||||
.m_methods = module_methods
|
/* m_size */ -1,
|
||||||
|
/* m_methods */ unicode_names_methods,
|
||||||
|
/* m_slots */ 0,
|
||||||
|
/* m_traverse */ 0,
|
||||||
|
/* m_clear */ 0,
|
||||||
|
/* m_free */ 0,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
CALIBRE_MODINIT_FUNC PyInit_unicode_names(void) {
|
||||||
EXPORTED PyMODINIT_FUNC
|
|
||||||
PyInit_unicode_names(void) {
|
|
||||||
PyObject *m;
|
|
||||||
|
|
||||||
m = PyModule_Create(&module);
|
|
||||||
if (m == NULL) return NULL;
|
|
||||||
return m;
|
|
||||||
}
|
|
||||||
#else
|
#else
|
||||||
EXPORTED
|
#define INITERROR return
|
||||||
initunicode_names(void) {
|
CALIBRE_MODINIT_FUNC initunicode_names(void) {
|
||||||
PyObject *m;
|
|
||||||
m = Py_InitModule3("unicode_names", module_methods,
|
|
||||||
""
|
|
||||||
);
|
|
||||||
if (m == NULL) return;
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
// Create the module
|
||||||
|
#if PY_MAJOR_VERSION >= 3
|
||||||
|
PyObject *mod = PyModule_Create(&unicode_names_module);
|
||||||
|
return mod;
|
||||||
|
#else
|
||||||
|
Py_InitModule3("unicode_names", unicode_names_methods, "");
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user