From 9b3f8c9819754752d9af05d07bcd5f1ff2d18840 Mon Sep 17 00:00:00 2001 From: Angus Leeming Date: Mon, 15 Apr 2002 12:05:07 +0000 Subject: [PATCH] Those parts of Herbert's natbib patch that either fix bugs or just move functions around. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@3995 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/frontends/controllers/ChangeLog | 10 ++++++ src/frontends/controllers/biblio.C | 10 ++++-- src/frontends/controllers/biblio.h | 9 +++++ src/frontends/controllers/helper_funcs.C | 44 ------------------------ src/frontends/controllers/helper_funcs.h | 10 ------ src/frontends/xforms/ChangeLog | 6 ++++ src/frontends/xforms/FormCharacter.C | 2 ++ src/frontends/xforms/FormExternal.C | 2 ++ src/support/ChangeLog | 6 ++++ src/support/lstrings.C | 43 +++++++++++++++++++++++ src/support/lstrings.h | 11 +++++- 11 files changed, 95 insertions(+), 58 deletions(-) diff --git a/src/frontends/controllers/ChangeLog b/src/frontends/controllers/ChangeLog index 2e1d53a1d2..f2730c68d7 100644 --- a/src/frontends/controllers/ChangeLog +++ b/src/frontends/controllers/ChangeLog @@ -1,3 +1,13 @@ +2002-04-14 Herbert Voss + + * helper_funcs.[Ch]: move the getVectorFromString and the vice versa + into the support/lstrings for better use in other programs. + + * biblio.[Ch] (getYear, getAbbreviatedAuthor, familyName): move out of + namespace anon and make globally accessible. + (familyName): test for the presence of a LaTeX Space at the front of + of a name; strip it if it exists. + 2002-04-11 Herbert Voss * ControlGraphics.C: expand "browse-string" to all available formats diff --git a/src/frontends/controllers/biblio.C b/src/frontends/controllers/biblio.C index 12fe7f12ef..9ed9961bfc 100644 --- a/src/frontends/controllers/biblio.C +++ b/src/frontends/controllers/biblio.C @@ -142,6 +142,10 @@ regexSearch(InfoMap const & theMap, return keys.end(); } + +} // namespace anon + + string const familyName(string const & name) { // Very simple parser @@ -158,6 +162,9 @@ string const familyName(string const & name) idx = fname.rfind("."); if (idx != string::npos) fname = frontStrip(fname.substr(idx+1)); + // test if we have a LaTeX Space in front + if (fname[0] == '\\') + return fname.substr(2); return fname; } @@ -217,9 +224,6 @@ string const getYear(InfoMap const & map, string const & key) return year; } -} // namespace anon - - // A functor for use with std::sort, leading to case insensitive sorting struct compareNoCase: public std::binary_function diff --git a/src/frontends/controllers/biblio.h b/src/frontends/controllers/biblio.h index b933aa53be..393d800400 100644 --- a/src/frontends/controllers/biblio.h +++ b/src/frontends/controllers/biblio.h @@ -60,6 +60,15 @@ namespace biblio Empty if no info exists. */ string const getInfo(InfoMap const &, string const &); + // rturn the year from the bibtex data record + string const getYear(InfoMap const & map, string const & key); + + /// return the short form of an authorlist + string const getAbbreviatedAuthor(InfoMap const & map, string const & key); + + // return only the family name + string const familyName(string const & name); + /** Search a BibTeX info field for the given key and return the associated field. */ string const parseBibTeX(string data, string const & findkey); diff --git a/src/frontends/controllers/helper_funcs.C b/src/frontends/controllers/helper_funcs.C index 7bb293c1cf..32d6ddb6bd 100644 --- a/src/frontends/controllers/helper_funcs.C +++ b/src/frontends/controllers/helper_funcs.C @@ -31,50 +31,6 @@ using std::pair; using std::vector; using std::make_pair; - -string const getStringFromVector(vector const & vec, - string const & delim) -{ - string str; - int i = 0; - for (vector::const_iterator it = vec.begin(); - it != vec.end(); ++it) { - string item = strip(frontStrip(*it)); - if (item.empty()) continue; - - if (i++ > 0) str += delim; - str += item; - } - return str; -} - -vector const getVectorFromString(string const & str, - string const & delim) -{ - vector vec; - if (str.empty()) - return vec; - - string keys(strip(str)); - - for(;;) { - string::size_type const idx = keys.find(delim); - if (idx == string::npos) { - vec.push_back(frontStrip(keys)); - break; - } - - string const key = strip(frontStrip(keys.substr(0, idx))); - if (!key.empty()) - vec.push_back(key); - - string::size_type const start = idx + delim.size(); - keys = keys.substr(start); - } - - return vec; -} - string const browseFile(LyXView * lv, string const & filename, string const & title, string const & pattern, diff --git a/src/frontends/controllers/helper_funcs.h b/src/frontends/controllers/helper_funcs.h index 2252cbcc27..eb8e77a50c 100644 --- a/src/frontends/controllers/helper_funcs.h +++ b/src/frontends/controllers/helper_funcs.h @@ -21,16 +21,6 @@ #pragma interface #endif -/** Functions to convert a string to/from a vector. */ - -/// -string const -getStringFromVector(std::vector const & vec, string const & delim=","); - -/// -std::vector const -getVectorFromString(string const & str, string const & delim=","); - class LyXView; /** Launch a file dialog and return the chosen file. diff --git a/src/frontends/xforms/ChangeLog b/src/frontends/xforms/ChangeLog index f857835ac4..f7f058ed17 100644 --- a/src/frontends/xforms/ChangeLog +++ b/src/frontends/xforms/ChangeLog @@ -1,3 +1,9 @@ +2002-04-14 Herbert Voss + + * FormCharacter.C + * FormExternal.C: adding #include "support/lstrings.h" + for the getStringFromVector and vice versa + 2002-04-12 Angus Leeming * FormParagraph.C (changedParagraph): ensure that the warning message diff --git a/src/frontends/xforms/FormCharacter.C b/src/frontends/xforms/FormCharacter.C index 371b3a91bf..d9b16cea30 100644 --- a/src/frontends/xforms/FormCharacter.C +++ b/src/frontends/xforms/FormCharacter.C @@ -23,6 +23,8 @@ #include "combox.h" #include "helper_funcs.h" +#include "support/lstrings.h" + using std::vector; using std::find; diff --git a/src/frontends/xforms/FormExternal.C b/src/frontends/xforms/FormExternal.C index 9a58f76f5e..ae325b8ddf 100644 --- a/src/frontends/xforms/FormExternal.C +++ b/src/frontends/xforms/FormExternal.C @@ -22,6 +22,8 @@ #include "xforms_helpers.h" #include "helper_funcs.h" +#include "support/lstrings.h" + typedef FormCB > base_class; FormExternal::FormExternal(ControlExternal & c) diff --git a/src/support/ChangeLog b/src/support/ChangeLog index 099ae47cca..b04d48b26c 100644 --- a/src/support/ChangeLog +++ b/src/support/ChangeLog @@ -1,3 +1,9 @@ +2002-04-14 Herbert Voss + + * lstrings.[Ch]: move the getVectorFromString and the vice versa + from frontends/controllers/helper_funcs for better use in other + programs + 2002-04-15 Angus Leeming * tempname.C (make_tempfile): simplify the #ifdef block by using diff --git a/src/support/lstrings.C b/src/support/lstrings.C index 57be367bf3..39594d53f1 100644 --- a/src/support/lstrings.C +++ b/src/support/lstrings.C @@ -27,6 +27,7 @@ using std::count; using std::transform; +using std::vector; #ifndef CXX_GLOBAL_CSTD using std::tolower; @@ -632,3 +633,45 @@ string const escape(string const & lab) } return enc; } + + +/// gives a vector of stringparts which have the delimiter delim +vector const getVectorFromString(string const & str, + string const & delim) +{ + vector vec; + if (str.empty()) + return vec; + string keys(strip(str)); + for(;;) { + string::size_type const idx = keys.find(delim); + if (idx == string::npos) { + vec.push_back(frontStrip(keys)); + break; + } + string const key = strip(frontStrip(keys.substr(0, idx))); + if (!key.empty()) + vec.push_back(key); + string::size_type const start = idx + delim.size(); + keys = keys.substr(start); + } + return vec; +} + +// the same vice versa +string const getStringFromVector(vector const & vec, + string const & delim) +{ + string str; + int i = 0; + for (vector::const_iterator it = vec.begin(); + it != vec.end(); ++it) { + string item = strip(frontStrip(*it)); + if (item.empty()) continue; + + if (i++ > 0) str += delim; + str += item; + } + return str; +} + diff --git a/src/support/lstrings.h b/src/support/lstrings.h index 7f78c374a8..eccfcc9ebd 100644 --- a/src/support/lstrings.h +++ b/src/support/lstrings.h @@ -18,12 +18,13 @@ //#include //#include +//#include +#include #include "Lsstream.h" #include "LString.h" - /// int compare_no_case(string const & s, string const & s2); @@ -250,4 +251,12 @@ string const rsplit(string const & a, string & piece, char delim); /// Escapes non ASCII chars string const escape(string const & lab); +/// gives a vector of stringparts which have the delimiter delim +std::vector const getVectorFromString(string const & str, + string const & delim = ","); + +// the same vice versa +string const getStringFromVector(std::vector const & vec, + string const & delim = ","); + #endif -- 2.39.2