# # This script written by Eli Fulkerson. # http://www.elifulkerson.com for more. # def split_respect_singlequotes( data, splitval=" "): """ This function returns a list of arguments in data, but ignoring the splitval token when it is found within single quotes. For instances, it allows "cast 'magic missile' 'big ogre'" to be returned as three arguments. cast, 'magic missile' and 'big ogre' """ tmp = [] buffer = "" quotes = 0 for counter in range(0, len(data)): if data[counter] == "'": quotes = (quotes + 1) % 2 elif quotes == 0 and data[counter] == splitval: tmp.append(buffer) buffer = "" else: buffer = buffer + data[counter] tmp.append(buffer) return tmp