#FEATURE by cg
authorClaus Gittinger <cg@exept.de>
Thu, 01 Feb 2018 13:58:15 +0100
changeset 22525 ea97c9efdaed
parent 22524 be41e4a8c1aa
child 22526 9b0aeeccd6f4
#FEATURE by cg class: CharacterArray class added: #withoutAmpersandEscapes:
CharacterArray.st
--- a/CharacterArray.st	Thu Feb 01 12:30:05 2018 +0100
+++ b/CharacterArray.st	Thu Feb 01 13:58:15 2018 +0100
@@ -1019,6 +1019,49 @@
 ! !
 
 
+!CharacterArray class methodsFor:'utilities'!
+
+withoutAmpersandEscapes:label
+    "remove single ampersands;
+     replace double ampersands by single ones.
+     This is used to unescape menu-labels 
+     (which use the ampersand as shortKey marker)"
+
+    ^ String 
+        streamContents:[:out |
+            |in ch next|
+
+            in := label readStream.
+            [in atEnd] whileFalse:[
+                ch := in next.
+                ch == $& ifTrue:[
+                    (next := in peek) == $& ifTrue:[
+                        in next.
+                        out nextPut:ch
+                    ] ifFalse:[
+                        ch := next
+                    ].
+                ] ifFalse:[
+                    out nextPut:ch
+                ].
+            ]
+        ]
+
+    "
+     String withoutAmpersandEscapes:''
+     String withoutAmpersandEscapes:'a'
+     String withoutAmpersandEscapes:'abcd'
+     String withoutAmpersandEscapes:'&abcd'
+     String withoutAmpersandEscapes:'&abcd&'
+     String withoutAmpersandEscapes:'&a&b&c&d'
+     String withoutAmpersandEscapes:'&a&b&c&d&'
+     String withoutAmpersandEscapes:'&&a&&b&&c&&d&&'
+     String withoutAmpersandEscapes:'&&a&&b&&c&&d&'
+     String withoutAmpersandEscapes:'&a&&b&&c&&d&'
+     String withoutAmpersandEscapes:'a&&b&&c&&d'
+    "
+! !
+
 !CharacterArray methodsFor:'Compatibility-ANSI'!
 
 addLineDelimiters