From 5216137bdb1a894f1896bdedbfb28f7b192758e7 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Andr=C3=A9=20P=C3=B6nitz?= Date: Mon, 5 Nov 2007 20:33:20 +0000 Subject: [PATCH] cosmetics as hinted by uncrustify git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@21450 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/BiblioInfo.cpp | 147 +++++++++++++++++++++++---------------------- src/Buffer.cpp | 23 +++---- 2 files changed, 87 insertions(+), 83 deletions(-) diff --git a/src/BiblioInfo.cpp b/src/BiblioInfo.cpp index a6113cf509..4718d37ed2 100644 --- a/src/BiblioInfo.cpp +++ b/src/BiblioInfo.cpp @@ -37,19 +37,21 @@ using std::endl; using std::set; namespace lyx { + using support::bformat; using support::compare_no_case; using support::getVectorFromString; using support::ltrim; using support::rtrim; -//////////////////////////////////////// +////////////////////////////////////////////////////////////////////// // // BibTeXInfo // -//////////////////////////////////////// +////////////////////////////////////////////////////////////////////// -BibTeXInfo::BibTeXInfo() : isBibTeX(true) +BibTeXInfo::BibTeXInfo() + : isBibTeX(true) {} @@ -75,33 +77,30 @@ docstring const & BibTeXInfo::getValueForField(string const & field) const } -namespace { - docstring const familyName(docstring const & name) - { - if (name.empty()) - return docstring(); - - // Very simple parser - docstring fname = name; - - // possible authorname combinations are: - // "Surname, FirstName" - // "Surname, F." - // "FirstName Surname" - // "F. Surname" - docstring::size_type idx = fname.find(','); - if (idx != docstring::npos) - return ltrim(fname.substr(0, idx)); - idx = fname.rfind('.'); - if (idx != docstring::npos && idx + 1 < fname.size()) - fname = ltrim(fname.substr(idx + 1)); - // test if we have a LaTeX Space in front - if (fname[0] == '\\') - return fname.substr(2); - return rtrim(fname); - } -} // namespace anon +static docstring familyName(docstring const & name) +{ + if (name.empty()) + return docstring(); + // Very simple parser + docstring fname = name; + + // possible authorname combinations are: + // "Surname, FirstName" + // "Surname, F." + // "FirstName Surname" + // "F. Surname" + docstring::size_type idx = fname.find(','); + if (idx != docstring::npos) + return ltrim(fname.substr(0, idx)); + idx = fname.rfind('.'); + if (idx != docstring::npos && idx + 1 < fname.size()) + fname = ltrim(fname.substr(idx + 1)); + // test if we have a LaTeX Space in front + if (fname[0] == '\\') + return fname.substr(2); + return rtrim(fname); +} docstring const BibTeXInfo::getAbbreviatedAuthor() const @@ -117,20 +116,22 @@ docstring const BibTeXInfo::getAbbreviatedAuthor() const return bibKey; } - //OK, we've got some names. Let's format them. - //Try to split the author list on " and " + // OK, we've got some names. Let's format them. + // Try to split the author list on " and " vector const authors = getVectorFromString(author, from_ascii(" and ")); if (authors.size() == 2) return bformat(_("%1$s and %2$s"), familyName(authors[0]), familyName(authors[1])); - else if (authors.size() > 2) + + if (authors.size() > 2) return bformat(_("%1$s et al."), familyName(authors[0])); - else - return familyName(authors[0]); + + return familyName(authors[0]); } + docstring const BibTeXInfo::getYear() const { if (!isBibTeX) @@ -150,11 +151,11 @@ docstring const BibTeXInfo::getInfo() const return it->second; } - //FIXME - //This could be made alot better using the entryType - //field to customize the output based upon entry type. + // FIXME + // This could be made a lot better using the entryType + // field to customize the output based upon entry type. - //Search for all possible "required" fields + // Search for all possible "required" fields docstring author = getValueForField("author"); if (author.empty()) author = getValueForField("editor"); @@ -166,45 +167,47 @@ docstring const BibTeXInfo::getInfo() const docLoc = getValueForField("chapter"); if (!docLoc.empty()) docLoc = from_ascii("Ch. ") + docLoc; - } else + } else { docLoc = from_ascii("pp. ") + docLoc; - docstring media = getValueForField("journal"); + } + + docstring media = getValueForField("journal"); + if (media.empty()) { + media = getValueForField("publisher"); if (media.empty()) { - media = getValueForField("publisher"); - if (media.empty()) { - media = getValueForField("school"); - if (media.empty()) - media = getValueForField("institution"); - } + media = getValueForField("school"); + if (media.empty()) + media = getValueForField("institution"); } - docstring volume = getValueForField("volume"); - - odocstringstream result; - if (!author.empty()) - result << author << ", "; - if (!title.empty()) - result << title; - if (!media.empty()) - result << ", " << media; - if (!year.empty()) - result << ", " << year; - if (!docLoc.empty()) - result << ", " << docLoc; - - docstring const result_str = rtrim(result.str()); - if (!result_str.empty()) - return result_str; - - // This should never happen (or at least be very unusual!) - return docstring(); + } + docstring volume = getValueForField("volume"); + + odocstringstream result; + if (!author.empty()) + result << author << ", "; + if (!title.empty()) + result << title; + if (!media.empty()) + result << ", " << media; + if (!year.empty()) + result << ", " << year; + if (!docLoc.empty()) + result << ", " << docLoc; + + docstring const result_str = rtrim(result.str()); + if (!result_str.empty()) + return result_str; + + // This should never happen (or at least be very unusual!) + return docstring(); } -//////////////////////////////////////// +////////////////////////////////////////////////////////////////////// // // BiblioInfo // -//////////////////////////////////////// +////////////////////////////////////////////////////////////////////// namespace { // A functor for use with std::sort, leading to case insensitive sorting @@ -309,7 +312,7 @@ vector const BiblioInfo::getNumericalStrings( biblio::getCiteStyles(buf.params().getEngine()); vector vec(styles.size()); - for (vector::size_type i = 0; i != vec.size(); ++i) { + for (size_t i = 0; i != vec.size(); ++i) { docstring str; switch (styles[i]) { @@ -430,11 +433,11 @@ void BiblioInfo::fillWithBibKeys(Buffer const * const buf) namespace biblio { -//////////////////////////////////////// +////////////////////////////////////////////////////////////////////// // // CitationStyle // -//////////////////////////////////////// +////////////////////////////////////////////////////////////////////// namespace { @@ -539,7 +542,7 @@ vector const getCiteStyles(CiteEngine const engine) typedef vector cite_vec; cite_vec styles(nStyles); - cite_vec::size_type i = 0; + size_t i = 0; int j = start; for (; i != styles.size(); ++i, ++j) styles[i] = citeStyles[j]; diff --git a/src/Buffer.cpp b/src/Buffer.cpp index 8ad8abf671..34e55b1fa7 100644 --- a/src/Buffer.cpp +++ b/src/Buffer.cpp @@ -157,7 +157,7 @@ namespace fs = boost::filesystem; namespace { -int const LYX_FORMAT = 299; //Uwe: Hyperlink types +int const LYX_FORMAT = 299; // Uwe: Hyperlink types } // namespace anon @@ -1770,12 +1770,12 @@ bool Buffer::hasMacro(docstring const & name, Paragraph const & par) const { Impl::PositionToMacroMap::iterator it; it = pimpl_->macros[name].upper_bound(par.macrocontextPosition()); - if( it != pimpl_->macros[name].end() ) + if (it != pimpl_->macros[name].end()) return true; // If there is a master buffer, query that - const Buffer *master = masterBuffer(); - if (master && master!=this) + const Buffer * master = masterBuffer(); + if (master && master != this) return master->hasMacro(name); return MacroTable::globalMacros().has(name); @@ -1788,15 +1788,16 @@ bool Buffer::hasMacro(docstring const & name) const return true; // If there is a master buffer, query that - const Buffer *master = masterBuffer(); - if (master && master!=this) + const Buffer * master = masterBuffer(); + if (master && master != this) return master->hasMacro(name); return MacroTable::globalMacros().has(name); } -MacroData const & Buffer::getMacro(docstring const & name, Paragraph const & par) const +MacroData const & Buffer::getMacro(docstring const & name, + Paragraph const & par) const { Impl::PositionToMacroMap::iterator it; it = pimpl_->macros[name].upper_bound(par.macrocontextPosition()); @@ -1804,8 +1805,8 @@ MacroData const & Buffer::getMacro(docstring const & name, Paragraph const & par return it->second; // If there is a master buffer, query that - const Buffer *master = masterBuffer(); - if (master && master!=this) + const Buffer * master = masterBuffer(); + if (master && master != this) return master->getMacro(name); return MacroTable::globalMacros().get(name); @@ -1820,8 +1821,8 @@ MacroData const & Buffer::getMacro(docstring const & name) const return it->second; // If there is a master buffer, query that - const Buffer *master = masterBuffer(); - if (master && master!=this) + const Buffer * master = masterBuffer(); + if (master && master != this) return master->getMacro(name); return MacroTable::globalMacros().get(name); -- 2.39.5