@@ -343,76 +343,6 @@ var IndentFunc = function.New(&function.Spec{
343
343
},
344
344
})
345
345
346
- // ReplaceFunc is a function that searches a given string for another given
347
- // substring, and replaces each occurence with a given replacement string.
348
- // The substr argument is a simple string.
349
- var ReplaceFunc = function .New (& function.Spec {
350
- Params : []function.Parameter {
351
- {
352
- Name : "str" ,
353
- Type : cty .String ,
354
- },
355
- {
356
- Name : "substr" ,
357
- Type : cty .String ,
358
- },
359
- {
360
- Name : "replace" ,
361
- Type : cty .String ,
362
- },
363
- {
364
- Name : "n" ,
365
- Type : cty .Number ,
366
- },
367
- },
368
- Type : function .StaticReturnType (cty .String ),
369
- Impl : func (args []cty.Value , retType cty.Type ) (cty.Value , error ) {
370
- str := args [0 ].AsString ()
371
- substr := args [1 ].AsString ()
372
- replace := args [2 ].AsString ()
373
- var n int
374
- err := gocty .FromCtyValue (args [3 ], & n )
375
- if err != nil {
376
- return cty .NilVal , err
377
- }
378
-
379
- return cty .StringVal (strings .Replace (str , substr , replace , n )), nil
380
- },
381
- })
382
-
383
- // RegexpReplaceAllFunc is a function that searches a given string for another
384
- // given substring, and replaces each occurence with a given replacement
385
- // string. The substr argument must be a valid regular expression.
386
- var RegexpReplaceAllFunc = function .New (& function.Spec {
387
- Params : []function.Parameter {
388
- {
389
- Name : "str" ,
390
- Type : cty .String ,
391
- },
392
- {
393
- Name : "substr" ,
394
- Type : cty .String ,
395
- },
396
- {
397
- Name : "replace" ,
398
- Type : cty .String ,
399
- },
400
- },
401
- Type : function .StaticReturnType (cty .String ),
402
- Impl : func (args []cty.Value , retType cty.Type ) (ret cty.Value , err error ) {
403
- str := args [0 ].AsString ()
404
- substr := args [1 ].AsString ()
405
- replace := args [2 ].AsString ()
406
-
407
- re , err := regexp .Compile (substr [1 : len (substr )- 1 ])
408
- if err != nil {
409
- return cty .UnknownVal (cty .String ), err
410
- }
411
-
412
- return cty .StringVal (re .ReplaceAllString (str , replace )), nil
413
- },
414
- })
415
-
416
346
// TitleFunc is a function that converts the first letter of each word in the
417
347
// given string to uppercase.
418
348
var TitleFunc = function .New (& function.Spec {
@@ -584,20 +514,6 @@ func Indent(spaces, str cty.Value) (cty.Value, error) {
584
514
return IndentFunc .Call ([]cty.Value {spaces , str })
585
515
}
586
516
587
- func Replace (str , substr , replace , n cty.Value ) (cty.Value , error ) {
588
- return ReplaceFunc .Call ([]cty.Value {str , substr , replace , n })
589
- }
590
-
591
- // ReplaceAll searches a given string for another given substring,
592
- // and replaces all occurrences with a given replacement string.
593
- func ReplaceAll (str , substr , replace cty.Value ) (cty.Value , error ) {
594
- return ReplaceFunc .Call ([]cty.Value {str , substr , replace , cty .NumberIntVal (- 1 )})
595
- }
596
-
597
- func RegexpReplaceAll (str , substr , replace cty.Value ) (cty.Value , error ) {
598
- return RegexpReplaceAllFunc .Call ([]cty.Value {str , substr , replace })
599
- }
600
-
601
517
// Title converts the first letter of each word in the given string to uppercase.
602
518
func Title (str cty.Value ) (cty.Value , error ) {
603
519
return TitleFunc .Call ([]cty.Value {str })
0 commit comments