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"
27 // Perfect case for a template... (Lgb)
31 string const write_attribute(string const & name, bool const & b)
33 return write_attribute(name, int(b));
37 string const write_attribute(string const & name, LyXLength const & value)
39 return write_attribute(name, value.asString());
42 string const tostr(LyXAlignment const & num)
51 case LYX_ALIGN_CENTER:
55 case LYX_ALIGN_LAYOUT:
57 case LYX_ALIGN_SPECIAL:
64 string const tostr(LyXTabular::VAlignment const & num)
67 case LyXTabular::LYX_VALIGN_TOP:
69 case LyXTabular::LYX_VALIGN_CENTER:
71 case LyXTabular::LYX_VALIGN_BOTTOM:
78 string const tostr(LyXTabular::BoxType const & num)
81 case LyXTabular::BOX_NONE:
83 case LyXTabular::BOX_PARBOX:
85 case LyXTabular::BOX_MINIPAGE:
91 // I would have liked a fromstr template a lot better. (Lgb)
92 bool string2type(string const str, LyXAlignment & num)
96 else if (str == "block")
97 num = LYX_ALIGN_BLOCK;
98 else if (str == "left")
100 else if (str == "center")
101 num = LYX_ALIGN_CENTER;
102 else if (str == "right")
103 num = LYX_ALIGN_RIGHT;
110 bool string2type(string const str, LyXTabular::VAlignment & num)
113 num = LyXTabular::LYX_VALIGN_TOP;
114 else if (str == "center")
115 num = LyXTabular::LYX_VALIGN_CENTER;
116 else if (str == "bottom")
117 num = LyXTabular::LYX_VALIGN_BOTTOM;
124 bool string2type(string const str, LyXTabular::BoxType & num)
127 num = LyXTabular::BOX_NONE;
128 else if (str == "parbox")
129 num = LyXTabular::BOX_PARBOX;
130 else if (str == "minipage")
131 num = LyXTabular::BOX_MINIPAGE;
138 bool string2type(string const str, bool & num)
142 else if (str == "false")
150 bool getTokenValue(string const & str, const char * token, string & ret)
152 size_t token_length = strlen(token);
153 string::size_type pos = str.find(token);
155 if (pos == string::npos || pos + token_length + 1 >= str.length()
156 || str[pos + token_length] != '=')
159 pos += token_length + 1;
161 if ((ch != '"') && (ch != '\'')) { // only read till next space
165 while ((pos < str.length() - 1) && (str[++pos] != ch))
172 bool getTokenValue(string const & str, const char * token, int & num)
175 if (!getTokenValue(str, token, tmp))
182 bool getTokenValue(string const & str, const char * token, LyXAlignment & num)
185 if (!getTokenValue(str, token, tmp))
187 return string2type(tmp, num);
191 bool getTokenValue(string const & str, const char * token,
192 LyXTabular::VAlignment & num)
195 if (!getTokenValue(str, token, tmp))
197 return string2type(tmp, num);
201 bool getTokenValue(string const & str, const char * token,
202 LyXTabular::BoxType & num)
205 if (!getTokenValue(str, token, tmp))
207 return string2type(tmp, num);
211 bool getTokenValue(string const & str, const char * token, bool & flag)
214 if (!getTokenValue(str, token, tmp))
216 return string2type(tmp, flag);
220 bool getTokenValue(string const & str, const char * token, LyXLength & len)
223 if (!getTokenValue(str, token, tmp))
225 return isValidLength(tmp, &len);
229 void l_getline(istream & is, string & str)
232 while (str.empty()) {
234 if (!str.empty() && str[str.length() - 1] == '\r')
235 str.erase(str.length() - 1);