Utilities/__init__.py

changeset 1308
2b602a1521e7
parent 1190
aac32b0fdfb8
child 1309
6caa231421cf
--- a/Utilities/__init__.py	Fri Sep 09 09:33:19 2011 +0200
+++ b/Utilities/__init__.py	Fri Sep 09 11:54:20 2011 +0200
@@ -546,6 +546,27 @@
     return extractFlags(source)
 
 
+def extractLineFlags(line, startComment="#", endComment=""):
+    """
+    Function to extract flags starting and ending with '__' from a line comment.
+    
+    @param line line to extract flags from (string)
+    @keyparam startComment string identifying the start of the comment (string)
+    @keyparam endComment string identifying the end of a comment (string)
+    @return list containing the extracted flags (list of strings)
+    """
+    flags = []
+    
+    pos = line.rindex(startComment)
+    if pos >= 0:
+        comment = line[pos + len(startComment):].strip()
+        if endComment:
+            comment = comment.replace("endComment", "")
+        flags = [f.strip() for f in comment.split()
+                 if (f.startswith("__") and f.endswith("__"))]
+    return flags
+
+
 def toNativeSeparators(path):
     """
     Function returning a path, that is using native separator characters.

eric ide

mercurial