From 34a9f36534a907ee52e1a387abe8d4385219a2df Mon Sep 17 00:00:00 2001 From: Ole Laursen Date: Mon, 16 Jan 2017 11:35:48 +0000 Subject: [PATCH] Add helper for getting word count from draft - Legacy-Id: 12655 --- ietf/utils/draft.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/ietf/utils/draft.py b/ietf/utils/draft.py index 896e15a7b..a6cde5a99 100755 --- a/ietf/utils/draft.py +++ b/ietf/utils/draft.py @@ -292,6 +292,15 @@ class Draft(): self._pagecount = count_pages return self._pagecount + # ------------------------------------------------------------------ + def get_wordcount(self): + count = 0 + # match any sequence of non-white-space characters like the Unix command "wc" + word_re = re.compile(r'\S+', re.UNICODE) + for l in self.lines: + count += sum(1 for _ in word_re.finditer(l)) + return count + # ---------------------------------------------------------------------- def get_status(self): if self._status == None: