Enhance sdn-assist reporting
[osm/RO.git] / osm_ro / utils.py
index 00f6f2d..c7d966e 100644 (file)
@@ -178,4 +178,21 @@ def check_valid_uuid(uuid):
         except js_e.ValidationError:
             return False
     return False
-    
+
+
+def expand_brackets(text):
+    """
+    Change a text with TEXT[ABC..] into a list with [TEXTA, TEXTB, TEXC, ...
+    if no bracket is used it just return the a list with the single text
+    It uses recursivity to allow several [] in the text
+    :param text:
+    :return:
+    """
+    start = text.find("[")
+    end = text.find("]")
+    if start < 0 or end < 0:
+        return [text]
+    text_list = []
+    for char in text[start+1:end]:
+        text_list += expand_brackets(text[:start] + char + text[end+1:])
+    return text_list