mirror of
https://git.lyx.org/repos/lyx.git
synced 2025-01-03 08:28:25 +00:00
fix from herbert to biblio parsing
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@3422 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
34e27f8c26
commit
58a522ef71
@ -1,3 +1,8 @@
|
|||||||
|
2002-01-19 Herbert Voss <voss@perce.de>
|
||||||
|
|
||||||
|
* biblio.C (parseBibTeX): change the parsing, so that
|
||||||
|
'#'-characters in a bibtex entry are no more a problem.
|
||||||
|
|
||||||
2002-01-19 Jean-Marc Lasgouttes <lasgouttes@freesurf.fr>
|
2002-01-19 Jean-Marc Lasgouttes <lasgouttes@freesurf.fr>
|
||||||
|
|
||||||
* ControlDialog_impl.h (ControlConnectBI>): make ControlDialogBI
|
* ControlDialog_impl.h (ControlConnectBI>): make ControlDialogBI
|
||||||
|
@ -319,101 +319,74 @@ searchKeys(InfoMap const & theMap,
|
|||||||
string const parseBibTeX(string data, string const & findkey)
|
string const parseBibTeX(string data, string const & findkey)
|
||||||
{
|
{
|
||||||
string keyvalue;
|
string keyvalue;
|
||||||
|
for (string::iterator it = data.begin(); it < data.end(); ++it) {
|
||||||
for (string::iterator it=data.begin(); it<data.end(); ++it) {
|
|
||||||
if ((*it) == '\n' || (*it) == '\t')
|
if ((*it) == '\n' || (*it) == '\t')
|
||||||
(*it)= ' ';
|
(*it)= ' ';
|
||||||
}
|
}
|
||||||
|
|
||||||
data = frontStrip(data);
|
data = frontStrip(data);
|
||||||
while (!data.empty() && data[0] != '=' &&
|
|
||||||
(data.find(' ') != string::npos || data.find('=') != string::npos)) {
|
// now get only the important line of the bibtex entry.
|
||||||
|
// all entries are devided by ',' except the last one.
|
||||||
string::size_type keypos = min(data.find(' '), data.find('='));
|
data += ','; // now we have same behaviour for all entries
|
||||||
string key = lowercase(data.substr(0, keypos));
|
// because the last one is "blah ... }"
|
||||||
|
int Entries = 0;
|
||||||
data = data.substr(keypos, data.length()-1);
|
string dummy = token(data, ',', Entries);
|
||||||
data = frontStrip(strip(data));
|
while (!contains(lowercase(dummy), findkey) && !dummy.empty())
|
||||||
if (data.length() > 1 && data[0]=='=') {
|
dummy = token(data, ',', ++Entries);
|
||||||
data = frontStrip(data.substr(1, data.length()-1));
|
if (dummy.empty())
|
||||||
if (!data.empty()) {
|
return string(); // no such keyword
|
||||||
keypos = 1;
|
// we are not sure, if we get all, because "key= "blah, blah" is allowed.
|
||||||
string value;
|
// therefore we read all until the next "=" character, which follows a
|
||||||
char enclosing;
|
// new keyword
|
||||||
|
keyvalue = dummy;
|
||||||
if (data[0]=='{') {
|
dummy = token(data, ',', ++Entries);
|
||||||
enclosing = '}';
|
while (!contains(dummy, '=') && !dummy.empty()) {
|
||||||
} else if (data[0]=='"') {
|
keyvalue += (',' + dummy);
|
||||||
enclosing = '"';
|
dummy = token(data, ',', ++Entries);
|
||||||
} else {
|
}
|
||||||
keypos=0;
|
data = keyvalue; // now we have the important line
|
||||||
enclosing=' ';
|
data = strip(data, ' '); // all spaces
|
||||||
}
|
if (!contains(data, '{')) // no opening '{'
|
||||||
|
data = strip(data, '}');// maybe there is a main closing '}'
|
||||||
if (keypos &&
|
// happens, when last keyword
|
||||||
data.find(enclosing)!=string::npos &&
|
string key = lowercase(data.substr(0, data.find('=')));
|
||||||
data.length()>1) {
|
data = data.substr(data.find('='), data.length() - 1);
|
||||||
string tmp = data.substr(keypos,
|
data = frontStrip(strip(data));
|
||||||
data.length()-1);
|
if (data.length() < 2 || data[0] != '=') { // a valid entry?
|
||||||
while (tmp.find('{') != string::npos &&
|
return string();
|
||||||
tmp.find('}') != string::npos &&
|
} else {
|
||||||
tmp.find('{') < tmp.find('}') &&
|
data = frontStrip(data.substr(1, data.length() - 1));
|
||||||
tmp.find('{') < tmp.find(enclosing)) {
|
if (data.length() < 2) {
|
||||||
|
return data; // not long enough to find delimiters
|
||||||
keypos += tmp.find('{')+1;
|
} else {
|
||||||
tmp = data.substr(keypos,
|
string::size_type keypos = 1;
|
||||||
data.length()-1);
|
char enclosing;
|
||||||
keypos += tmp.find('}')+1;
|
if (data[0] == '{') {
|
||||||
tmp = data.substr(keypos,
|
enclosing = '}';
|
||||||
data.length()-1);
|
} else if (data[0] == '"') {
|
||||||
}
|
enclosing = '"';
|
||||||
|
} else {
|
||||||
if (tmp.find(enclosing)==string::npos)
|
return data; // no {} and no "", pure data
|
||||||
return keyvalue;
|
}
|
||||||
else {
|
string tmp = data.substr(keypos, data.length()-1);
|
||||||
keypos += tmp.find(enclosing);
|
while (tmp.find('{') != string::npos &&
|
||||||
tmp = data.substr(keypos,
|
tmp.find('}') != string::npos &&
|
||||||
data.length()-1);
|
tmp.find('{') < tmp.find('}') &&
|
||||||
}
|
tmp.find('{') < tmp.find(enclosing)) {
|
||||||
|
|
||||||
value = data.substr(1, keypos-1);
|
keypos += tmp.find('{') + 1;
|
||||||
|
tmp = data.substr(keypos, data.length() - 1);
|
||||||
if (keypos+1<data.length()-1)
|
keypos += tmp.find('}') + 1;
|
||||||
data = frontStrip(data.substr(keypos+1, data.length()-1));
|
tmp = data.substr(keypos, data.length() - 1);
|
||||||
else
|
}
|
||||||
data = "";
|
if (tmp.find(enclosing) == string::npos)
|
||||||
|
return data;
|
||||||
} else if (!keypos &&
|
else {
|
||||||
(data.find(' ') ||
|
keypos += tmp.find(enclosing);
|
||||||
data.find(','))) {
|
return data.substr(1, keypos - 1);
|
||||||
keypos = data.length()-1;
|
|
||||||
if (data.find(' ') != string::npos)
|
|
||||||
keypos = data.find(' ');
|
|
||||||
if (data.find(',') != string::npos &&
|
|
||||||
keypos > data.find(','))
|
|
||||||
keypos = data.find(',');
|
|
||||||
|
|
||||||
value = data.substr(0, keypos);
|
|
||||||
|
|
||||||
if (keypos+1<data.length()-1)
|
|
||||||
data = frontStrip(data.substr(keypos+1, data.length()-1));
|
|
||||||
else
|
|
||||||
data = "";
|
|
||||||
}
|
|
||||||
else
|
|
||||||
return keyvalue;
|
|
||||||
|
|
||||||
if (findkey == key) {
|
|
||||||
keyvalue = value;
|
|
||||||
return keyvalue;
|
|
||||||
}
|
|
||||||
|
|
||||||
data = frontStrip(frontStrip(data,','));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else return keyvalue;
|
|
||||||
}
|
}
|
||||||
return keyvalue;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user