support.go 519 B

12345678910111213141516171819202122232425
  1. package evaluator
  2. import (
  3. "regexp"
  4. "strings"
  5. )
  6. var (
  7. TOKEN_ENV_INTERPOLATION = regexp.MustCompile("(\\\\\\\\+|[^\\\\]|\\b|\\A)\\$({?)([[:alnum:]_]+)(}?)")
  8. )
  9. func replaceEnv(b *buildFile, str string) string {
  10. for _, match := range TOKEN_ENV_INTERPOLATION.FindAllString(str, -1) {
  11. match = match[strings.Index(match, "$"):]
  12. matchKey := strings.Trim(match, "${}")
  13. for envKey, envValue := range b.env {
  14. if matchKey == envKey {
  15. str = strings.Replace(str, match, envValue, -1)
  16. }
  17. }
  18. }
  19. return str
  20. }