Next / Previous / Contents / Shipman's homepage

5.6. entmarch: extractData()

This function generates all the entity definitions for a given code point, if there are any.

# - - -   e x t r a c t D a t a

def extractData(uniData, uniChar, setName):
    '''Write all entities in set (setName) for character (uniChar)

      [ (uniData is a UniData instance) and
        (uniChar is a code point as an int) and
        (setName is an entity set name) ->
          sys.stdout  +:=  entity definitions for any entities in
              entity set setName for code point cp in uniData ]

First we build a list of all the entities in uniChar whose entity set names match setName.

    #-- 1
    # [ uniEntList  :=  list of UniEnt instances in uniChar that have
    #       (setName) as their entity set names ]
    uniEntList = [ uniEnt
                   for uniEnt in uniChar.genEnts()
                   if setName == uniEnt.setName ]

If there are no entities, we are done here. Otherwise, write a header comment showing the character's full name, then write the entity declarations. For ENTITY_INDENT, see Section 5.3, “entmarch: Manifest constants”.

    #-- 2
    # [ if uniEntList is nonempty ->
    #     sys.stdout  +:=  (comment displaying uniChar.fullName) +
    #         (entity definitions for names in uniEntList as code
    #         point cp)
    #   else -> I ]
    if len(uniEntList) > 0:
        print("  <!--{0}-->".format(uniChar.fullName))
        for uniEnt in uniEntList:
            print('{spacer}<!ENTITY  {entName:<12s} '