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 * ======================================================
16 #pragma implementation
19 #include "tabular_funcs.h"
21 #include "support/lstrings.h"
22 #include "support/LIstream.h"
26 // Perfect case for a template... (Lgb)
30 string const write_attribute(string const & name, bool const & b)
32 return write_attribute(name, int(b));
36 string const write_attribute(string const & name, LyXLength const & value)
38 return write_attribute(name, value.asString());
41 string const tostr(LyXAlignment const & num)
50 case LYX_ALIGN_CENTER:
54 case LYX_ALIGN_LAYOUT:
56 case LYX_ALIGN_SPECIAL:
63 string const tostr(LyXTabular::VAlignment const & num)
66 case LyXTabular::LYX_VALIGN_TOP:
68 case LyXTabular::LYX_VALIGN_CENTER:
70 case LyXTabular::LYX_VALIGN_BOTTOM:
77 string const tostr(LyXTabular::BoxType const & num)
80 case LyXTabular::BOX_NONE:
82 case LyXTabular::BOX_PARBOX:
84 case LyXTabular::BOX_MINIPAGE:
90 // I would have liked a fromstr template a lot better. (Lgb)
91 bool string2type(string const str, LyXAlignment & num)
95 else if (str == "block")
96 num = LYX_ALIGN_BLOCK;
97 else if (str == "left")
99 else if (str == "center")
100 num = LYX_ALIGN_CENTER;
101 else if (str == "right")
102 num = LYX_ALIGN_RIGHT;
109 bool string2type(string const str, LyXTabular::VAlignment & num)
112 num = LyXTabular::LYX_VALIGN_TOP;
113 else if (str == "center")
114 num = LyXTabular::LYX_VALIGN_CENTER;
115 else if (str == "bottom")
116 num = LyXTabular::LYX_VALIGN_BOTTOM;
123 bool string2type(string const str, LyXTabular::BoxType & num)
126 num = LyXTabular::BOX_NONE;
127 else if (str == "parbox")
128 num = LyXTabular::BOX_PARBOX;
129 else if (str == "minipage")
130 num = LyXTabular::BOX_MINIPAGE;
137 bool string2type(string const str, bool & num)
141 else if (str == "false")
149 bool getTokenValue(string const & str, const char * token, string & ret)
151 size_t token_length = strlen(token);
152 string::size_type pos = str.find(token);
154 if (pos == string::npos || pos + token_length + 1 >= str.length()
155 || str[pos + token_length] != '=')
158 pos += token_length + 1;
160 if ((ch != '"') && (ch != '\'')) { // only read till next space
164 while ((pos < str.length() - 1) && (str[++pos] != ch))
171 bool getTokenValue(string const & str, const char * token, int & num)
174 if (!getTokenValue(str, token, tmp))
181 bool getTokenValue(string const & str, const char * token, LyXAlignment & num)
184 if (!getTokenValue(str, token, tmp))
186 return string2type(tmp, num);
190 bool getTokenValue(string const & str, const char * token,
191 LyXTabular::VAlignment & num)
194 if (!getTokenValue(str, token, tmp))
196 return string2type(tmp, num);
200 bool getTokenValue(string const & str, const char * token,
201 LyXTabular::BoxType & num)
204 if (!getTokenValue(str, token, tmp))
206 return string2type(tmp, num);
210 bool getTokenValue(string const & str, const char * token, bool & flag)
213 if (!getTokenValue(str, token, tmp))
215 return string2type(tmp, flag);
219 bool getTokenValue(string const & str, const char * token, LyXLength & len)
222 if (!getTokenValue(str, token, tmp))
224 return isValidLength(tmp, &len);
228 void l_getline(istream & is, string & str)
231 while (str.empty()) {
233 if (!str.empty() && str[str.length() - 1] == '\r')
234 str.erase(str.length() - 1);