X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Ftabular_funcs.C;h=dd1a2a01c5696dc07158c1b5beb6c860dea684f7;hb=98c966c64594611e469313314abd1e59524adb4a;hp=78181137e1663ce0d64193f6ad26297cd688cb33;hpb=feed97be54568a15cda31f309d58f029f0d10daf;p=lyx.git diff --git a/src/tabular_funcs.C b/src/tabular_funcs.C index 78181137e1..dd1a2a01c5 100644 --- a/src/tabular_funcs.C +++ b/src/tabular_funcs.C @@ -1,13 +1,13 @@ /* This file is part of - * ====================================================== - * + * ====================================================== + * * LyX, The Document Processor - * + * * Copyright 2000-2001 The LyX Team. * * @author: Jürgen Vigna * - * ====================================================== + * ====================================================== */ #include @@ -17,33 +17,51 @@ #endif #include "tabular_funcs.h" + #include "support/lstrings.h" +#include "support/LIstream.h" +using std::istream; +using std::getline; // Perfect case for a template... (Lgb) // or perhaps not... -template -string const write_attribute(string const & name, T const & t) + +template <> +string const write_attribute(string const & name, bool const & b) { - string str = " " + name + "=\"" + tostr(t) + "\""; - return str; + // we write only true attribute values so we remove a bit of the + // file format bloat for tabulars. + if (!b) + return string(); + + return write_attribute(name, tostr(b)); } template <> -string const write_attribute(string const & name, bool const & b) +string const write_attribute(string const & name, int const & i) { - return write_attribute(name, int(b)); + // we write only true attribute values so we remove a bit of the + // file format bloat for tabulars. + if (!i) + return string(); + + return write_attribute(name, tostr(i)); } template <> string const write_attribute(string const & name, LyXLength const & value) { + // we write only the value if we really have one same reson as above. + if (value.zero()) + return string(); + return write_attribute(name, value.asString()); } string const tostr(LyXAlignment const & num) { - switch(num) { + switch (num) { case LYX_ALIGN_NONE: return "none"; case LYX_ALIGN_BLOCK: @@ -65,7 +83,7 @@ string const tostr(LyXAlignment const & num) string const tostr(LyXTabular::VAlignment const & num) { - switch(num) { + switch (num) { case LyXTabular::LYX_VALIGN_TOP: return "top"; case LyXTabular::LYX_VALIGN_CENTER: @@ -79,7 +97,7 @@ string const tostr(LyXTabular::VAlignment const & num) string const tostr(LyXTabular::BoxType const & num) { - switch(num) { + switch (num) { case LyXTabular::BOX_NONE: return "none"; case LyXTabular::BOX_PARBOX: @@ -151,13 +169,13 @@ bool string2type(string const str, bool & num) bool getTokenValue(string const & str, const char * token, string & ret) { + ret.erase(); size_t token_length = strlen(token); string::size_type pos = str.find(token); if (pos == string::npos || pos + token_length + 1 >= str.length() || str[pos + token_length] != '=') return false; - ret.erase(); pos += token_length + 1; char ch = str[pos]; if ((ch != '"') && (ch != '\'')) { // only read till next space @@ -174,6 +192,7 @@ bool getTokenValue(string const & str, const char * token, string & ret) bool getTokenValue(string const & str, const char * token, int & num) { string tmp; + num = 0; if (!getTokenValue(str, token, tmp)) return false; num = strToInt(tmp); @@ -212,20 +231,26 @@ bool getTokenValue(string const & str, const char * token, bool getTokenValue(string const & str, const char * 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; if (!getTokenValue(str, token, tmp)) return false; return string2type(tmp, flag); -} +} bool getTokenValue(string const & str, const char * 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; if (!getTokenValue(str, token, tmp)) return false; return isValidLength(tmp, &len); -} +} void l_getline(istream & is, string & str)