]> git.lyx.org Git - lyx.git/blobdiff - lib/lyx2lyx/parser_tools.py
When cleaning up before quitting, take care of exceptions
[lyx.git] / lib / lyx2lyx / parser_tools.py
index 85e2b6ae8c969c1e98de55fb3f169b4ab737069b..d208c06412f129f8676dcf427ef537b5b8c08987 100644 (file)
@@ -64,7 +64,7 @@ get_value(lines, token, start[, end[, default]):
   and is what is returned if we do not find anything. So you
   can use that to set a default.
   
-get_quoted_value(lines, token, start[, end[, default]):
+get_quoted_value(lines, token, start[, end[, default]]):
   Similar to get_value, but it will strip quotes off the
   value, if they are present. So use this one for cases
   where the value is normally quoted.
@@ -74,6 +74,9 @@ get_option_value(line, option):
       option="value"
   and returns value. Returns "" if not found.
 
+get_bool_value(lines, token, start[, end[, default]]):
+  Like get_value, but returns a boolean.
+
 del_token(lines, token, start[, end]):
   Like find_token, but deletes the line if it finds one.
   Returns True if a line got deleted, otherwise False.
@@ -315,6 +318,25 @@ def get_quoted_value(lines, token, start, end = 0, default = ""):
     return val.strip('"')
 
 
+def get_bool_value(lines, token, start, end = 0, default = None):
+    """ get_value(lines, token, start[[, end], default]) -> string
+
+    Find the next line that looks like:
+      token bool_value
+
+    Returns True if bool_value is 1 or true and
+    False if bool_value is 0 or false
+    """
+
+    val = get_quoted_value(lines, token, start, end, "")
+
+    if val == "1" or val == "true":
+        return True
+    if val == "0" or val == "false":
+        return False
+    return default
+
+
 def get_option_value(line, option):
     rx = option + '\s*=\s*"([^"]+)"'
     rx = re.compile(rx)