(pr-str) { /data get ( ) true _pr_str_args }
(str) { /data get () false _pr_str_args }
(prn) { /data get ( ) true _pr_str_args print (\n) print null }
- (println) { /data get () false _pr_str_args print (\n) print null }
+ (println) { /data get ( ) false _pr_str_args print (\n) print null }
(<) { dup 0 _nth exch 1 _nth lt }
(<=) { dup 0 _nth exch 1 _nth le }
(>) { dup 0 _nth exch 1 _nth gt }
obj 10 slen string cvrs
}{ /stringtype obj type eq { % if string
print_readably {
- (") obj (") concatenate concatenate
+ (")
+ obj (\\) (\\\\) replace
+ (") (\\") replace
+ (") concatenate concatenate
}{
obj
} ifelse
} if
/ch str idx get def % current character
/idx idx 1 add def
+ ch 92 eq { % if \
+ str idx get 34 eq { %if \"
+ /idx idx 1 add def
+ /cnt cnt 1 add def % 1 more below
+ } if
+ } if
ch 34 eq { exit } if % '"' is end of string
/cnt cnt 1 add def
} loop
str start cnt getinterval % the matched string
+ (\\") (") replace
str idx % return: new_string string new_idx
} def
% General functions
% concatenate: concatenate two strings or two arrays
-% From Thinking in PostScript 1990 Reid
+% From Thinking in PostScript 1990 Reid, Example 11.7
% (string1) (string2) concatenate string3
% array1 array2 concatenate array3
/concatenate { %def
]
} bind def
+% string1 string2 string3 -> replace -> string4
+% Return a string4 with all occurrences of string2 in string1 replaced
+% with string3
+/replace { 4 dict begin
+ /repstr exch def
+ /needle exch def
+ /haystack exch def
+ /result () def
+ { % loop
+ haystack needle search
+ { %if found
+ % stack: post match pre
+ repstr concatenate 3 1 roll pop % stack: pre+ post
+ /haystack exch def % stack: pre+
+ result exch concatenate /result exch def
+ }{
+ result exch concatenate /result exch def
+ exit
+ } ifelse
+ } loop
+ result
+end } def
+
+
% objA objB -> _equal? -> bool
/_equal? { 6 dict begin
/b exch def