Georg Baum wrote:

> Attached is a better patch, based on your comments.
> 
> Plase test.

Did anybody test this? It works for me. I think I am committing it to trunk
soon, but I'd like to get enough testing so that it can also go into 1.4.1.

ChangeLog:

        * parser_tools.py (find_tokens_exact): new, extract tokens with
        exact match
        * parser_tools.py (find_token2): rename to find_token_exact and make
        it work for tokens with spaces
        * lyx_1_4.py (revert_box, convert_collapsable, revert_bibtopic,
        convert_float): use find_token(s)_exact instead of find_token(s).
        This does not match "FloatList" when "Float" is searched (bug 2245)



Georg
Index: lib/lyx2lyx/parser_tools.py
===================================================================
--- lib/lyx2lyx/parser_tools.py	(Revision 13327)
+++ lib/lyx2lyx/parser_tools.py	(Arbeitskopie)
@@ -37,27 +37,43 @@ def find_token(lines, token, start, end 
     return -1
 
 
-def find_token2(lines, token, start, end = 0):
+def find_token_exact(lines, token, start, end = 0):
     if end == 0:
 	end = len(lines)
     for i in xrange(start, end):
-	x = string.split(lines[i])
-	if len(x) > 0 and x[0] == token:
-	    return i
+        x = string.split(lines[i])
+        y = string.split(token)
+        if len(x) < len(y):
+            continue
+        if x[:len(y)] == y:
+            return i
     return -1
 
 
 def find_tokens(lines, tokens, start, end = 0):
     if end == 0:
 	end = len(lines)
-    for i in xrange(start, end):
-	line = lines[i]
+    for i in range(start, end):
 	for token in tokens:
-	    if line[:len(token)] == token:
+	    if lines[i][:len(token)] == token:
 		return i
     return -1
 
 
+def find_tokens_exact(lines, tokens, start, end = 0):
+    if end == 0:
+	end = len(lines)
+    for i in range(start, end):
+        for token in tokens:
+            x = string.split(lines[i])
+            y = string.split(token)
+            if len(x) < len(y):
+                continue
+            if x[:len(y)] == y:
+                return i
+    return -1
+
+
 def find_re(lines, rexp, start, end = 0):
     if end == 0:
 	end = len(lines)
@@ -86,7 +102,7 @@ def find_tokens_backwards(lines, tokens,
 
 
 def get_value(lines, token, start, end = 0):
-    i = find_token2(lines, token, start, end)
+    i = find_token_exact(lines, token, start, end)
     if i == -1:
 	return ""
     if len(string.split(lines[i])) > 1:
@@ -103,7 +119,7 @@ def get_layout(line, default_layout):
 
 
 def del_token(lines, token, i, j):
-    k = find_token2(lines, token, i, j)
+    k = find_token_exact(lines, token, i, j)
     if k == -1:
 	return j
     else:
Index: lib/lyx2lyx/lyx_1_3.py
===================================================================
--- lib/lyx2lyx/lyx_1_3.py	(Revision 13327)
+++ lib/lyx2lyx/lyx_1_3.py	(Arbeitskopie)
@@ -20,7 +20,7 @@
 import string
 import re
 from parser_tools import find_token, find_end_of_inset, get_value,\
-                         find_token2, del_token
+                         find_token_exact, del_token
 
 def change_insetgraphics(file):
     lines = file.body
@@ -38,16 +38,16 @@ def change_insetgraphics(file):
 	if get_value(lines, "rotateOrigin", i, j) == "leftBaseline":
 	    j = del_token(lines, "rotateOrigin", i, j)
 
-	k = find_token2(lines, "rotate", i, j)
+	k = find_token_exact(lines, "rotate", i, j)
 	if k != -1:
 	    del lines[k]
 	    j = j-1
 	else:
 	    j = del_token(lines, "rotateAngle", i, j)
 
-	k = find_token2(lines, "size_type", i, j)
+	k = find_token_exact(lines, "size_type", i, j)
 	if k == -1:
-	    k = find_token2(lines, "size_kind", i, j)
+	    k = find_token_exact(lines, "size_kind", i, j)
 	if k != -1:
 	    size_type = string.split(lines[k])[1]
 	    del lines[k]
@@ -64,9 +64,9 @@ def change_insetgraphics(file):
 	    else:
 		j = del_token(lines, "scale", i, j)
 
-	k = find_token2(lines, "lyxsize_type", i, j)
+	k = find_token_exact(lines, "lyxsize_type", i, j)
 	if k == -1:
-	    k = find_token2(lines, "lyxsize_kind", i, j)
+	    k = find_token_exact(lines, "lyxsize_kind", i, j)
 	if k != -1:
 	    lyxsize_type = string.split(lines[k])[1]
 	    del lines[k]
Index: lib/lyx2lyx/lyx_1_4.py
===================================================================
--- lib/lyx2lyx/lyx_1_4.py	(Revision 13327)
+++ lib/lyx2lyx/lyx_1_4.py	(Arbeitskopie)
@@ -23,8 +23,8 @@ from os import access, F_OK
 import os.path
 from parser_tools import find_token, find_end_of_inset, get_next_paragraph, \
                          get_paragraph, get_value, del_token, is_nonempty_line,\
-			 find_tokens, find_end_of, find_token2, find_re,\
-                         get_layout
+			 find_tokens, find_end_of, find_token_exact, find_tokens_exact,\
+                         find_re, get_layout
 from sys import stdin
 from string import replace, split, find, strip, join
 
@@ -827,7 +827,7 @@ def revert_box(file):
 def convert_collapsable(file):
     i = 0
     while 1:
-        i = find_tokens(file.body, ["\\begin_inset Box",
+        i = find_tokens_exact(file.body, ["\\begin_inset Box",
                                 "\\begin_inset Branch",
                                 "\\begin_inset CharStyle",
                                 "\\begin_inset Float",
@@ -861,7 +861,7 @@ def convert_collapsable(file):
 def revert_collapsable(file):
     i = 0
     while 1:
-        i = find_tokens(file.body, ["\\begin_inset Box",
+        i = find_tokens_exact(file.body, ["\\begin_inset Box",
                                 "\\begin_inset Branch",
                                 "\\begin_inset CharStyle",
                                 "\\begin_inset Float",
@@ -1752,7 +1752,7 @@ def revert_bibtopic(file):
 def convert_float(file):
     i = 0
     while 1:
-        i = find_token(file.body, '\\begin_inset Float', i)
+        i = find_token_exact(file.body, '\\begin_inset Float', i)
         if i == -1:
             return
         # Seach for a line starting 'wide'
@@ -1773,7 +1773,7 @@ def convert_float(file):
 def revert_float(file):
     i = 0
     while 1:
-        i = find_token(file.body, '\\begin_inset Float', i)
+        i = find_token_exact(file.body, '\\begin_inset Float', i)
         if i == -1:
             return
         j = find_end_of_inset(file.body, i)
@@ -1799,7 +1799,7 @@ def convert_graphics(file):
         if i == -1:
             return
 
-	j = find_token2(file.body, "filename", i)
+	j = find_token_exact(file.body, "filename", i)
         if j == -1:
             return
         i = i + 1

Reply via email to