From 8476b829518881789cfaf1b365c747c0696df0c8 Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Tue, 20 May 2003 19:14:14 +0000 Subject: Preserve strings while reconciling svn:r18 --- BibTeX.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'BibTeX.py') diff --git a/BibTeX.py b/BibTeX.py index f696604..c7761fb 100644 --- a/BibTeX.py +++ b/BibTeX.py @@ -186,7 +186,7 @@ class BibTeXEntry: best = u return best - def format(self, width=70, indent=8, v=0): + def format(self, width=70, indent=8, v=0, invStrings={}): d = ["@%s{%s,\n" % (self.type, self.key)] if v: df = DISPLAYED_FIELDS[:] @@ -204,7 +204,10 @@ class BibTeXEntry: d.append("%% %s = {?????},\n"%f) continue d.append(" ") - s = "%s = {%s},\n" % (f, v) + if invStrings.has_key(v): + s = "%s = %s," %(f, invStrings[v]) + else: + s = "%s = {%s},\n" % (f, v) d.append(_split(s,width,indent)) d.append("}\n") return "".join(d) @@ -609,6 +612,10 @@ class Parser: def __init__(self, fileiter, initial_strings, result=None): self.strings = config.INITIAL_STRINGS.copy() self.strings.update(initial_strings) + self.newStrings = {} + self.invStrings = {} + for k,v in config.INITIAL_STRINGS.items(): + self.invStrings[v]=k self.fileiter = fileiter self.entries = {} if result is None: @@ -768,6 +775,8 @@ class Parser: if self.curEntType == 'string': self.strings[v[0]] = v[1] + self.newStrings[v[0]] = v[1] + self.invStrings[v[1]] = v[0] elif self.curEntType == 'preamble': pass else: @@ -791,6 +800,9 @@ class Parser: raise ParseError("Unexpected EOF at line %s (%s)" % ( self.fileiter.lineno, self.entryLine)) + self.result.invStrings = self.invStrings + self.result.newStrings = self.newStrings + return self.result def _parse(self): -- cgit v1.2.3-70-g09d2