From 1f3c320719450029915b042534d224be34c56e80 Mon Sep 17 00:00:00 2001 From: Angus Leeming Date: Wed, 6 Nov 2002 15:40:12 +0000 Subject: [PATCH] Rearrange code in readiness for a larger patch. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@5591 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/frontends/controllers/biblio.C | 226 +++++++++++++++-------------- 1 file changed, 114 insertions(+), 112 deletions(-) diff --git a/src/frontends/controllers/biblio.C b/src/frontends/controllers/biblio.C index 564f474fb9..99d643b5c1 100644 --- a/src/frontends/controllers/biblio.C +++ b/src/frontends/controllers/biblio.C @@ -26,122 +26,10 @@ #include -using std::find; -using std::min; using std::vector; namespace biblio { -namespace { - -using namespace biblio; - -char const * const citeCommands[] = { - "cite", "citet", "citep", "citealt", "citealp", "citeauthor", - "citeyear", "citeyearpar" }; - -unsigned int const nCiteCommands = - sizeof(citeCommands) / sizeof(char *); - -CiteStyle const citeStyles[] = { - CITE, CITET, CITEP, CITEALT, CITEALP, - CITEAUTHOR, CITEYEAR, CITEYEARPAR }; - -unsigned int const nCiteStyles = - sizeof(citeStyles) / sizeof(CiteStyle); - -CiteStyle const citeStylesFull[] = { - CITET, CITEP, CITEALT, CITEALP, CITEAUTHOR }; - -unsigned int const nCiteStylesFull = - sizeof(citeStylesFull) / sizeof(CiteStyle); - -CiteStyle const citeStylesUCase[] = { - CITET, CITEP, CITEALT, CITEALP, CITEAUTHOR }; - -unsigned int const nCiteStylesUCase = - sizeof(citeStylesUCase) / sizeof(CiteStyle); - - -// The functions doing the dirty work for the search. -vector::const_iterator -simpleSearch(InfoMap const & theMap, - vector const & keys, - string const & expr, - vector::const_iterator start, - Direction dir, - bool caseSensitive) -{ - string tmp = expr; - if (!caseSensitive) - tmp = lowercase(tmp); - - vector searchwords = getVectorFromString(tmp, " "); - - // Loop over all keys from start... - for (vector::const_iterator it = start; - // End condition is direction-dependent. - (dir == FORWARD) ? (it=keys.begin()); - // increment is direction-dependent. - (dir == FORWARD) ? (++it) : (--it)) { - - string data = (*it); - InfoMap::const_iterator info = theMap.find(*it); - if (info != theMap.end()) - data += " " + info->second; - if (!caseSensitive) - data = lowercase(data); - - bool found = true; - - // Loop over all search words... - for (vector::const_iterator sit = searchwords.begin(); - sit != searchwords.end(); ++sit) { - if (data.find(*sit) == string::npos) { - found = false; - break; - } - } - - if (found) return it; - } - - return keys.end(); -} - - -vector::const_iterator -regexSearch(InfoMap const & theMap, - vector const & keys, - string const & expr, - vector::const_iterator start, - Direction dir) -{ - boost::regex reg(STRCONV(expr)); - - for (vector::const_iterator it = start; - // End condition is direction-dependent. - (dir == FORWARD) ? (it < keys.end()) : (it >= keys.begin()); - // increment is direction-dependent. - (dir == FORWARD) ? (++it) : (--it)) { - - string data = (*it); - InfoMap::const_iterator info = theMap.find(*it); - if (info != theMap.end()) - data += " " + info->second; - - if (boost::regex_match(STRCONV(data), reg)) { - return it; - } - } - - return keys.end(); -} - - -} // namespace anon - - string const familyName(string const & name) { // Very simple parser @@ -348,6 +236,87 @@ string const getInfo(InfoMap const & map, string const & key) } +namespace { + +// The functions doing the dirty work for the search. +vector::const_iterator +simpleSearch(InfoMap const & theMap, + vector const & keys, + string const & expr, + vector::const_iterator start, + Direction dir, + bool caseSensitive) +{ + string tmp = expr; + if (!caseSensitive) + tmp = lowercase(tmp); + + vector searchwords = getVectorFromString(tmp, " "); + + // Loop over all keys from start... + for (vector::const_iterator it = start; + // End condition is direction-dependent. + (dir == FORWARD) ? (it=keys.begin()); + // increment is direction-dependent. + (dir == FORWARD) ? (++it) : (--it)) { + + string data = (*it); + InfoMap::const_iterator info = theMap.find(*it); + if (info != theMap.end()) + data += " " + info->second; + if (!caseSensitive) + data = lowercase(data); + + bool found = true; + + // Loop over all search words... + for (vector::const_iterator sit = searchwords.begin(); + sit != searchwords.end(); ++sit) { + if (data.find(*sit) == string::npos) { + found = false; + break; + } + } + + if (found) return it; + } + + return keys.end(); +} + + +vector::const_iterator +regexSearch(InfoMap const & theMap, + vector const & keys, + string const & expr, + vector::const_iterator start, + Direction dir) +{ + boost::regex reg(STRCONV(expr)); + + for (vector::const_iterator it = start; + // End condition is direction-dependent. + (dir == FORWARD) ? (it < keys.end()) : (it >= keys.begin()); + // increment is direction-dependent. + (dir == FORWARD) ? (++it) : (--it)) { + + string data = (*it); + InfoMap::const_iterator info = theMap.find(*it); + if (info != theMap.end()) + data += " " + info->second; + + if (boost::regex_match(STRCONV(data), reg)) { + return it; + } + } + + return keys.end(); +} + + +} // namespace anon + + vector::const_iterator searchKeys(InfoMap const & theMap, vector const & keys, @@ -503,6 +472,39 @@ string const parseBibTeX(string data, string const & findkey) } +namespace { + +using namespace biblio; + +char const * const citeCommands[] = { + "cite", "citet", "citep", "citealt", "citealp", "citeauthor", + "citeyear", "citeyearpar" }; + +unsigned int const nCiteCommands = + sizeof(citeCommands) / sizeof(char *); + +CiteStyle const citeStyles[] = { + CITE, CITET, CITEP, CITEALT, CITEALP, + CITEAUTHOR, CITEYEAR, CITEYEARPAR }; + +unsigned int const nCiteStyles = + sizeof(citeStyles) / sizeof(CiteStyle); + +CiteStyle const citeStylesFull[] = { + CITET, CITEP, CITEALT, CITEALP, CITEAUTHOR }; + +unsigned int const nCiteStylesFull = + sizeof(citeStylesFull) / sizeof(CiteStyle); + +CiteStyle const citeStylesUCase[] = { + CITET, CITEP, CITEALT, CITEALP, CITEAUTHOR }; + +unsigned int const nCiteStylesUCase = + sizeof(citeStylesUCase) / sizeof(CiteStyle); + +} // namespace anon + + CitationStyle const getCitationStyle(string const & command) { if (command.empty()) return CitationStyle(); -- 2.39.5