mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-08 02:34:06 -04:00
Add a count_words() function to the break iterator
This commit is contained in:
parent
780625e18e
commit
e5b741c7ea
@ -39,3 +39,10 @@ def index_of(needle, haystack, lang='en'):
|
|||||||
it.set_text(haystack)
|
it.set_text(haystack)
|
||||||
return it.index(needle)
|
return it.index(needle)
|
||||||
|
|
||||||
|
def count_words(text, lang='en'):
|
||||||
|
with _lock:
|
||||||
|
it = _iterators.get(lang, None)
|
||||||
|
if it is None:
|
||||||
|
it = _iterators[lang] = _icu.BreakIterator(_icu.UBRK_WORD, lang_as_iso639_1(lang) or lang)
|
||||||
|
it.set_text(text)
|
||||||
|
return len(it.split2())
|
||||||
|
Loading…
x
Reference in New Issue
Block a user