2016-07-20 08:53:00 -04:00
|
|
|
#!/bin/python
|
|
|
|
|
2016-07-21 05:35:16 -04:00
|
|
|
def getPrevWord(currX,currY, currText):
|
|
|
|
if currText == '':
|
|
|
|
return -1, -1, ''
|
|
|
|
x, y, word = getCurrentWord(currX,currY,currText)
|
|
|
|
if (x == currX) or (y == currY) and (word == ''):
|
|
|
|
return currX, currY, ''
|
|
|
|
return getCurrentWord(x - 2, y, currText)
|
|
|
|
|
2016-07-20 10:03:22 -04:00
|
|
|
def getCurrentWord(currX,currY, currText):
|
2016-07-20 09:25:28 -04:00
|
|
|
if currText == '':
|
|
|
|
return -1, -1, ''
|
2016-07-20 10:11:05 -04:00
|
|
|
x = currX
|
|
|
|
y = currY
|
|
|
|
wrappedLines = currText.split('\n')
|
2016-07-20 08:53:00 -04:00
|
|
|
wordFound = False
|
|
|
|
currWord = ''
|
2016-07-21 06:53:50 -04:00
|
|
|
if x < 0:
|
2016-07-21 05:35:16 -04:00
|
|
|
if y != 0:
|
|
|
|
y -= 1
|
|
|
|
currLine = wrappedLines[y].replace("\t"," ")
|
|
|
|
else:
|
|
|
|
return currX, currY, ''
|
|
|
|
x = len(currLine) - 1
|
|
|
|
else:
|
|
|
|
currLine = wrappedLines[y].replace("\t"," ")
|
2016-07-20 08:53:00 -04:00
|
|
|
while not wordFound:
|
|
|
|
x = currLine[:x].rfind(" ")
|
|
|
|
if x == -1:
|
|
|
|
x = 0
|
|
|
|
else:
|
|
|
|
x += 1
|
2016-07-21 06:53:50 -04:00
|
|
|
wordEnd = currLine[x + 2:].find(" ")
|
2016-07-20 08:53:00 -04:00
|
|
|
if wordEnd == -1:
|
2016-07-21 06:53:50 -04:00
|
|
|
wordEnd = len(currLine[x:])
|
2016-07-20 08:53:00 -04:00
|
|
|
else:
|
|
|
|
wordEnd += x + 1
|
|
|
|
currWord = currLine[x:wordEnd]
|
|
|
|
wordFound = currWord.strip(" \t\n") != ''
|
2016-07-21 06:53:50 -04:00
|
|
|
print(currWord)
|
2016-07-20 08:53:00 -04:00
|
|
|
if wordFound:
|
|
|
|
break
|
2016-07-21 06:53:50 -04:00
|
|
|
print(currWord)
|
2016-07-20 08:53:00 -04:00
|
|
|
if x == 0:
|
|
|
|
if y != 0:
|
|
|
|
y -= 1
|
|
|
|
currLine = wrappedLines[y].replace("\t"," ")
|
|
|
|
else:
|
2016-07-20 10:03:22 -04:00
|
|
|
return currX, currY, ''
|
2016-07-21 05:35:16 -04:00
|
|
|
x = len(currLine) - 1
|
2016-07-20 08:53:00 -04:00
|
|
|
else:
|
|
|
|
x -= 1
|
2016-07-21 06:53:50 -04:00
|
|
|
print(currWord)
|
2016-07-20 10:11:05 -04:00
|
|
|
return x, y, currWord
|