func (r *replacer) Replace(s string) string {
	// Do not attempt replacements if no placeholder is found.
	if !strings.ContainsAny(s, "{}") {
		return s
	}

	result := ""
Placeholders: // process each placeholder in sequence
	for {
		var idxStart, idxEnd int

		idxOffset := 0
		for { // find first unescaped opening brace
			searchSpace := s[idxOffset:]
			idxStart = strings.Index(searchSpace, "{")
			if idxStart == -1 {
				// no more placeholders
				break Placeholders
			}
			if idxStart == 0 || searchSpace[idxStart-1] != '\\' {
				// preceding character is not an escape
				idxStart += idxOffset
				break
			}
			// the brace we found was escaped
			// search the rest of the string next
			idxOffset += idxStart + 1
		}

		idxOffset = 0
		for { // find first unescaped closing brace
			searchSpace := s[idxStart+idxOffset:]
			idxEnd = strings.Index(searchSpace, "}")
			if idxEnd == -1 {
				// unpaired placeholder
				break Placeholders
			}
			if idxEnd == 0 || searchSpace[idxEnd-1] != '\\' {
				// preceding character is not an escape
				idxEnd += idxOffset + idxStart
				break
			}
			// the brace we found was escaped
			// search the rest of the string next
			idxOffset += idxEnd + 1
		}

		// get a replacement for the unescaped placeholder
		placeholder := unescapeBraces(s[idxStart : idxEnd+1])
		replacement := r.getSubstitution(placeholder)
		if replacement == "" {
			replacement = "-"
		}
		r.setReplacedValue(placeholder, replacement)

		// append unescaped prefix + replacement
		result += strings.TrimPrefix(unescapeBraces(s[:idxStart]), "\\") + replacement

		// strip out scanned parts
		s = s[idxEnd+1:]
	}

	// append unscanned parts
	return result + unescapeBraces(s)
}
// Replace performs a replacement of values on s and returns
// the string with the replaced values.
Replace performs a replacement of values on s and returns
the string with the replaced values.
// Replace performs a replacement of values on s and returns // the string with the replaced values .
func (r *replacer) Replace(s string) string {
	if !strings.ContainsAny(s, "{}") {
		return s
	}
	result := ""
Placeholders: 
	for {
		var idxStart, idxEnd int
		idxOffset := 0
		for { 
			searchSpace := s[idxOffset:]
			idxStart = strings.Index(searchSpace, "{")
			if idxStart == -1 {
				break Placeholders
			}
			if idxStart == 0 || searchSpace[idxStart-1] != '\\' {
				idxStart += idxOffset
				break
			}
			idxOffset += idxStart + 1
		}
		idxOffset = 0
		for { 
			searchSpace := s[idxStart+idxOffset:]
			idxEnd = strings.Index(searchSpace, "}")
			if idxEnd == -1 {
				break Placeholders
			}
			if idxEnd == 0 || searchSpace[idxEnd-1] != '\\' {
				idxEnd += idxOffset + idxStart
				break
			}
			idxOffset += idxEnd + 1
		}
		placeholder := unescapeBraces(s[idxStart : idxEnd+1])
		replacement := r.getSubstitution(placeholder)
		if replacement == "" {
			replacement = "-"
		}
		r.setReplacedValue(placeholder, replacement)
		result += strings.TrimPrefix(unescapeBraces(s[:idxStart]), "\\") + replacement
		s = s[idxEnd+1:]
	}
	return result + unescapeBraces(s)
}
func ( r * replacer ) Replace ( s string ) string { if ! strings . ContainsAny ( s , " " ) { return s } result := " " Placeholders : for { var idxStart , idxEnd int idxOffset := 0 for { searchSpace := s [ idxOffset : ] idxStart = strings . Index ( searchSpace , " " ) if idxStart == - 1 { break Placeholders } if idxStart == 0 || searchSpace [ idxStart - 1 ] != '\\' { idxStart += idxOffset break } idxOffset += idxStart + 1 } idxOffset = 0 for { searchSpace := s [ idxStart + idxOffset : ] idxEnd = strings . Index ( searchSpace , " " ) if idxEnd == - 1 { break Placeholders } if idxEnd == 0 || searchSpace [ idxEnd - 1 ] != '\\' { idxEnd += idxOffset + idxStart break } idxOffset += idxEnd + 1 } placeholder := unescapeBraces ( s [ idxStart : idxEnd + 1 ] ) replacement := r . getSubstitution ( placeholder ) if replacement == " " { replacement = " " } r . setReplacedValue ( placeholder , replacement ) result += strings . TrimPrefix ( unescapeBraces ( s [ : idxStart ] ) , " \\ " ) + replacement s = s [ idxEnd + 1 : ] } return result + unescapeBraces ( s ) }
Replace performs a replacement of values on s and returns
the string with the replaced values.
Replace performs a replacement of values on s and returns the string with the replaced values .
// Do not attempt replacements if no placeholder is found. // process each placeholder in sequence // find first unescaped opening brace // no more placeholders // preceding character is not an escape // the brace we found was escaped // search the rest of the string next // find first unescaped closing brace // unpaired placeholder // preceding character is not an escape // the brace we found was escaped // search the rest of the string next // get a replacement for the unescaped placeholder // append unescaped prefix + replacement // strip out scanned parts // append unscanned parts