class: CharacterArray
authorClaus Gittinger <cg@exept.de>
Sat, 08 Nov 2014 10:35:08 +0100
changeset 17000 28e08401d7ae
parent 16999 4d5ceea1cea6
child 17001 0524ca8f7a55
class: CharacterArray added: #quote comment/format in: #withCEscapes #withoutCEscapes changed: #unquote #withoutQuotes
CharacterArray.st
--- a/CharacterArray.st	Sat Nov 08 10:05:49 2014 +0100
+++ b/CharacterArray.st	Sat Nov 08 10:35:08 2014 +0100
@@ -1624,21 +1624,39 @@
 
 !CharacterArray methodsFor:'JavaScript support'!
 
+quote
+    "add double quotes around the receiver (unless already quoted).
+     This is the JavaSccript standard quote function."
+
+    ((self first == $") and:[self last == $"]) ifFalse:[
+        ^ '"',self,'"'
+    ].
+    ^ self
+
+    "
+     'hello' quote
+
+     JavaScriptParser evaluate:'''hello''.quote.unquote' 
+    "
+!
+
 unquote
-    "removes double quotes from the receiver"
-
-    self size >= 2 ifTrue:[
-        (self startsWith:$") ifTrue:[
-            (self endsWith:$") ifTrue:[
-                ^ self copyFrom:2 to:self size-1
-            ].
+    "removes double quotes from the receiver.
+     This is the JavaSccript standard unquote function."
+
+    |mySize|
+
+    (mySize := self size) >= 2 ifTrue:[
+        ((self first == $") and:[self last == $"]) ifTrue:[
+            ^ self copyFrom:2 to:mySize-1
         ].
     ].
     ^ self
 
     "
-     JavaScriptParser
-        evaluate:'''hello''.quote.unquote'
+     'hello' quote unquote
+
+     JavaScriptParser evaluate:'''hello''.quote.unquote' 
     "
 ! !
 
@@ -5895,6 +5913,9 @@
         \unnnn  four digit hex number defining the characters ascii value
         \Unnnnnnnn  eight digit hex number defining the characters ascii value
      This is the opposite of withoutCEscapes.
+
+     Sigh: this is named completely wrong (opposite naming of withCRs/witoutCRs),
+           but it cannot be changed easily, as these methods are already used heavily
     "
 
     |anyEscapeNeeded out seq|
@@ -5950,7 +5971,9 @@
     ^ out contents
 
     "
-     'hello\nworld\na\n\tnice\n\t\tstring' withoutCEscapes withCEscapes.  
+     'hello\n\tworld' withoutCEscapes. 
+     'hello\nworld\na\n\tnice\n\t\tstring' withoutCEscapes withCEscapes.
+     ('hello ',(Character value:16r1234),' world') withCEscapes 
     "
 
     "Created: / 25-01-2012 / 11:08:16 / cg"
@@ -6262,6 +6285,9 @@
      (not in pre 2.11 versions)
 
      This is the opposite of withCEscapes.
+
+     Sigh: this is named completely wrong (opposite naming of withCRs/witoutCRs),
+           but it cannot be changed easily, as these methods are already used heavily
     "
 
     |val     "{ SmallInteger }"
@@ -6455,23 +6481,25 @@
 !
 
 withoutQuotes
-    "remove quotes ("" and ') from the front and the end of myself"
-
-    |result quote|
-
-    result := self.
-    ((result startsWith:$") or:[(result startsWith:$')]) ifTrue:[
-        quote := result at:1.
-        result := result copyFrom:2.
-        (result endsWith:quote) ifTrue:[
-            result := result copyButLast:1
-        ].
+    "/ remove quotes ($" and $') from the front and end of myself (if matching)"
+
+    |firstChar|
+
+    firstChar := self first.
+    ((firstChar == $") or:[firstChar == $']) ifFalse:[^ self].
+
+    self last == firstChar ifTrue:[
+        ^ self copyFrom:2 to:(self size-1)
     ].
-    ^ result
-
-"/     '"hello"' withoutQuotes
-"/     '''hello''' withoutQuotes
-"/     'hello' withoutQuotes
+    ^ self
+
+    "/
+    "/ '"hello"' withoutQuotes     
+    "/ '''hello''' withoutQuotes   
+    "/ 'hello' withoutQuotes 
+    "/ '"hello' withoutQuotes 
+    "/ 'hello"' withoutQuotes  
+    "/
 !
 
 withoutSeparators
@@ -7114,11 +7142,11 @@
 !CharacterArray class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic/CharacterArray.st,v 1.546 2014-10-09 12:35:52 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/CharacterArray.st,v 1.547 2014-11-08 09:35:08 cg Exp $'
 !
 
 version_CVS
-    ^ '$Header: /cvs/stx/stx/libbasic/CharacterArray.st,v 1.546 2014-10-09 12:35:52 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/CharacterArray.st,v 1.547 2014-11-08 09:35:08 cg Exp $'
 ! !