X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2FTexRow.cpp;h=a18d84f5438925847e1a65129d5f14f7236aeb97;hb=225c1dbe55635a97b183909ea7194b8d92051378;hp=635be479f0fbeba8548b9eedeffc34d6e594616a;hpb=6b87801d096c2e462b8202af22b0adea24bceff9;p=lyx.git diff --git a/src/TexRow.cpp b/src/TexRow.cpp index 635be479f0..a18d84f543 100644 --- a/src/TexRow.cpp +++ b/src/TexRow.cpp @@ -4,7 +4,7 @@ * Licence details can be found in the file COPYING. * * \author Matthias Ettrich - * \author Lars Gullik Bjønnes + * \author Lars Gullik Bjønnes * \author John Levon * * Full author contact details are available in file CREDITS. @@ -13,7 +13,8 @@ #include #include "TexRow.h" -#include "debug.h" + +#include "support/debug.h" #include @@ -43,10 +44,16 @@ void TexRow::newline() rowlist.push_back(tmp); } +void TexRow::newlines(int num_lines) +{ + for (int i = 0; i < num_lines; ++i) { + newline(); + } +} bool TexRow::getIdFromRow(int row, int & id, int & pos) const { - if (row <= 0 || row > rowlist.size()) { + if (row <= 0 || row > int(rowlist.size())) { id = -1; pos = 0; return false; @@ -60,20 +67,24 @@ bool TexRow::getIdFromRow(int row, int & id, int & pos) const int TexRow::getRowFromIdPos(int id, int pos) const { - int bestrow = 0; bool foundid = false; - // this loop finds the last *nonempty* row whith the same id + // this loop finds the last *nonempty* row with the same id // and position <= pos - for (unsigned r = 0, n = rowlist.size(); r != n; ++r) { - if (rowlist[r].id() == id && rowlist[r].pos() <= pos) { + RowList::const_iterator bestrow = rowlist.begin(); + RowList::const_iterator it = rowlist.begin(); + RowList::const_iterator const end = rowlist.end(); + for (; it != end; ++it) { + if (it->id() == id && it->pos() <= pos) { foundid = true; - if (rowlist[bestrow].id() != id || rowlist[r].pos() > rowlist[bestrow].pos()) - bestrow = r; + if (bestrow->id() != id || it->pos() > bestrow->pos()) + bestrow = it; } else if (foundid) break; } - return bestrow; + if (!foundid) + return rowlist.size(); + return distance(rowlist.begin(), bestrow) + 1; }