1 /* This file is part of
2 * ======================================================
4 * LyX, The Document Processor
6 * Copyright 2000-2001 The LyX Team.
8 * @author: Jürgen Vigna
10 * ======================================================
17 #include "support/lstrings.h"
26 bool getTokenValue(string const & str, const char * token, string & ret)
28 size_t token_length = std::strlen(token);
29 string::size_type pos = str.find(token);
31 if (pos == string::npos || pos + token_length + 1 >= str.length()
32 || str[pos + token_length] != '=')
35 pos += token_length + 1;
37 if ((ch != '"') && (ch != '\'')) { // only read till next space
41 while((pos < str.length() - 1) && (str[++pos] != ch))
48 bool getTokenValue(string const & str, const char * token, int & num)
50 string::size_type pos = str.find(token);
51 char ch = str[pos + std::strlen(token)];
53 if ((pos == string::npos) || (ch != '='))
56 pos += std::strlen(token) + 1;
58 if ((ch != '"') && (ch != '\'')) { // only read till next space
64 while((pos < str.length() - 1) && isdigit(str[pos]))
72 bool getTokenValue(string const & str, const char * token, LyXAlignment & num)
75 bool const ret = getTokenValue(str, token, tmp);
76 num = static_cast<LyXAlignment>(tmp);
81 bool getTokenValue(string const & str, const char * token,
82 LyXTabular::VAlignment & num)
85 bool const ret = getTokenValue(str, token, tmp);
86 num = static_cast<LyXTabular::VAlignment>(tmp);
91 bool getTokenValue(string const & str, const char * token,
92 LyXTabular::BoxType & num)
95 bool ret = getTokenValue(str, token, tmp);
96 num = static_cast<LyXTabular::BoxType>(tmp);
101 bool getTokenValue(string const & str, const char * token, bool & flag)
103 string::size_type pos = str.find(token);
104 char ch = str[pos + std::strlen(token)];
106 if ((pos == string::npos) || (ch != '='))
109 pos += std::strlen(token) + 1;
111 if ((ch != '"') && (ch != '\'')) { // only read till next space
117 while((pos < str.length() - 1) && isdigit(str[pos]))
120 flag = strToInt(ret);
126 void l_getline(istream & is, string & str)
129 #warning old l_getline
139 void LyXTabular::ReadOld(Buffer const * buf, istream & is,
140 LyXLex & lex, string const & l)
145 if (!getTokenValue(line, "rows", rows_arg))
147 if (!getTokenValue(line, "columns", columns_arg))
149 Init(rows_arg, columns_arg);
151 if (!prefixIs(line, "<Features ")) {
152 lyxerr << "Wrong tabular format (expected <Feture ...> got" <<
156 getTokenValue(line, "islongtable", is_long_tabular);
157 getTokenValue(line, "endhead", endhead);
158 getTokenValue(line, "endfirsthead", endfirsthead);
159 getTokenValue(line, "endfoot", endfoot);
160 getTokenValue(line, "endlastfoot", endlastfoot);
162 for (int i = 0; i < rows_; ++i) {
164 if (!prefixIs(line, "<Row ")) {
165 lyxerr << "Wrong tabular format (expected <Row ...> got" <<
169 getTokenValue(line, "topline", row_info[i].top_line);
170 getTokenValue(line, "bottomline", row_info[i].bottom_line);
171 getTokenValue(line, "newpage", row_info[i].newpage);
172 for (int j = 0; j < columns_; ++j) {
174 if (!prefixIs(line,"<Column")) {
175 lyxerr << "Wrong tabular format (expected <Column ...> got" <<
180 getTokenValue(line, "alignment", column_info[j].alignment);
181 getTokenValue(line, "valignment", column_info[j].valignment);
182 getTokenValue(line, "leftline", column_info[j].left_line);
183 getTokenValue(line, "rightline", column_info[j].right_line);
184 getTokenValue(line, "width", column_info[j].p_width);
185 getTokenValue(line, "special", column_info[j].align_special);
188 if (!prefixIs(line, "<Cell")) {
189 lyxerr << "Wrong tabular format (expected <Cell ...> got" <<
193 getTokenValue(line, "multicolumn", cell_info[i][j].multicolumn);
194 getTokenValue(line, "alignment", cell_info[i][j].alignment);
195 getTokenValue(line, "valignment", cell_info[i][j].valignment);
196 getTokenValue(line, "topline", cell_info[i][j].top_line);
197 getTokenValue(line, "bottomline", cell_info[i][j].bottom_line);
198 getTokenValue(line, "leftline", cell_info[i][j].left_line);
199 getTokenValue(line, "rightline", cell_info[i][j].right_line);
200 getTokenValue(line, "rotate", cell_info[i][j].rotate);
201 getTokenValue(line, "usebox", cell_info[i][j].usebox);
202 getTokenValue(line, "width", cell_info[i][j].p_width);
203 getTokenValue(line, "special", cell_info[i][j].align_special);
205 if (prefixIs(line, "\\begin_inset")) {
206 cell_info[i][j].inset.Read(buf, lex);
209 if (line != "</Cell>") {
210 lyxerr << "Wrong tabular format (expected </Cell> got" <<
215 if (line != "</Column>") {
216 lyxerr << "Wrong tabular format (expected </Column> got" <<
222 if (line != "</Row>") {
223 lyxerr << "Wrong tabular format (expected </Row> got" <<
228 while (line != "</LyXTabular>") {
231 set_row_column_number_info();