2016-08-23 11:12:51 -04:00
|
|
|
#!/bin/python
|
|
|
|
|
2016-08-23 11:38:13 -04:00
|
|
|
def getTextBetweenMarks(firstMark, secondMark, inText):
|
2016-08-23 11:14:15 -04:00
|
|
|
if firstMark == None:
|
|
|
|
return ''
|
|
|
|
if secondMark == None:
|
|
|
|
return ''
|
2016-08-23 11:12:51 -04:00
|
|
|
if (firstMark['y'] + 1) * (firstMark['x'] + 1) <= (secondMark['y'] + 1) * (secondMark['x'] + 1):
|
|
|
|
startMark = firstMark.copy()
|
|
|
|
endMark = secondMark.copy()
|
|
|
|
else:
|
|
|
|
endMark = firstMark.copy()
|
|
|
|
startMark = secondMark.copy()
|
|
|
|
startX = startMark['x']
|
|
|
|
startY = startMark['y']
|
|
|
|
textPart = ''
|
|
|
|
while startY <= endMark['y']:
|
2016-08-23 18:41:16 -04:00
|
|
|
if startMark['y'] == endMark['y']:
|
|
|
|
textPart += inText[startY][startX:endMark['x'] + 1]
|
2016-08-23 11:12:51 -04:00
|
|
|
else:
|
2016-08-23 18:41:16 -04:00
|
|
|
if startY < endMark['y']:
|
|
|
|
textPart += inText[startY][startX:]
|
|
|
|
if len(textPart) - len(textPart[::-1].strip()) > 0:
|
|
|
|
textPart = textPart[:len(textPart[::-1].strip())] + "\n"
|
|
|
|
else:
|
|
|
|
textPart += inText[startY][:startX + 1]
|
2016-08-23 11:12:51 -04:00
|
|
|
startX = 0
|
|
|
|
startY += 1
|
|
|
|
return textPart
|