mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Function to get available locales for break iteration
This commit is contained in:
parent
f138d716a5
commit
53b8bed17a
@ -73,6 +73,7 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "sqlite_extension",
|
"name": "sqlite_extension",
|
||||||
|
"headers": "calibre/utils/cpp_binding.h",
|
||||||
"sources": "calibre/db/sqlite_extension.cpp",
|
"sources": "calibre/db/sqlite_extension.cpp",
|
||||||
"needs_c++11": true,
|
"needs_c++11": true,
|
||||||
"libraries": "icudata icui18n icuuc icuio",
|
"libraries": "icudata icui18n icuuc icuio",
|
||||||
|
@ -250,6 +250,7 @@ class ExtensionsImporter:
|
|||||||
'matcher',
|
'matcher',
|
||||||
'tokenizer',
|
'tokenizer',
|
||||||
'certgen',
|
'certgen',
|
||||||
|
'sqlite_extension',
|
||||||
)
|
)
|
||||||
if iswindows:
|
if iswindows:
|
||||||
extra = ('winutil', 'wpd', 'winfonts', 'winsapi')
|
extra = ('winutil', 'wpd', 'winfonts', 'winsapi')
|
||||||
|
@ -16,6 +16,8 @@
|
|||||||
#include <unicode/uchar.h>
|
#include <unicode/uchar.h>
|
||||||
#include <unicode/translit.h>
|
#include <unicode/translit.h>
|
||||||
#include <unicode/errorcode.h>
|
#include <unicode/errorcode.h>
|
||||||
|
#include <unicode/brkiter.h>
|
||||||
|
#include "../utils/cpp_binding.h"
|
||||||
SQLITE_EXTENSION_INIT1
|
SQLITE_EXTENSION_INIT1
|
||||||
|
|
||||||
typedef int (*token_callback_func)(void *, int, const char *, int, int, int);
|
typedef int (*token_callback_func)(void *, int, const char *, int, int, int);
|
||||||
@ -250,8 +252,31 @@ calibre_sqlite_extension_init(sqlite3 *db, char **pzErrMsg, const sqlite3_api_ro
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static PyObject*
|
||||||
|
get_locales_for_break_iteration(PyObject *self, PyObject *args) {
|
||||||
|
std::unique_ptr<icu::StringEnumeration> locs(icu::BreakIterator::getAvailableLocales());
|
||||||
|
icu::ErrorCode status;
|
||||||
|
pyobject_raii ans(PyList_New(0));
|
||||||
|
if (ans) {
|
||||||
|
const icu::UnicodeString *item;
|
||||||
|
while ((item = locs->snext(status))) {
|
||||||
|
std::string name;
|
||||||
|
item->toUTF8String(name);
|
||||||
|
pyobject_raii pn(PyUnicode_FromString(name.c_str()));
|
||||||
|
if (pn) PyList_Append(ans.ptr(), pn.ptr());
|
||||||
|
}
|
||||||
|
if (status.isFailure()) {
|
||||||
|
PyErr_Format(PyExc_RuntimeError, "Failed to iterate over locales with error: %s", status.errorName());
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ans.detach();
|
||||||
|
}
|
||||||
|
|
||||||
static PyMethodDef methods[] = {
|
static PyMethodDef methods[] = {
|
||||||
|
{"get_locales_for_break_iteration", get_locales_for_break_iteration, METH_NOARGS,
|
||||||
|
"Get list of available locales for break iteration"
|
||||||
|
},
|
||||||
{NULL, NULL, 0, NULL}
|
{NULL, NULL, 0, NULL}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user