PostScript / PDF string literals are surrounded by parentheses and are allowed to contain beveled brackets if the brackets are fully balanced. For example,
( () ) % valid string constant
( ( ) % invalid string constant, the inner ( should be escaped
I know an algorithm to tell me if there are any unbalanced parentheses in a string; what I'm looking for is an algorithm that will find a minimal set of brackets that are not balanced so that I can then use the backslash in front of them to make all the valid string literal. Additional examples:
( ⟶ \(
() ⟶ ()
(() ⟶ \(() or (\()
()) ⟶ ()\) or (\))
()( ⟶ ()\(
source
share