replaceContent function

String replaceContent(
  1. String content,
  2. List<Object> params
)

Implementation

String replaceContent(String content,List<Object> params){
  int matchIndex = 0;
  String replace(Match m){
    if (matchIndex < params.length) {
      switch (m[0]){
        case "%s":
          return params[matchIndex++].toString();
      }
    }else{
      throw new Exception("Missing parameter for string format");
    }
    throw new Exception("Invalid format string" + m[0].toString());
  }

  return content.replaceAllMapped('%s', replace);
}