Skip to content

Commit

Permalink
SpeechSymbols.save: Escape the "#" character in identifiers so it doe…
Browse files Browse the repository at this point in the history
…sn't become a comment and thus get ignored when loaded.

SpeechSymbols.{load,save}: Handle escapes at the start of a longer identifier string so that, for example, "##" will work as an identifier.
Fixes #1526.
  • Loading branch information
jcsteh committed May 26, 2011
1 parent fe65cdd commit d4a018d
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions source/characterProcessing.py
Expand Up @@ -222,6 +222,7 @@ def _loadSymbolField(self, input, inputMap=None):
"r": "\r",
"f": "\f",
"v": "\v",
"#": "#",
}
IDENTIFIER_ESCAPES_OUTPUT = {v: k for k, v in IDENTIFIER_ESCAPES_INPUT.iteritems()}
LEVEL_INPUT = {
Expand Down Expand Up @@ -253,8 +254,8 @@ def _loadSymbol(self, line):
if not identifier:
# Empty identifier is not allowed.
raise ValueError
if len(identifier) == 2 and identifier.startswith("\\"):
identifier = self.IDENTIFIER_ESCAPES_INPUT.get(identifier[1], identifier[1])
if identifier.startswith("\\"):
identifier = self.IDENTIFIER_ESCAPES_INPUT.get(identifier[1], identifier[1]) + identifier[2:]
replacement = self._loadSymbolField(next(line))
except StopIteration:
# These fields are mandatory.
Expand Down Expand Up @@ -308,7 +309,8 @@ def _saveSymbolField(self, output, outputMap=None):
def _saveSymbol(self, symbol):
identifier = symbol.identifier
try:
identifier = u"\\%s" % self.IDENTIFIER_ESCAPES_OUTPUT[identifier]
identifier = u"\\%s%s" % (
self.IDENTIFIER_ESCAPES_OUTPUT[identifier[0]], identifier[1:])
except KeyError:
pass
fields = [identifier,
Expand Down

0 comments on commit d4a018d

Please sign in to comment.