]> git.lyx.org Git - lyx.git/blob - src/TexRow.cpp
Make Thesaurus check for more general dictionaries (en-v2.idx)
[lyx.git] / src / TexRow.cpp
1 /**
2  * \file TexRow.cpp
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Matthias Ettrich
7  * \author Lars Gullik Bjønnes
8  * \author John Levon
9  *
10  * Full author contact details are available in file CREDITS.
11  */
12
13 #include <config.h>
14
15 #include "TexRow.h"
16
17 #include "support/debug.h"
18
19 #include <algorithm>
20
21
22 namespace lyx {
23
24
25 void TexRow::reset()
26 {
27         rowlist.clear();
28         lastid = -1;
29         lastpos = -1;
30 }
31
32
33 void TexRow::start(int id, int pos)
34 {
35         if (started)
36                 return;
37
38         lastid = id;
39         lastpos = pos;
40         started = true;
41 }
42
43
44 void TexRow::newline()
45 {
46         int const id = lastid;
47         RowList::value_type tmp(id, lastpos);
48         rowlist.push_back(tmp);
49         started = false;
50 }
51
52 void TexRow::newlines(int num_lines)
53 {
54         for (int i = 0; i < num_lines; ++i) {
55                 newline();
56         }
57 }
58
59 bool TexRow::getIdFromRow(int row, int & id, int & pos) const
60 {
61         if (row <= 0 || row > int(rowlist.size())) {
62                 id = -1;
63                 pos = 0;
64                 return false;
65         }
66
67         id = rowlist[row - 1].id();
68         pos = rowlist[row - 1].pos();
69         return true;
70 }
71
72
73 int TexRow::getRowFromIdPos(int id, int pos) const
74 {
75         bool foundid = false;
76
77         // this loop finds the last *nonempty* row with the same id
78         // and position <= pos
79         RowList::const_iterator bestrow = rowlist.begin();
80         RowList::const_iterator it = rowlist.begin();
81         RowList::const_iterator const end = rowlist.end();
82         for (; it != end; ++it) {
83                 if (it->id() == id && it->pos() <= pos) {
84                         foundid = true;
85                         if (bestrow->id() != id || it->pos() > bestrow->pos())
86                                 bestrow = it;
87                 } else if (foundid)
88                         break;
89         }
90         if (!foundid)
91                 return rowlist.size();
92         return distance(rowlist.begin(), bestrow) + 1;
93 }
94
95
96 } // namespace lyx