2 c@(UnicodeCharacter traits) printOn: w &inString: isInString &encodedIn: encoding &makeEncoder: makeEncoder
4 makeEncoder `defaultsTo: False.
5 isInString `defaultsTo: False.
6 encoding `defaultsTo: UTF8.
7 encoder: (makeEncoder ifTrue: [encoding Encoder newOn: w] ifFalse: [w]).
8 c code ifNil: [encoder ; '("' ; c printName ; '")']
9 ifNotNil: [isInString ifFalse: [encoder nextPut: ($$ as: UnicodeCharacter)].
13 c@(UnicodeSubset traits) printOn: w
14 [w ; '("Unicode ' ; c printName ; '")'].
16 s@(EncodedString traits) printOn: w
17 [s do: [| :each | each printOn: w &inString: True]].
19 s@(UnicodeString traits) printOn: o &encodedIn: encoding &makeEncoder: makeEncoder
20 "Print the String readably, using escapes to preserve the contents."
21 "FIXME: this currently relies on the fact that every unprintable character
22 is in 8-bit range. That might change."
24 makeEncoder `defaultsTo: False.
25 encoding `defaultsTo: UTF8.
26 encoder: (makeEncoder ifTrue: [encoding Encoder newOn: o] ifFalse: [o]).
27 encoder nextPut: ($\' as: UnicodeCharacter).
30 index >= o stringLimit
31 ifTrue: ['...\'' printOn: encoder. ^ o].
34 (16r27 as: UnicodeCharacter) -> ['\\\'' printOn: encoder].
35 (16r9 as: UnicodeCharacter) -> ['\\t' printOn: encoder].
36 (16rA as: UnicodeCharacter) -> ['\\n' printOn: encoder].
37 (16rB as: UnicodeCharacter) -> ['\\v' printOn: encoder].
38 (16rC as: UnicodeCharacter) -> ['\\f' printOn: encoder].
39 (16rD as: UnicodeCharacter) -> ['\\r' printOn: encoder].
40 (16r8 as: UnicodeCharacter) -> ['\\b' printOn: encoder].
41 (16r7 as: UnicodeCharacter) -> ['\\a' printOn: encoder].
42 (16r1B as: UnicodeCharacter) -> ['\\e' printOn: encoder].
43 (16r0 as: UnicodeCharacter) -> ['\\0' printOn: encoder].
47 ifTrue: [c printOn: encoder &inString: True]
49 ['\\x' printOn: encoder.
50 (c as: Integer) // 16 printOn: o radix: 16.
51 (c as: Integer) \\ 16 printOn: o radix: 16]]].
52 encoder nextPut: ($\' as: UnicodeCharacter).