diff --git a/lib/lyx2lyx/lyx_1_3.py b/lib/lyx2lyx/lyx_1_3.py index 7ced9af7fd..57d3ff17b6 100644 --- a/lib/lyx2lyx/lyx_1_3.py +++ b/lib/lyx2lyx/lyx_1_3.py @@ -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] diff --git a/lib/lyx2lyx/lyx_1_4.py b/lib/lyx2lyx/lyx_1_4.py index ea6dddee26..edc027cff5 100644 --- a/lib/lyx2lyx/lyx_1_4.py +++ b/lib/lyx2lyx/lyx_1_4.py @@ -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 diff --git a/lib/lyx2lyx/parser_tools.py b/lib/lyx2lyx/parser_tools.py index c3d9899e88..d857e2287c 100644 --- a/lib/lyx2lyx/parser_tools.py +++ b/lib/lyx2lyx/parser_tools.py @@ -37,27 +37,43 @@ def find_token(lines, token, start, end = 0): 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, start): 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: diff --git a/status.14x b/status.14x index f4ace5cf05..858e384d35 100644 --- a/status.14x +++ b/status.14x @@ -37,6 +37,9 @@ What's new - Import fixed width table columns correctly in tex2lyx (bug 2290). +- Convert old LyX documents with a float list at the end correctly in + lyx2lyx (bug 2245). + * User Interface: - Convert line endings for external copy/paste on OS X (bug 1955).