]> git.lyx.org Git - lyx.git/blobdiff - src/insets/InsetCommandParams.cpp
Routines for calculating numerical labels for BibTeX citations.
[lyx.git] / src / insets / InsetCommandParams.cpp
index dfbc902b9858d3da95b7d1acf735dd4568949614..13e31a7b0097ff0ac6e75fb0b8ab0f0da615bd80 100644 (file)
@@ -35,7 +35,7 @@
 #include "support/gettext.h"
 #include "support/lstrings.h"
 
-#include <boost/assert.hpp>
+#include "support/lassert.h"
 
 using namespace std;
 using namespace lyx::support;
@@ -55,7 +55,7 @@ static ParamInfo const & findInfo(InsetCode code, string const & cmdName)
        case BIBTEX_CODE:
                return InsetBibtex::findInfo(cmdName);
        case CITE_CODE:
-               return InsetCitation::findInfo(cmdName);        
+               return InsetCitation::findInfo(cmdName);
        case FLOAT_LIST_CODE:
                return InsetFloatList::findInfo(cmdName);
        case HYPERLINK_CODE:
@@ -65,7 +65,7 @@ static ParamInfo const & findInfo(InsetCode code, string const & cmdName)
        case INDEX_PRINT_CODE:
                return InsetPrintIndex::findInfo(cmdName);
        case LABEL_CODE:
-               return InsetLabel::findInfo(cmdName);   
+               return InsetLabel::findInfo(cmdName);
        case NOMENCL_CODE:
                return InsetNomencl::findInfo(cmdName);
        case NOMENCL_PRINT_CODE:
@@ -75,7 +75,7 @@ static ParamInfo const & findInfo(InsetCode code, string const & cmdName)
        case TOC_CODE:
                return InsetTOC::findInfo(cmdName);
        default:
-               BOOST_ASSERT(false);
+               LASSERT(false, /**/);
        }
        static const ParamInfo pi;
        return pi; // to silence the warning
@@ -134,7 +134,7 @@ bool ParamInfo::operator==(ParamInfo const & rhs) const
 ParamInfo::ParamData const & 
        ParamInfo::operator[](std::string const & name) const
 {
-       BOOST_ASSERT(hasParam(name));
+       LASSERT(hasParam(name), /**/);
        const_iterator it = begin();
        const_iterator last = end();
        for (; it != last; ++it) {
@@ -202,7 +202,7 @@ string InsetCommandParams::getDefaultCmd(InsetCode code)
                case TOC_CODE:
                        return InsetTOC::defaultCommand();
                default:
-                       BOOST_ASSERT(false);
+                       LASSERT(false, /**/);
        }
        return string(); // silence the warning
 }
@@ -236,7 +236,7 @@ bool InsetCommandParams::isCompatibleCommand(InsetCode code, string const & s)
                case TOC_CODE:
                        return InsetTOC::isCompatibleCommand(s);
                default:
-                       BOOST_ASSERT(false);
+                       LASSERT(false, /**/);
        }
        return false; // silence the warning
 }
@@ -258,30 +258,12 @@ void InsetCommandParams::setCmdName(string const & name)
 
 void InsetCommandParams::read(Lexer & lex)
 {
-       if (lex.isOK()) {
-               lex.next();
-               string const insetType = lex.getString();
-               InsetCode const code = insetCode(insetType);
-               if (code != insetCode_) {
-                       lex.printError("InsetCommandParams: Attempt to change type of inset.");
-                       throw ExceptionMessage(WarningException, _("InsetCommandParams Error: "),
-                                        _("Attempt to change type of parameters."));
-               }
-       }
-
-       if (lex.isOK()) {
-               lex.next();
-               string const test = lex.getString();
-               if (test != "LatexCommand") {
-                       lex.printError("InsetCommandParams: No LatexCommand line found.");
-                       throw ExceptionMessage(WarningException, _("InsetCommandParams error: "),
-                                              _("Can't find LatexCommand line."));
-               }
-       }
-       lex.next();
-       cmdName_ = lex.getString();
-       if (!isCompatibleCommand(insetCode_, cmdName_)){
-               lex.printError("InsetCommandParams: Incompatible command name " + cmdName_ + ".");
+       lex.setContext("InsetCommandParams::read");
+       lex >> insetName(insetCode_).c_str();
+       lex >> "LatexCommand";
+       lex >> cmdName_;
+       if (!isCompatibleCommand(insetCode_, cmdName_)) {
+               lex.printError("Incompatible command name " + cmdName_ + ".");
                throw ExceptionMessage(WarningException, _("InsetCommandParams Error: "),
                                       _("Incompatible command name."));
        }
@@ -313,8 +295,8 @@ void InsetCommandParams::read(Lexer & lex)
                lex.printError("Missing \\end_inset at this point. "
                               "Read: `$$Token'");
                throw ExceptionMessage(WarningException,
-                       _("Missing \\end_inset at this point."),
-                       from_utf8(token));
+                       _("InsetCommandParams Error: "),
+                       _("Missing \\end_inset at this point: ") + from_utf8(token));
        }
 }
 
@@ -342,8 +324,9 @@ void InsetCommandParams::write(ostream & os) const
 
 bool InsetCommandParams::writeEmptyOptional(ParamInfo::const_iterator ci) const
 {
-       if (!ci->isOptional())
-               BOOST_ASSERT(false);
+       if (!ci->isOptional()) {
+               LASSERT(false, /**/);
+       }
        ++ci; // we want to start with the next one
        ParamInfo::const_iterator end = info_.end();
        for (; ci != end; ++ci) {
@@ -412,8 +395,9 @@ docstring InsetCommandParams::getFirstNonOptParam() const
        ParamInfo::const_iterator it = 
                find_if(info_.begin(), info_.end(), 
                        not1(mem_fun_ref(&ParamInfo::ParamData::isOptional)));
-       if (it == info_.end())
-               BOOST_ASSERT(false);
+       if (it == info_.end()) {
+               LASSERT(false, return docstring());
+       }
        return (*this)[it->name()];
 }
 
@@ -421,7 +405,7 @@ docstring InsetCommandParams::getFirstNonOptParam() const
 docstring const & InsetCommandParams::operator[](string const & name) const
 {
        static const docstring dummy; //so we don't return a ref to temporary
-       BOOST_ASSERT(info_.hasParam(name));
+       LASSERT(info_.hasParam(name), return dummy);
        ParamMap::const_iterator data = params_.find(name);
        if (data == params_.end() || data->second.empty())
                return dummy;
@@ -431,7 +415,7 @@ docstring const & InsetCommandParams::operator[](string const & name) const
 
 docstring & InsetCommandParams::operator[](string const & name)
 {
-       BOOST_ASSERT(info_.hasParam(name));
+       LASSERT(info_.hasParam(name), /**/);
        return params_[name];
 }