]> https://gitweb.dealii.org/ - dealii.git/commitdiff
wrapcomments.py: numbered list support
authorTimo Heister <timo.heister@gmail.com>
Sun, 7 Feb 2016 00:47:56 +0000 (19:47 -0500)
committerTimo Heister <timo.heister@gmail.com>
Sun, 7 Feb 2016 01:12:17 +0000 (20:12 -0500)
contrib/utilities/wrapcomments.py

index 61ce6144ea7da8c0cabed9e972c5203580554fad..8a0d93f67fa8dd5d828c1eb81e2889eb0220c725 100755 (executable)
@@ -8,7 +8,7 @@
 
 from __future__ import print_function
 import textwrap
-import sys
+import sys, re
 wrapper = textwrap.TextWrapper()
 
 # take an array of lines and wrap them to 78 columns and let each line start
@@ -116,7 +116,15 @@ def format_block(lines, infostr=""):
                 if it in thisline and thisline!=it:
                     print ("%s warning %s not in separate line"%(infostr, it), file=sys.stderr)
             out.append(start + thisline)
-        elif starts_with_one(["* - ", "*   - "],lines[idx].strip()):
+        elif re.match(r'\*\s+- ',lines[idx].strip()):
+            # bullet ('-') list
+            if curlines!=[]:
+                out.extend(wrap_block(remove_junk(curlines), start))
+                curlines=[]
+            thisline = lines[idx].strip()[2:]
+            out.append(start + thisline)
+        elif lines[idx].strip().startswith("* ") and re.match(r'\s*\d+.',lines[idx][3:]):
+            # numbered list
             if curlines!=[]:
                 out.extend(wrap_block(remove_junk(curlines), start))
                 curlines=[]
@@ -441,6 +449,7 @@ lineI = [" /**", \
          "  *   - C", \
          "  *   - D", \
          "  * - E", \
+         "  *         - very indented", \
          "  */"]
 lineO = lineI
 assert(format_block(lineI)==lineO)
@@ -472,9 +481,35 @@ lineI = [" /**", \
          "  * bla", \
          "  */"]
 lineO = lineI
-#print (lineI, "\n",format_block(lineI))
 assert(format_block(lineI)==lineO)
 
+# lists
+lineI = [" /**", \
+         "  * Hello:", \
+         "  *  - a", \
+         "  *  - b", \
+         "  * the end.", \
+         "  */"]
+lineO = lineI
+assert(format_block(lineI)==lineO)
+
+# numbered lists
+lineI = [" /**", \
+         "  * Hello:", \
+         "  * 1. a", \
+         "  * 2. b", \
+         "  * the end.", \
+         "  */"]
+lineO = lineI
+assert(format_block(lineI)==lineO)
+
+
+
+#print (lineI)
+#print (format_block(lineI))
+
+
+
 
 # now open the file and do the work
 

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.