From 207e327413a9e9a4cc0c87bb5c51e68417c6dc2d Mon Sep 17 00:00:00 2001 From: chrys87 Date: Wed, 20 Jul 2016 14:53:00 +0200 Subject: [PATCH] Create word_utils.py --- src/fenrir-package/utils/word_utils.py | 31 ++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 src/fenrir-package/utils/word_utils.py diff --git a/src/fenrir-package/utils/word_utils.py b/src/fenrir-package/utils/word_utils.py new file mode 100644 index 00000000..0c8e28ff --- /dev/null +++ b/src/fenrir-package/utils/word_utils.py @@ -0,0 +1,31 @@ +#!/bin/python + +def getCurrentWord(x,y, currText): + wordFound = False + currWord = '' + currLine = wrappedLines[y].replace("\t"," ") + while not wordFound: + x = currLine[:x].rfind(" ") + if x == -1: + x = 0 + else: + x += 1 + wordEnd = currLine[x + 1:].find(" ") + if wordEnd == -1: + wordEnd = len(currLine) + else: + wordEnd += x + 1 + currWord = currLine[x:wordEnd] + wordFound = currWord.strip(" \t\n") != '' + if wordFound: + break + if x == 0: + if y != 0: + y -= 1 + currLine = wrappedLines[y].replace("\t"," ") + else: + break + x = len(wrappedLines[y]) - 1 + else: + x -= 1 + return x, y, currWord