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 * ======================================================
15 #include "tabular_funcs.h"
17 #include "support/LIstream.h"
19 #ifndef CXX_GLOBAL_CSTD
26 // Perfect case for a template... (Lgb)
30 string const write_attribute(string const & name, bool const & b)
32 // we write only true attribute values so we remove a bit of the
33 // file format bloat for tabulars.
37 return write_attribute(name, tostr(b));
41 string const write_attribute(string const & name, int const & i)
43 // we write only true attribute values so we remove a bit of the
44 // file format bloat for tabulars.
48 return write_attribute(name, tostr(i));
52 string const write_attribute(string const & name, LyXLength const & value)
54 // we write only the value if we really have one same reson as above.
58 return write_attribute(name, value.asString());
62 string const tostr(LyXAlignment const & num)
71 case LYX_ALIGN_CENTER:
75 case LYX_ALIGN_LAYOUT:
77 case LYX_ALIGN_SPECIAL:
84 string const tostr(LyXTabular::VAlignment const & num)
87 case LyXTabular::LYX_VALIGN_TOP:
89 case LyXTabular::LYX_VALIGN_CENTER:
91 case LyXTabular::LYX_VALIGN_BOTTOM:
98 string const tostr(LyXTabular::BoxType const & num)
101 case LyXTabular::BOX_NONE:
103 case LyXTabular::BOX_PARBOX:
105 case LyXTabular::BOX_MINIPAGE:
111 // I would have liked a fromstr template a lot better. (Lgb)
112 bool string2type(string const str, LyXAlignment & num)
115 num = LYX_ALIGN_NONE;
116 else if (str == "block")
117 num = LYX_ALIGN_BLOCK;
118 else if (str == "left")
119 num = LYX_ALIGN_LEFT;
120 else if (str == "center")
121 num = LYX_ALIGN_CENTER;
122 else if (str == "right")
123 num = LYX_ALIGN_RIGHT;
130 bool string2type(string const str, LyXTabular::VAlignment & num)
133 num = LyXTabular::LYX_VALIGN_TOP;
134 else if (str == "center")
135 num = LyXTabular::LYX_VALIGN_CENTER;
136 else if (str == "bottom")
137 num = LyXTabular::LYX_VALIGN_BOTTOM;
144 bool string2type(string const str, LyXTabular::BoxType & num)
147 num = LyXTabular::BOX_NONE;
148 else if (str == "parbox")
149 num = LyXTabular::BOX_PARBOX;
150 else if (str == "minipage")
151 num = LyXTabular::BOX_MINIPAGE;
158 bool string2type(string const str, bool & num)
162 else if (str == "false")
170 bool getTokenValue(string const & str, const char * token, string & ret)
173 size_t token_length = strlen(token);
174 string::size_type pos = str.find(token);
176 if (pos == string::npos || pos + token_length + 1 >= str.length()
177 || str[pos + token_length] != '=')
179 pos += token_length + 1;
181 if ((ch != '"') && (ch != '\'')) { // only read till next space
185 while ((pos < str.length() - 1) && (str[++pos] != ch))
192 bool getTokenValue(string const & str, const char * token, int & num)
196 if (!getTokenValue(str, token, tmp))
203 bool getTokenValue(string const & str, const char * token, LyXAlignment & num)
206 if (!getTokenValue(str, token, tmp))
208 return string2type(tmp, num);
212 bool getTokenValue(string const & str, const char * token,
213 LyXTabular::VAlignment & num)
216 if (!getTokenValue(str, token, tmp))
218 return string2type(tmp, num);
222 bool getTokenValue(string const & str, const char * token,
223 LyXTabular::BoxType & num)
226 if (!getTokenValue(str, token, tmp))
228 return string2type(tmp, num);
232 bool getTokenValue(string const & str, const char * token, bool & flag)
234 // set the flag always to false as this should be the default for bools
235 // not in the file-format.
238 if (!getTokenValue(str, token, tmp))
240 return string2type(tmp, flag);
244 bool getTokenValue(string const & str, const char * token, LyXLength & len)
246 // set the lenght to be zero() as default as this it should be if not
247 // in the file format.
250 if (!getTokenValue(str, token, tmp))
252 return isValidLength(tmp, &len);
256 void l_getline(istream & is, string & str)
259 while (str.empty()) {
261 if (!str.empty() && str[str.length() - 1] == '\r')
262 str.erase(str.length() - 1);