Changeset 2951


Ignore:
Timestamp:
Mar 20, 2013, 12:51:12 PM (5 years ago)
Author:
cameron
Message:

Add LF/CRLF/CR normalization to LF

File:
1 edited

Legend:

Unmodified
Added
Removed
  • proto/PDF/cb_pablo.py

    r2934 r2951  
    1 
    2 class Basis_bits():
    3     bit_0 = 0
    4     bit_1 = 0
    5     bit_2 = 0
    6     bit_3 = 0
    7     bit_4 = 0
    8     bit_5 = 0
    9     bit_6 = 0
    10     bit_7 = 0
     1# cb_pdf.py
     2#
     3# (c) 2012 Robert D. Cameron, Ken Herdy, Ben Hull, Dan Lin
     4# All rights reserved.
     5#
     6import sys
     7import pablo
     8
     9class Basis_bits():     
     10        bit_0 = 0
     11        bit_1 = 0
     12        bit_2 = 0
     13        bit_3 = 0
     14        bit_4 = 0
     15        bit_5 = 0
     16        bit_6 = 0
     17        bit_7 = 0
     18
     19class Parity():
     20        odd = 0
     21        even = 0
    1122
    1223class Lex ():
     
    4051        Nonoct = 0
    4152        Regular = 0
    42        
    43 class Parity():
    44         odd = 0
    45         even = 0
    4653       
    4754class Escape_Callouts():
     
    479486    out_Callouts.bit_7 = out_Callouts.bit_7 &~ out_Callouts.zeromask
    480487   
     488#
     489# Make sure all three forms of linebreak (CR, CRLF, LF) are translated to a
     490# single LF.
     491#
     492def Normalize_WS(lex, out_Callouts):
     493        if lex.CR:
     494                # Modify CR (#x0D) to LF (#x0A)
     495                out_Callouts.bit_5 ^= lex.CR
     496                out_Callouts.bit_6 ^= lex.CR
     497                out_Callouts.bit_7 ^= lex.CR
     498                CRLF = pablo.Advance(lex.CR) & lex.LF
     499                out_Callouts.delmask |= CRLF
     500
    481501
    482502def Main(basis_bits, lex, escape_Callouts, out_Callouts):
     
    488508        Parse_HexStrings(lex, marker, out_Callouts)
    489509
     510        Normalize_WS(lex, out_Callouts)
     511
    490512        Prepare_content_buffer(basis_bits, lex, escape_Callouts, out_Callouts)
    491513
Note: See TracChangeset for help on using the changeset viewer.