private void ParseField(BibtexEntry entry) { string key = ParseTextToken().ToLower(); // Util.pr("Field: _"+key+"_"); SkipWhitespace(); Consume('='); string content = ParseFieldContent(key); if (content.Length > 0) { if (entry.getField(key) == null) entry.setField(key, content); else { // The following hack enables the parser to deal with multiple // author or // editor lines, stringing them together instead of getting just // one of them. // Multiple author or editor lines are not allowed by the bibtex // format, but // at least one online database exports bibtex like that, making // it inconvenient // for users if JabRef didn't accept it. if (key.Equals("author") || key.Equals("editor")) entry.setField(key, entry.getField(key) + " and " + content); } } }
public BibtexEntry ParseEntry(BibtexEntryType tp) { string id = Util.createNeutralId();// createId(tp, _db); BibtexEntry result = new BibtexEntry(id, tp); SkipWhitespace(); Consume('{', '('); SkipWhitespace(); int c = Peek(); if ((c != '\n') && (c != '\r')) SkipWhitespace(); string key = null; bool doAgain = true; while (doAgain) { doAgain = false; try { if (key != null) key = key + ParseKey();// parseTextToken(), else key = ParseKey(); } catch (NoLabelException ex) { // This exception will be thrown if the entry lacks a key // altogether, like in "@article{ author = { ...". // It will also be thrown if a key Contains =. c = (char) Peek(); if (char.IsWhiteSpace((char)c) || (c == '{') || (c == '\"')) { string fieldName = ex.Message.Trim().ToLower(); string cont = ParseFieldContent(fieldName); result.setField(fieldName, cont); } else { if (key != null) key = key + ex.Message + "="; else key = ex.Message + "="; doAgain = true; } } } if ((key != null) && key.Equals("")) key = null; result.setField(Globals.KEY_FIELD, key); SkipWhitespace(); while (true) { c = Peek(); if ((c == '}') || (c == ')')) { break; } if (c == ',') Consume(','); SkipWhitespace(); c = Peek(); if ((c == '}') || (c == ')')) { break; } ParseField(result); } Consume('}', ')'); return result; }