eric6/Utilities/__init__.py

changeset 8075
6774034a1e0f
parent 8067
a467ab075be0
child 8100
a4c231453cbc
--- a/eric6/Utilities/__init__.py	Fri Feb 05 09:48:22 2021 +0100
+++ b/eric6/Utilities/__init__.py	Fri Feb 05 11:02:11 2021 +0100
@@ -16,6 +16,7 @@
 import getpass
 import ctypes
 import subprocess           # secok
+import shlex
 
 
 def __showwarning(message, category, filename, lineno, file=None, line=""):
@@ -1340,58 +1341,23 @@
     """
     Function used to convert an option string into a list of options.
     
-    @param s option string (string or string)
-    @return list of options (list of strings)
-    """
-    rx = re.compile(r"""\s([\w=/-]*"[^"]+"|[\w=/-]*'[^']+'|[^\s]+)""")
-    s = re.sub(r"%[A-Z%]", _percentReplacementFunc, s)
-    return parseString(s, rx)
-    
-
-def parseEnvironmentString(s):
-    """
-    Function used to convert an environment string into a list of environment
-    settings.
-    
-    @param s environment string (string)
-    @return list of environment settings (list of strings)
-    """
-    rx = re.compile(r"""\s(\w+\+?=[^\s]+|\w+="[^"]+"|\w+='[^']+')""")
-    return parseString(s, rx)
-
-
-def parseString(s, rx):
-    """
-    Function used to convert a string into a list.
-    
-    @param s string to be parsed
+    @param s option string
     @type str
-    @param rx regular expression object defining the parse pattern
-    @type re.Pattern
-    @return list of parsed data
+    @return list of options
     @rtype list of str
     """
-    olist = []
-    if s:
-        if not s.startswith(' '):
-            # prepare the  string to fit our pattern
-            s = ' ' + s
-        
-        for match in rx.finditer(s):
-            cs = match.group(1)
-            if cs.startswith('"') or cs.startswith("'"):
-                cs = cs[1:-1]
-            olist.append(cs)
-    
-    return olist
+    s = re.sub(r"%[A-Z%]", _percentReplacementFunc, s)
+    return shlex.split(s)
 
 
 def _percentReplacementFunc(matchobj):
     """
     Protected function called for replacing % codes.
     
-    @param matchobj matchobject for the code
+    @param matchobj match object for the code
+    @type re.Match
     @return replacement string
+    @rtype str
     """
     return getPercentReplacement(matchobj.group(0))
     
@@ -1400,8 +1366,10 @@
     """
     Function to get the replacement for code.
     
-    @param code code indicator (string)
-    @return replacement string (string)
+    @param code code indicator
+    @type str
+    @return replacement string
+    @rtype str
     """
     if code in ["C", "%C"]:
         # column of the cursor of the current editor

eric ide

mercurial