CharacterArray.st
changeset 16785 58e758125b3a
parent 16759 347181805b43
child 16855 c088880a590b
--- a/CharacterArray.st	Fri Jul 18 17:27:03 2014 +0200
+++ b/CharacterArray.st	Sun Jul 20 23:19:54 2014 +0200
@@ -326,6 +326,7 @@
     "
 ! !
 
+
 !CharacterArray class methodsFor:'pattern matching'!
 
 matchEscapeCharacter
@@ -5765,6 +5766,9 @@
      The resulting string will contain only 7-bit ascii characters.
      Emphasis is not supported.
      The following escapes are generated:
+        \'      single quote character
+        \dQuote double quote character
+        \r      return character
         \r      return character
         \n      newline character
         \t      tab character
@@ -5779,7 +5783,11 @@
     "
      first, check if any escape is needed and return the receiver unchanged if not
     "
-    anyEscapeNeeded := self contains:[:ch | (ch codePoint between:32 and:126) not ].
+    anyEscapeNeeded := self 
+                        contains:[:ch | 
+                            ((ch codePoint between:32 and:126) not
+                            or:[ch == $' or:[ch == $"]]) 
+                        ].
     anyEscapeNeeded ifFalse:[ ^ self ].
 
     self hasChangeOfEmphasis ifTrue:[ self error:'emphasis not supported' ].
@@ -5789,36 +5797,41 @@
     self do:[:ch |
         |cp|
 
-        (ch codePoint between:32 and:126) ifTrue:[
-            out nextPut:ch
+        (ch == $' or:[ch == $"]) ifTrue:[
+            out nextPut:$\.
+            out nextPut:ch.
         ] ifFalse:[
-            ch == Character return ifTrue:[
-                seq := '\r'
-            ] ifFalse:[ ch == Character nl ifTrue:[
-                seq := '\n'
-            ] ifFalse:[ ch == Character tab ifTrue:[
-                seq := '\t'
-            ] ifFalse:[ ch == $\ ifTrue:[
-                seq := '\\'
-            ] ifFalse:[ 
-                cp := ch codePoint.
-                cp <= 16rFF ifTrue:[
-                    seq := '\x' , (cp printStringRadix:16 padTo:2)   
-                ] ifFalse:[
-                    cp <= 16rFFFF ifTrue:[
-                        seq := '\u' , (cp printStringRadix:16 padTo:4)   
+            (ch codePoint between:32 and:126) ifTrue:[
+                out nextPut:ch
+            ] ifFalse:[
+                ch == Character return ifTrue:[
+                    seq := '\r'
+                ] ifFalse:[ ch == Character nl ifTrue:[
+                    seq := '\n'
+                ] ifFalse:[ ch == Character tab ifTrue:[
+                    seq := '\t'
+                ] ifFalse:[ ch == $\ ifTrue:[
+                    seq := '\\'
+                ] ifFalse:[ 
+                    cp := ch codePoint.
+                    cp <= 16rFF ifTrue:[
+                        seq := '\x' , (cp printStringRadix:16 padTo:2)   
                     ] ifFalse:[
-                        seq := '\U',(cp printStringRadix:16 padTo:8)
+                        cp <= 16rFFFF ifTrue:[
+                            seq := '\u' , (cp printStringRadix:16 padTo:4)   
+                        ] ifFalse:[
+                            seq := '\U',(cp printStringRadix:16 padTo:8)
+                        ]
                     ]
-                ]
-            ]]]].
-            out nextPutAll:seq
+                ]]]].
+                out nextPutAll:seq
+            ].
         ].
     ].
     ^ out contents
 
     "
-     'hello\nworld\na\n\tnice\n\t\tstring' withoutCEscapes withCEscapes  
+     'hello\nworld\na\n\tnice\n\t\tstring' withoutCEscapes withCEscapes.  
     "
 
     "Created: / 25-01-2012 / 11:08:16 / cg"
@@ -6978,11 +6991,11 @@
 !CharacterArray class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic/CharacterArray.st,v 1.539 2014-07-11 00:08:36 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/CharacterArray.st,v 1.540 2014-07-20 21:19:54 cg Exp $'
 !
 
 version_CVS
-    ^ '$Header: /cvs/stx/stx/libbasic/CharacterArray.st,v 1.539 2014-07-11 00:08:36 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/CharacterArray.st,v 1.540 2014-07-20 21:19:54 cg Exp $'
 ! !