Commit f3056f04 authored by Christian Stenger's avatar Christian Stenger
Browse files

Squish: Fix script for multiline strings

If object names are scattered across multiple lines the
script failed to get the whole object name and failed therefore.
This patch corrects this behavior.

Change-Id: Ia97e2577162b77ae1b72fdd51dda4c74c59abe25
Reviewed-by: default avatarRobert Loehning <>
parent eac15b5e
......@@ -8,6 +8,8 @@ from toolfunctions import checkDirectory
from toolfunctions import getFileContent
objMap = None
lastToken = [None, None]
stopTokens = ('OP', 'NAME', 'NUMBER', 'ENDMARKER')
def parseCommandLine():
global directory, onlyRemovable, fileType
......@@ -44,12 +46,32 @@ def getFileSuffix():
'Tcl':'.tcl', 'Ruby':'.rb'}
return fileSuffixes.get(fileType, None)
def handleStringsWithTrailingBackSlash(origStr):
while True:
index = origStr.index("\\\n")
origStr = origStr[:index] + origStr[index+2:].lstrip()
return origStr
def handle_token(tokenType, token, (startRow, startCol), (endRow, endCol), line):
global useCounts
global useCounts, lastToken, stopTokens
if tokenize.tok_name[tokenType] == 'STRING':
for obj in useCounts:
useCounts[obj] += str(token).count("'%s'" % obj)
useCounts[obj] += str(token).count('"%s"' % obj)
# concatenate strings followed directly by other strings
if lastToken[0] == 'STRING':
token = "'" + lastToken[1][1:-1] + str(token)[1:-1] + "'"
# store the new string as lastToken after removing potential trailing backslashes
# (including their following indentation)
lastToken = ['STRING' , handleStringsWithTrailingBackSlash(str(token))]
# if a stop token occurs check the potential string before it
elif tokenize.tok_name[tokenType] in stopTokens:
if lastToken[0] == 'STRING':
for obj in useCounts:
useCounts[obj] += lastToken[1].count("'%s'" % obj)
useCounts[obj] += lastToken[1].count('"%s"' % obj)
# store the stop token as lastToken
lastToken = [tokenize.tok_name[tokenType], str(token)]
def findUsages():
global directory, objMap
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment