1 #----------------------------------------------------------------------------
3 # Purpose: String Utilities
9 # Copyright: (c) 2005 ActiveGrid, Inc.
10 # License: wxWindows License
11 #----------------------------------------------------------------------------
14 def caseInsensitiveCompare(s1
, s2
):
15 """ Method used by sort() to sort values in case insensitive order """
25 def multiSplit(stringList
, tokenList
=[" "]):
26 """Splits strings in stringList by tokens, returns list of string."""
27 if not stringList
: return []
28 if isinstance(tokenList
, basestring
):
29 tokenList
= [tokenList
]
30 if isinstance(stringList
, basestring
):
31 stringList
= [stringList
]
33 for token
in tokenList
:
35 for string
in rtnList
:
36 if string
.find(token
) > -1:
37 rtnList
.remove(string
)
38 names
= string
.split(token
)
47 def _findArgStart(argStr
):
58 def _findArgEnd(argStr
):
60 argEndChar
= argStr
[0]
61 if (not argEndChar
in QUOTES
):
74 return min(i
+1, len(argStr
))
79 def parseArgs(argStr
, stripQuotes
=False):
81 Given a str representation of method arguments, returns list arguments (as
84 Input: "('[a,b]', 'c', 1)" -> Output: ["'[a,b]'", "'c'", "1"].
86 If stripQuotes, removes quotes from quoted arg.
88 if (argStr
.startswith("(")):
90 if (argStr
.endswith(")")):
93 raise AssertionError("Expected argStr to end with ')'")
96 argsStr
= argStr
.strip()
98 startIndex
= _findArgStart(argStr
)
99 if (startIndex
== None):
101 argStr
= argStr
[startIndex
:]
102 endIndex
= _findArgEnd(argStr
)
103 if (endIndex
== len(argStr
) - 1):
104 rtn
.append(argStr
.strip())
106 t
= argStr
[:endIndex
].strip()
107 if (stripQuotes
and t
[0] in QUOTES
and t
[-1] in QUOTES
):
110 argStr
= argStr
[endIndex
:]