@@ -138,15 +138,81 @@ func Lower(frame wdte.Frame, args ...wdte.Func) wdte.Func {
138
138
return wdte .String (strings .ToLower (string (args [0 ].Call (frame ).(wdte.String ))))
139
139
}
140
140
141
+ // Repeat is a WDTE function with the following signatures:
142
+ //
143
+ // repeat string times
144
+ // (repeat string) times
145
+ // repeat times string
146
+ // (repeat times) string
147
+ //
148
+ // It returns a new string containing the given string repeated the
149
+ // number of times specified.
150
+ func Repeat (frame wdte.Frame , args ... wdte.Func ) wdte.Func {
151
+ frame = frame .Sub ("repeat" )
152
+
153
+ switch len (args ) {
154
+ case 0 :
155
+ return wdte .GoFunc (Repeat )
156
+ case 1 :
157
+ return wdte .GoFunc (func (frame wdte.Frame , next ... wdte.Func ) wdte.Func {
158
+ return Repeat (frame , append (args , next ... )... )
159
+ })
160
+ }
161
+
162
+ var str wdte.String
163
+ var times wdte.Number
164
+ switch a0 := args [0 ].Call (frame ).(type ) {
165
+ case wdte.String :
166
+ str = a0
167
+ times = args [1 ].Call (frame ).(wdte.Number )
168
+
169
+ case wdte.Number :
170
+ times = a0
171
+ str = args [1 ].Call (frame ).(wdte.String )
172
+ }
173
+
174
+ return wdte .String (strings .Repeat (string (str ), int (times )))
175
+ }
176
+
177
+ // Join is a WDTE function with the following signatures:
178
+ //
179
+ // join strings sep
180
+ // (join sep) strings
181
+ //
182
+ // It returns a new string containing the strings in the provided
183
+ // array with sep inserted between each.
184
+ func Join (frame wdte.Frame , args ... wdte.Func ) wdte.Func {
185
+ frame = frame .Sub ("join" )
186
+
187
+ switch len (args ) {
188
+ case 0 :
189
+ return wdte .GoFunc (Join )
190
+ case 1 :
191
+ return wdte .GoFunc (func (frame wdte.Frame , next ... wdte.Func ) wdte.Func {
192
+ return Join (frame , append (next , args ... )... )
193
+ })
194
+ }
195
+
196
+ a := args [0 ].Call (frame ).(wdte.Array )
197
+ s := make ([]string , 0 , len (a ))
198
+ for _ , str := range a {
199
+ s = append (s , string (str .(wdte.String )))
200
+ }
201
+
202
+ return wdte .String (strings .Join (s , string (args [1 ].Call (frame ).(wdte.String ))))
203
+ }
204
+
141
205
// Scope is a scope containing the functions in this package.
142
206
var Scope = wdte .S ().Map (map [wdte.ID ]wdte.Func {
143
207
"contains" : wdte .GoFunc (Contains ),
144
208
"prefix" : wdte .GoFunc (Prefix ),
145
209
"suffix" : wdte .GoFunc (Suffix ),
146
210
"index" : wdte .GoFunc (Index ),
147
211
148
- "upper" : wdte .GoFunc (Upper ),
149
- "lower" : wdte .GoFunc (Lower ),
212
+ "upper" : wdte .GoFunc (Upper ),
213
+ "lower" : wdte .GoFunc (Lower ),
214
+ "repeat" : wdte .GoFunc (Repeat ),
215
+ "join" : wdte .GoFunc (Join ),
150
216
151
217
"format" : wdte .GoFunc (Format ),
152
218
})
0 commit comments