From 143f71f6910595d07c288f64180220ce4ac13087 Mon Sep 17 00:00:00 2001 From: Angus Leeming Date: Tue, 16 Apr 2002 09:09:42 +0000 Subject: [PATCH] (Herbert): fix parsing of bibtex entry bug. (Henry Pfister): also fixes bug in loading bibtex database. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@3999 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/frontends/controllers/ChangeLog | 5 +++++ src/frontends/controllers/biblio.C | 27 +++++++++++++++++++-------- src/insets/ChangeLog | 5 +++++ src/insets/insetbib.C | 1 + 4 files changed, 30 insertions(+), 8 deletions(-) diff --git a/src/frontends/controllers/ChangeLog b/src/frontends/controllers/ChangeLog index f2730c68d7..b723d65fa4 100644 --- a/src/frontends/controllers/ChangeLog +++ b/src/frontends/controllers/ChangeLog @@ -1,3 +1,8 @@ +2002-04-15 Herbert Voss + + * biblio.[Ch] (parseBibTeX): fix bug while scanning bibtexentries + with something like ,,...blah...`` (two commas) + 2002-04-14 Herbert Voss * helper_funcs.[Ch]: move the getVectorFromString and the vice versa diff --git a/src/frontends/controllers/biblio.C b/src/frontends/controllers/biblio.C index 9ed9961bfc..bda91ed8e3 100644 --- a/src/frontends/controllers/biblio.C +++ b/src/frontends/controllers/biblio.C @@ -355,7 +355,8 @@ string const parseBibTeX(string data, string const & findkey) } dummy = token(data, '\n', ++Entries); } - data = data_; + // replace double commas with "" for easy scanning + data = subst(data_, ",,", "\"\""); // unlikely! if (data.empty()) @@ -370,9 +371,12 @@ string const parseBibTeX(string data, string const & findkey) while (!contains(lowercase(dummy), findkey) && !dummy.empty()) dummy = token(data, ',', ++Entries); if (dummy.empty()) - return string(); // no such keyword - // we are not sure, if we get all, because "key= "blah, blah" is allowed. - // therefore we read all until the next "=" character, which follows a + // no such keyword + return string(); + + // we are not sure, if we get all, because "key= "blah, blah" is + // allowed. + // Therefore we read all until the next "=" character, which follows a // new keyword keyvalue = dummy; dummy = token(data, ',', ++Entries); @@ -380,10 +384,17 @@ string const parseBibTeX(string data, string const & findkey) keyvalue += (',' + dummy); dummy = token(data, ',', ++Entries); } - data = keyvalue; // now we have the important line - data = strip(data, ' '); // all spaces - if (!contains(data, '{')) // no opening '{' - data = strip(data, '}');// maybe there is a main closing '}' + + // replace double "" with originals ,, (two commas) + // leaving us with the all-important line + data = subst(keyvalue, "\"\"", ",,"); + + // Clean-up. + // 1. Spaces + data = strip(data, ' '); + // 2. if there is no opening '{' then a closing '{' is probably cruft. + if (!contains(data, '{')) + data = strip(data, '}'); // happens, when last keyword string::size_type const idx = !data.empty() ? data.find('=') : string::npos; diff --git a/src/insets/ChangeLog b/src/insets/ChangeLog index 448a456a03..b86eca6d83 100644 --- a/src/insets/ChangeLog +++ b/src/insets/ChangeLog @@ -1,3 +1,8 @@ +2002-04-16 Angus Leeming + + * insetbib.C (getKeys): strip leading '\t's from the line too. + With thanks to Henry Pfister . + 2002-04-12 Juergen Vigna * insettext.h: added cix() helper function and use it where appropriate diff --git a/src/insets/insetbib.C b/src/insets/insetbib.C index 481e8dfe54..8b4ca13d18 100644 --- a/src/insets/insetbib.C +++ b/src/insets/insetbib.C @@ -264,6 +264,7 @@ vector > const InsetBibtex::getKeys(Buffer const * buffer) && !prefixIs(tmp, "@preamble")) { linebuf = split(linebuf, tmp, ','); tmp = frontStrip(tmp); + tmp = frontStrip(tmp,'\t'); if (!tmp.empty()) { keys.push_back(pair(tmp,string())); } -- 2.39.2