# HG changeset patch # User Claus Gittinger # Date 1517489895 -3600 # Node ID ea97c9efdaed6e931c287c6004bfe210ec5871ab # Parent be41e4a8c1aa3ea30c07802650a19fa1904f1625 #FEATURE by cg class: CharacterArray class added: #withoutAmpersandEscapes: diff -r be41e4a8c1aa -r ea97c9efdaed 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