Example #1
0
def __create_database_file(TargetEncoding, TargetEncodingName):
    """Writes a database file for a given TargetEncodingName. The 
       TargetEncodingName is required to name the file where the 
       data is to be stored.
    """
    encoder     = codecs.getencoder(TargetEncoding)
    prev_output = -1
    db          = []
    bytes_per_char = -1
    for input in range(0x110000):
        output, n = __get_transformation(encoder, input)

        if bytes_per_char == -1: 
            bytes_per_char = n
        elif n != -1 and bytes_per_char != n:
            print "# not a constant size byte format."
            return False

        # Detect discontinuity in the mapping
        if   prev_output == -1:
            if output != -1:
                input_interval        = Interval(input)
                target_interval_begin = output

        elif output != prev_output + 1:
            # If interval was valid, append it to the database
            input_interval.end    = input
            db.append((input_interval, target_interval_begin))
            # If interval ahead is valid, prepare an object for it
            if output != -1:
                input_interval        = Interval(input)
                target_interval_begin = output

        prev_output = output

    if prev_output != -1:
        input_interval.end = input
        db.append((input_interval, target_interval_begin))

    fh = open_file_or_die(QUEX_CODEC_DB_PATH + "/%s.dat" % TargetEncoding, "wb")
    fh.write("// Describes mapping from Unicode Code pointer to Character code in %s (%s)\n" \
             % (TargetEncoding, TargetEncodingName))
    fh.write("// [SourceInterval.begin] [SourceInterval.Size]  [TargetInterval.begin] (all in hexidecimal)\n")
    for i, t in db:
        fh.write("0x%X %i 0x%X\n" % (i.begin, i.end - i.begin, t))
    fh.close()

    return True
Example #2
0
 def __do_this(A, B):
     interval_list = B.get_intervals()
     for interval in interval_list:
         print "#"
         print "#  A                 = " + repr(A)
         print "#  B                 = " + repr(interval)
         X = deepcopy(A)
         safe = Interval(interval.begin, interval.end)
         X.cut_interval(safe)
         X.assert_consistency()
         safe.begin = 7777
         safe.end = 0000
         print "#  A.cut_interval(B) = " + repr(X)
 def __do_this(A, B):
     interval_list = B.get_intervals()
     for interval in interval_list:
         print "#"
         print "#  A                 = " + repr(A)
         print "#  B                 = " + repr(interval)
         X = deepcopy(A)
         safe = Interval(interval.begin, interval.end)
         X.cut_interval(safe)
         X.assert_consistency()
         safe.begin = 7777
         safe.end   = 0000
         print "#  A.cut_interval(B) = " + repr(X)