Next / Previous / Contents / TCC Help System / NM Tech homepage

36.10. CensusRowLabel._foRealQuotes()

cbchistlib.py
# - - -   C e n s u s R o w L a b e l . _ f o R e a l Q u o t e s

    def _foRealQuotes(self, s, text):
        '''Replace double-quote characters with paired double quotes.

          [ (s is a sox.Sox instance) and (text is a string) ->
              s  +:=  text, with double-quote characters replaced
                  alternately by “ and ” ]
        '''

First we split the text on double-quote characters. This gives us a list in which the first element is output as is; the second element is output preceded by a “, the third element is preceded by a ” character, and so forth. (We don't actually check to make sure that the double-quote characters (“"”) occur in pairs.)

cbchistlib.py
        #-- 1
        partList = text.split('"')

        #-- 2
        # [ s  +:=  partList[0] ]
        s.write(partList[0])

        #-- 3
        # [ s  +:=  partList[1:], with odd-numbered elements preceded
        #       by “ and even-number elements preceded by
        #       ” ]
        for k in range(1, len(partList)):
            if (k % 2) == 1:
                s.write(LDQUO)
            else:
                s.write(RDQUO)
            s.write(partList[k])