String method expandMacrosWith:
Last updated at 5:05 pm UTC on 7 March 2017
Mon, Mar 6, 2017 at 3:21 PM
Reply-To: The general-purpose Squeak developers list
On 03/05/2017 02:23 PM, tim Rowledge wrote:
Whilst looking for ways of formatting values of my weather data I discovered the String>expandMacros etc methods, which look rather like they are intended to do something like formatting. But there are no comments, no hints about what is supposed to happen, etc, etc. Couldn’t find anything in the swiki either. None of it appears to be used except in a single unit test.
So what is meant to happen here?
I'm guessing that these methods originally came from the Refactoring Browser port. VisualWorks has expandMacrosmethods which were used by the RB. When the RB was ported, these were created to support the parts of expandMacros that the RB used. I don't know if the VW expandMacros supports more features.
Here are the rules:
- All text is output directly
- Special items are delimited by <>
- <n> inserts a cr
- <t>inserts a tab
- <#p> prints the # argument on the stream
- <#s>appends the # argument on the stream (for strings)
- <#?trueValue:falseValue> if # argument is true output trueValue else output falseValue (good luck if you want a colon in your true value or a greater than in either part)
- If you want a character in your string, you need % (I don't remember if the original RB implementation had this, but it appears that Squeak now does)
Here's an example, that shows all features:
with: #() size ~= 1
with: 'This is a string'
This is a string'
As a macro expansion goes, it isn't that powerful, but it is fairly simple.
String method format:
STT - Smalltalk Templates