Michael Schmitt wrote:

> 
> - The year of the following bibtex entry is not shown correctly in the citation 
>dialog (#109)
> 
>      @STRING{ ProcOfThe = "Proceedings of the " }
>      @ARTICLE{FrinckeTomp96,
>         AUTHOR =       {D. A. Frincke and A. Tompkins},
>         JOURNAL =      {Journal of Computing and Information},
>         NOTE =         {Special Issue: } # ProcOfThe # {Eighth International
>                         Conference of Computing and Information (ICCI'96)},
>         NUMBER =       {1},
>         PAGES =        {986--999},
>         TITLE =        {Using Symbolic Execution to Detect Undesirable
>                         Program States},
>         VOLUME =       {2},
>         YEAR =         1996
>      }
> 
>   Note: '#' is correct BibTeX notation!


attached a patch for this.


Herbert



-- 
http://www.lyx.org/help/
Index: src/frontends/controllers/ChangeLog
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/frontends/controllers/ChangeLog,v
retrieving revision 1.119
diff -u -r1.119 ChangeLog
--- src/frontends/controllers/ChangeLog 2002/01/19 17:05:23     1.119
+++ src/frontends/controllers/ChangeLog 2002/01/19 17:49:54
@@ -1,3 +1,8 @@
+2002-01-19  Herbert Voss  <[EMAIL PROTECTED]>
+
+       * biblio.C (parseBibTeX): change the parsing, so that 
+       '#'-characters in a bibtex entry are no more a problem.
+
 2002-01-19  Jean-Marc Lasgouttes  <[EMAIL PROTECTED]>
 
        * helper_funcs.C (browseRelFile): forgot to pass dir2 to browseFile
Index: src/frontends/controllers/biblio.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/frontends/controllers/biblio.C,v
retrieving revision 1.11
diff -u -r1.11 biblio.C
--- src/frontends/controllers/biblio.C  2001/08/09 15:08:06     1.11
+++ src/frontends/controllers/biblio.C  2002/01/19 17:49:55
@@ -319,101 +319,79 @@
 string const parseBibTeX(string data, string const & findkey)
 {
        string keyvalue;
-       
        for (string::iterator it=data.begin(); it<data.end(); ++it) {
                if ((*it) == '\n' || (*it) == '\t')
                        (*it)= ' ';
        }
-       
        data = frontStrip(data);
-       while (!data.empty() && data[0] != '=' && 
-              (data.find(' ') != string::npos || data.find('=') != string::npos)) {
-
-               string::size_type keypos = min(data.find(' '), data.find('='));
-               string key = lowercase(data.substr(0, keypos));
-      
-               data = data.substr(keypos, data.length()-1);
-               data = frontStrip(strip(data));
-               if (data.length() > 1 && data[0]=='=') {
-                       data = frontStrip(data.substr(1, data.length()-1));
-                       if (!data.empty()) {
-                               keypos = 1;
-                               string value;
-                               char enclosing;
-
-                               if (data[0]=='{') {
-                                       enclosing = '}';
-                               } else if (data[0]=='"') {
-                                       enclosing = '"';
-                               } else {
-                                       keypos=0;
-                                       enclosing=' ';
-                               }
-
-                               if (keypos &&
-                                   data.find(enclosing)!=string::npos &&
-                                   data.length()>1) {
-                                       string tmp = data.substr(keypos,
-                                                                data.length()-1);
-                                       while (tmp.find('{') != string::npos &&
-                                              tmp.find('}') != string::npos &&
-                                              tmp.find('{') < tmp.find('}') &&
-                                              tmp.find('{') < tmp.find(enclosing)) {
-
-                                               keypos += tmp.find('{')+1;
-                                               tmp = data.substr(keypos,
-                                                                 data.length()-1);
-                                               keypos += tmp.find('}')+1;
-                                               tmp = data.substr(keypos,
-                                                                 data.length()-1);
-                                       }
-
-                                       if (tmp.find(enclosing)==string::npos)
-                                               return keyvalue;
-                                       else {
-                                               keypos += tmp.find(enclosing);
-                                               tmp = data.substr(keypos,
-                                                                 data.length()-1);
-                                       }
-
-                                       value = data.substr(1, keypos-1);
-
-                                       if (keypos+1<data.length()-1)
-                                               data = 
frontStrip(data.substr(keypos+1, data.length()-1));
-                                       else
-                                               data = "";
-
-                               } else if (!keypos &&
-                                          (data.find(' ') ||
-                                           data.find(','))) {
-                                       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,','));
-                       }
+       
+    // now get only the important line of the bibtex entry.
+    // all entries are devided by ',' except the last one.     
+    data += ',';                       // now we have same behaviour for all entries
+    int Entries = 0;
+    string dummy = token(data,',',Entries);
+    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
+    // new keyword
+    keyvalue = dummy;
+    dummy = token(data,',',++Entries);
+    while (!contains(dummy,'=') && !dummy.empty()) {
+       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 '}'
+                                               // happens, when last keyword
+    string key = lowercase(data.substr(0, data.find('=')));
+    data = data.substr(data.find('='), data.length()-1);
+    data = frontStrip(strip(data));
+    if (data.length() < 2 || data[0]!='=') {   // a valis entry?
+       return string();
+    } else {
+       data = frontStrip(data.substr(1, data.length()-1));
+       if (data.empty()) {
+           return string();                    // nothing behind "="
+       } else {
+           string::size_type keypos = 1;
+           string value;
+           char enclosing;
+           if (data[0]=='{') {
+               enclosing = '}';
+           } else if (data[0]=='"') {
+               enclosing = '"';
+           } else {
+               return data;            // no {} and no "", pure data
+           }
+           if (data.length() < 2) {    // at least two chars (makes no sense)
+               return data;            // no valid entry
+           } else {
+               string tmp = data.substr(keypos, data.length()-1);
+               while (tmp.find('{') != string::npos &&
+                   tmp.find('}') != string::npos &&
+                   tmp.find('{') < tmp.find('}') &&
+                   tmp.find('{') < tmp.find(enclosing)) {
+
+                   keypos += tmp.find('{')+1;
+                   tmp = data.substr(keypos, data.length()-1);
+                   keypos += tmp.find('}')+1;
+                   tmp = data.substr(keypos, data.length()-1);
+               }
+               if (tmp.find(enclosing)==string::npos)
+                   return keyvalue;
+               else {
+                   keypos += tmp.find(enclosing);
+                   tmp = data.substr(keypos, data.length()-1);
                }
-               else return keyvalue;
+               return data.substr(1, keypos-1);
+           }
        }
-       return keyvalue;
+    }
 }
 
 

Reply via email to