+ while (pos < str.length() - 1 && str[++pos] != ch)
+ ret += str[pos];
+
+ return true;
+}
+
+
+bool getTokenValue(string const & str, char const * token, int & num)
+{
+ string tmp;
+ num = 0;
+ if (!getTokenValue(str, token, tmp))
+ return false;
+ num = convert<int>(tmp);
+ return true;
+}
+
+
+bool getTokenValue(string const & str, char const * token, LyXAlignment & num)
+{
+ string tmp;
+ return getTokenValue(str, token, tmp) && string2type(tmp, num);
+}
+
+
+bool getTokenValue(string const & str, char const * token,
+ LyXTabular::VAlignment & num)
+{
+ string tmp;
+ return getTokenValue(str, token, tmp) && string2type(tmp, num);
+}
+
+
+bool getTokenValue(string const & str, char const * token,
+ LyXTabular::BoxType & num)
+{
+ string tmp;
+ return getTokenValue(str, token, tmp) && string2type(tmp, num);
+}
+
+
+bool getTokenValue(string const & str, char const * token, bool & flag)
+{
+ // set the flag always to false as this should be the default for bools
+ // not in the file-format.
+ flag = false;
+ string tmp;
+ return getTokenValue(str, token, tmp) && string2type(tmp, flag);
+}
+
+
+bool getTokenValue(string const & str, char const * token, LyXLength & len)
+{
+ // set the lenght to be zero() as default as this it should be if not
+ // in the file format.
+ len = LyXLength();
+ string tmp;
+ return getTokenValue(str, token, tmp) && isValidLength(tmp, &len);
+}
+
+
+bool getTokenValue(string const & str, char const * token, LyXLength & len, bool & flag)
+{
+ len = LyXLength();
+ flag = false;
+ string tmp;
+ if (!getTokenValue(str, token, tmp))
+ return false;
+ if (tmp == "default") {
+ flag = true;
+ return true;
+ }
+ return isValidLength(tmp, &len);
+}
+
+
+void l_getline(istream & is, string & str)
+{
+ str.erase();
+ while (str.empty()) {
+ getline(is, str);
+ if (!str.empty() && str[str.length() - 1] == '\r')
+ str.erase(str.length() - 1);
+ }
+}
+
+} // namespace
+
+/// Define a few methods for the inner structs
+
+LyXTabular::cellstruct::cellstruct(BufferParams const & bp)
+ : cellno(0),
+ width_of_cell(0),
+ multicolumn(LyXTabular::CELL_NORMAL),
+ alignment(LYX_ALIGN_CENTER),
+ valignment(LYX_VALIGN_TOP),
+ top_line(true),
+ bottom_line(false),
+ left_line(true),
+ right_line(false),
+ usebox(BOX_NONE),
+ rotate(false),
+ inset(new InsetText(bp))
+{}
+
+
+LyXTabular::cellstruct::cellstruct(cellstruct const & cs)
+ : cellno(cs.cellno),
+ width_of_cell(cs.width_of_cell),
+ multicolumn(cs.multicolumn),
+ alignment(cs.alignment),
+ valignment(cs.valignment),
+ top_line(cs.top_line),
+ bottom_line(cs.bottom_line),
+ left_line(cs.left_line),
+ right_line(cs.right_line),
+ usebox(cs.usebox),
+ rotate(cs.rotate),
+ align_special(cs.align_special),
+ p_width(cs.p_width),
+ inset(dynamic_cast<InsetText*>(cs.inset->clone().release()))
+{}
+
+
+LyXTabular::cellstruct &
+LyXTabular::cellstruct::operator=(cellstruct cs)
+{
+ swap(cs);
+ return *this;
+}
+
+
+void
+LyXTabular::cellstruct::swap(cellstruct & rhs)
+{
+ std::swap(cellno, rhs.cellno);
+ std::swap(width_of_cell, rhs.width_of_cell);
+ std::swap(multicolumn, rhs.multicolumn);
+ std::swap(alignment, rhs.alignment);
+ std::swap(valignment, rhs.valignment);
+ std::swap(top_line, rhs.top_line);
+ std::swap(bottom_line, rhs.bottom_line);
+ std::swap(left_line, rhs.left_line);
+ std::swap(right_line, rhs.right_line);
+ std::swap(usebox, rhs.usebox);
+ std::swap(rotate, rhs.rotate);
+ std::swap(align_special, rhs.align_special);
+ p_width.swap(rhs.p_width);
+ inset.swap(rhs.inset);
+}
+
+
+LyXTabular::rowstruct::rowstruct()
+ : ascent_of_row(0),
+ descent_of_row(0),
+ top_line(true),
+ bottom_line(false),
+ top_space_default(false),
+ bottom_space_default(false),
+ interline_space_default(false),
+ endhead(false),
+ endfirsthead(false),
+ endfoot(false),
+ endlastfoot(false),
+ newpage(false)
+{}
+
+
+LyXTabular::columnstruct::columnstruct()
+ : alignment(LYX_ALIGN_CENTER),
+ valignment(LYX_VALIGN_TOP),
+ left_line(true),
+ right_line(false),
+ width_of_column(0)
+{
+}
+
+
+LyXTabular::ltType::ltType()
+ : topDL(false),
+ bottomDL(false),
+ empty(false)
+{}
+
+
+LyXTabular::LyXTabular(BufferParams const & bp, row_type rows_arg,
+ col_type columns_arg)
+{
+ init(bp, rows_arg, columns_arg);