-def GetSplitValueList(String, SplitTag = DataType.TAB_VALUE_SPLIT, MaxSplit = -1):\r
- return map(lambda l: l.strip(), String.split(SplitTag, MaxSplit))\r
+def GetSplitValueList(String, SplitTag=DataType.TAB_VALUE_SPLIT, MaxSplit= -1):\r
+ ValueList = []\r
+ Last = 0\r
+ Escaped = False\r
+ InString = False\r
+ InParenthesis = 0\r
+ for Index in range(0, len(String)):\r
+ Char = String[Index]\r
+\r
+ if not Escaped:\r
+ # Found a splitter not in a string, split it\r
+ if not InString and InParenthesis == 0 and Char == SplitTag:\r
+ ValueList.append(String[Last:Index].strip())\r
+ Last = Index + 1\r
+ if MaxSplit > 0 and len(ValueList) >= MaxSplit:\r
+ break\r
+\r
+ if Char == '\\' and InString:\r
+ Escaped = True\r
+ elif Char == '"':\r
+ if not InString:\r
+ InString = True\r
+ else:\r
+ InString = False\r
+ elif Char == '(':\r
+ InParenthesis = InParenthesis + 1\r
+ elif Char == ')':\r
+ InParenthesis = InParenthesis - 1\r
+ else:\r
+ Escaped = False\r
+\r
+ if Last < len(String):\r
+ ValueList.append(String[Last:].strip())\r
+ elif Last == len(String):\r
+ ValueList.append('')\r
+\r
+ return ValueList\r
+\r
+## GetSplitList\r
+#\r
+# Get a value list from a string with multiple values splited with SplitString\r
+# The default SplitTag is DataType.TAB_VALUE_SPLIT\r
+# 'AAA|BBB|CCC' -> ['AAA', 'BBB', 'CCC']\r
+#\r
+# @param String: The input string to be splitted\r
+# @param SplitStr: The split key, default is DataType.TAB_VALUE_SPLIT\r
+# @param MaxSplit: The max number of split values, default is -1\r
+#\r
+# @retval list() A list for splitted string\r
+#\r
+def GetSplitList(String, SplitStr=DataType.TAB_VALUE_SPLIT, MaxSplit= -1):\r
+ return map(lambda l: l.strip(), String.split(SplitStr, MaxSplit))\r