Ideas for converting straight quotes to curly quotes

前端 未结 9 1990
星月不相逢
星月不相逢 2021-02-07 16:40

I have a file that contains \"straight\" (normal, ASCII) quotes, and I\'m trying to convert them to real quotation mark glyphs (“curly” quotes, U+2018 to U+201D). Since the tran

9条回答
  •  不知归路
    2021-02-07 17:24

    A good place to start would be with a state machine:

    • Starting at position 0, iterate over the characters
    • Upon finding a quote, enter the "Quoted" state ( open quote )
    • If in "Quoted" state and you encounter a quote, return to "Starting" state ( closing quote )

    You can make additional decisions at each of the state transitions.

    You could attempt to normalize the single quotes by identifying known conjunctions, for instance, and converting them to a different, not text, character prior to processing.

    My $0.02

提交回复
热议问题