X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=lib%2Flyx2lyx%2Fparser_tools.py;h=43ebcd091c3d90625e483bed50fd3a408014ab04;hb=0db238a371fe9b9455cea32d88c8c5d4216fc9d9;hp=0299ed7c4a4ffd0f7e063762367faf221ff99905;hpb=5e4493d97be6b5cb4c4e740870a5c6923e5f6a69;p=lyx.git diff --git a/lib/lyx2lyx/parser_tools.py b/lib/lyx2lyx/parser_tools.py index 0299ed7c4a..43ebcd091c 100644 --- a/lib/lyx2lyx/parser_tools.py +++ b/lib/lyx2lyx/parser_tools.py @@ -1,6 +1,7 @@ # This file is part of lyx2lyx # -*- coding: utf-8 -*- -# Copyright (C) 2002-2004 Dekel Tsur , José Matos +# Copyright (C) 2002-2010 Dekel Tsur , +# José Matos , Richard Heck # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License @@ -16,7 +17,7 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -" This modules offer several free functions to help parse lines." +" This modules offer several free functions to help parse lines. " # Utilities for one line def check_token(line, token): @@ -241,3 +242,18 @@ def find_end_of_inset(lines, i): def find_end_of_layout(lines, i): " Find end of layout, where lines[i] is included." return find_end_of(lines, i, "\\begin_layout", "\\end_layout") + + +# checks if line i is in the inset e.g., "\\begin_inset CommandInset ref" +# if so, returns starting and ending lines +# otherwise, returns (-1, -1) +def get_containing_inset(lines, i, inset): + defval = (-1, -1) + stins = find_token_backwards(lines, inset, i) + if stins == -1: + return defval + endins = find_end_of_inset(lines, stins) + # note that this includes the notfound case. + if endins < i: + return defval + return (stins, endins)