Update mark_utils.py
This commit is contained in:
parent
9ad3596406
commit
41caeed747
@ -1,6 +1,14 @@
|
|||||||
#!/bin/python
|
#!/bin/python
|
||||||
|
|
||||||
def getTextBetweenMarks(firstMark, secondMark, inText):
|
def getTextBetweenMarks(firstMark, secondMark, inText):
|
||||||
|
if inText == None:
|
||||||
|
return ''
|
||||||
|
if isinstance(inText, list):
|
||||||
|
inText = inText.split('\n')
|
||||||
|
if len(inText) < 1:
|
||||||
|
return ''
|
||||||
|
if inText == '':
|
||||||
|
return ''
|
||||||
if firstMark == None:
|
if firstMark == None:
|
||||||
return ''
|
return ''
|
||||||
if secondMark == None:
|
if secondMark == None:
|
||||||
@ -11,19 +19,41 @@ def getTextBetweenMarks(firstMark, secondMark, inText):
|
|||||||
else:
|
else:
|
||||||
endMark = firstMark.copy()
|
endMark = firstMark.copy()
|
||||||
startMark = secondMark.copy()
|
startMark = secondMark.copy()
|
||||||
startX = startMark['x']
|
currX = startMark['x']
|
||||||
startY = startMark['y']
|
currY = startMark['y']
|
||||||
textPart = ''
|
textPart = ''
|
||||||
while startY <= endMark['y']:
|
while currY <= endMark['y'] and currY <= len(inText):
|
||||||
if startMark['y'] == endMark['y']:
|
if startMark['y'] == endMark['y']:
|
||||||
textPart += inText[startY][startX:endMark['x'] + 1]
|
textPart += inText[currY][currX:endMark['x'] + 1]
|
||||||
else:
|
else:
|
||||||
if startY < endMark['y']:
|
if currY < endMark['y']:
|
||||||
textPart += inText[startY][startX:]
|
textPart += inText[currY][currX:]
|
||||||
if len(textPart) - len(textPart[::-1].strip()) > 0:
|
if len(textPart) - len(textPart[::-1].strip()) > 0:
|
||||||
textPart = textPart[:len(textPart[::-1].strip())] + "\n"
|
textPart = textPart[:len(textPart[::-1].strip())] + "\n"
|
||||||
else:
|
else:
|
||||||
textPart += inText[startY][:startX + 1]
|
textPart += inText[currY][:currX + 1]
|
||||||
startX = 0
|
currX = 0
|
||||||
startY += 1
|
currY += 1
|
||||||
return textPart
|
return textPart
|
||||||
|
|
||||||
|
def getTextBeforeMark(mark, inText):
|
||||||
|
if inText == None:
|
||||||
|
return ''
|
||||||
|
if isinstance(inText, list):
|
||||||
|
inText = inText.split('\n')
|
||||||
|
if len(inText) < 1:
|
||||||
|
return ''
|
||||||
|
if mark == None:
|
||||||
|
return ''
|
||||||
|
return getTextBetweenMarks({'x':0,'y':0}, mark, inText)
|
||||||
|
|
||||||
|
def getTextAfterMark(mark, inText):
|
||||||
|
if inText == None:
|
||||||
|
return ''
|
||||||
|
if isinstance(inText, list):
|
||||||
|
inText = inText.split('\n')
|
||||||
|
if len(inText) < 1:
|
||||||
|
return ''
|
||||||
|
if mark == None:
|
||||||
|
return ''
|
||||||
|
return getTextBetweenMarks(mark, {'x':len(inText[0])-1,'y':len(inText)-1}, inText)
|
||||||
|
Loading…
Reference in New Issue
Block a user