#FEATURE by cg
authorClaus Gittinger <cg@exept.de>
Thu, 14 Jun 2018 11:47:20 +0200
changeset 23067 a9b2aa8f652a
parent 23066 caf3599f703e
child 23068 991e92b378ef
#FEATURE by cg class: CharacterArray added: #expandPlaceholders:with:ignoreNumericEscapes:on: changed: #expandPlaceholders:with: #expandPlaceholders:with:on: #expandPlaceholdersWith:on:
CharacterArray.st
--- a/CharacterArray.st	Wed Jun 13 17:33:14 2018 +0200
+++ b/CharacterArray.st	Thu Jun 14 11:47:20 2018 +0200
@@ -6588,7 +6588,7 @@
     |stream|
 
     stream := (TextStream ? CharacterWriteStream) on:(self species uninitializedNew:self size + 20).
-    self expandPlaceholders:escapeCharacter with:argArrayOrDictionary on:stream.
+    self expandPlaceholders:escapeCharacter with:argArrayOrDictionary ignoreNumericEscapes:false on:stream.
     ^ stream contents.
 
 
@@ -6617,29 +6617,35 @@
      'hello $1 %a $b %(foo) $foo ' expandPlaceholders:$% with:dict.
     "
 
-    "Modified: 1.7.1997 / 00:53:24 / cg"
-!
-
-expandPlaceholders:escapeCharacter with:argArrayOrDictionary on:aStream
+    "Modified: / 01-07-1997 / 00:53:24 / cg"
+    "Modified: / 14-06-2018 / 11:46:18 / Claus Gittinger"
+!
+
+expandPlaceholders:escapeCharacter with:argArrayOrDictionary ignoreNumericEscapes:ignoreNumericEscapes on:aStream
     "this is the generic version of the old %-escaping method, allowing for an arbitrary
      escape character to be used (typically $$ or $% are effectively used).
 
      Write the receiver to aStream, where all %i escapes are
-     replaced by corresponding arguments' printStrings from the argArrayOrDictionary.
+     replaced by corresponding arguments' printStrings from the argArray.
      I.e. 'hello %1; how is %2' expandPlaceholdersWith:#('world' 'this') results
      in the new string 'hello world; how is this'.
 
      As an extension, the argument may also be a dictionary, providing values for symbolic keys.
      In this case, %a .. %z and %(...) are also allowed.
      (%1..%9 require a numeric key in the dictionary, however)
-     Also, the values in argArrayOrDictionary may be blocks.
+
+     Also, values in argArrayOrDictionary may be blocks.
 
      To get a '%' character, use a '%%'-escape.
      To get an integer-indexed placeHolder followed by another digit,
      or an index > 9, you must use %(digit).
 
      See also bindWith:... for VisualAge compatibility.
-     Use %<cr> to insert a CR and %<tab> to insert a TAB."
+     Use %<cr> to insert a CR and %<tab> to insert a TAB.
+
+     ignoreNumericEscapes controls if %<nr> escapes are expanded or not.
+     This is required for Windows batch-script expansion, where %<nr> should be left
+     unchanged."
 
     |next v key numericKey
      idx   "{ SmallInteger }"
@@ -6771,7 +6777,83 @@
      ].
     "
 
+    "Created: / 14-06-2018 / 11:44:08 / Claus Gittinger"
+!
+
+expandPlaceholders:escapeCharacter with:argArrayOrDictionary on:aStream
+    "this is the generic version of the old %-escaping method, allowing for an arbitrary
+     escape character to be used (typically $$ or $% are effectively used).
+
+     Write the receiver to aStream, where all %i escapes are
+     replaced by corresponding arguments' printStrings from the argArrayOrDictionary.
+     I.e. 'hello %1; how is %2' expandPlaceholdersWith:#('world' 'this') results
+     in the new string 'hello world; how is this'.
+
+     As an extension, the argument may also be a dictionary, providing values for symbolic keys.
+     In this case, %a .. %z and %(...) are also allowed.
+     (%1..%9 require a numeric key in the dictionary, however)
+     Also, the values in argArrayOrDictionary may be blocks.
+
+     To get a '%' character, use a '%%'-escape.
+     To get an integer-indexed placeHolder followed by another digit,
+     or an index > 9, you must use %(digit).
+
+     See also bindWith:... for VisualAge compatibility.
+     Use %<cr> to insert a CR and %<tab> to insert a TAB."
+
+    ^ self
+        expandPlaceholders:escapeCharacter 
+        with:argArrayOrDictionary 
+        ignoreNumericEscapes:false 
+        on:aStream
+
+    "
+     String streamContents:[:s|
+        'hello %1' expandPlaceholders:$% with:#('world') on:s.
+        s cr.
+        'hello $1; how is $2' expandPlaceholders:$$ with:#('world' 'this') on:s.
+        s cr.
+        'hello %2; how is %1' expandPlaceholders:$% with:#('world' 'this') on:s.
+        s cr.
+        '%1 plus %2 gives %3 ' expandPlaceholders:$% with:#(4 5 9) on:s.
+        s cr.
+        '%%(1)0 gives %(1)0' expandPlaceholders:$% with:#(123) on:s.
+        s cr.
+        '%%10 gives %10' expandPlaceholders:$% with:#(123) on:s.
+        s cr.
+        '%%(10) gives %(10) %<cr>%<tab>next line' expandPlaceholders:$% with:#(123) on:s.
+        s cr.
+        '%%test gives %test' expandPlaceholders:$% with:#(123) on:s.
+        s cr.
+        '|%%<tab>|%%1|%%<cr>| gives |%<tab>|%1|%<cr>|' expandPlaceholders:$% with:#(foo) on:s.
+     ]
+    "
+
+    "
+     |dict|
+
+     dict := Dictionary new.
+     dict at:1 put:'one'.
+     dict at:$a put:'AAAAA'.
+     dict at:$b put:[ Time now ].
+     String streamContents:[:s|
+         'hello $1 $a $b' expandPlaceholders:$$ with:dict on:s.
+     ].
+    "
+
+    "using blocks:
+     |dict|
+
+     dict := Dictionary new.
+     dict at:'time' put:[Time now printString].
+     dict at:'date' put:[Date today printString].
+     String streamContents:[:s|
+         'it is $(time) $(date)' expandPlaceholders:$$ with:dict on:s.
+     ].
+    "
+
     "Modified: / 18-11-2010 / 15:43:28 / cg"
+    "Modified: / 14-06-2018 / 11:44:32 / Claus Gittinger"
 !
 
 expandPlaceholdersWith:argArrayOrDictionary
@@ -6847,7 +6929,7 @@
      See also bindWith:... for VisualAge compatibility.
      Use %<cr> to insert a CR and %<tab> to insert a TAB."
 
-    ^ self expandPlaceholders:$% with:argArrayOrDictionary on:aStream
+    ^ self expandPlaceholders:$% with:argArrayOrDictionary ignoreNumericEscapes:false on:aStream
 
     "
      String streamContents:[:s|
@@ -6882,6 +6964,7 @@
     "
 
     "Modified: / 18-11-2010 / 15:43:28 / cg"
+    "Modified: / 14-06-2018 / 11:45:36 / Claus Gittinger"
 !
 
 extractPlaceHolders:escapeCharacter