package rp import ( "regexp" "strings" ) const ( InlineUpdateMarker = "x-releaser-pleaser-version" ) var ( SemVerRegex = regexp.MustCompile(`(?\d+)\.(?\d+)\.(?\d+)(-(?[\w.]+))?(\+(?[-\w.]+))?`) ) type Updater interface { UpdateContent(content, version string) string } type GenericUpdater struct{} func (u *GenericUpdater) UpdateContent(content, version string) string { // TODO: use buffered input/output output := strings.Builder{} output.Grow(len(content)) for _, line := range strings.Split(content, "\n") { if strings.Contains(line, InlineUpdateMarker) { // We strip the "v" prefix to avoid adding/removing it from the users input. line = SemVerRegex.ReplaceAllLiteralString(line, strings.TrimPrefix(version, "v")) } output.WriteString(line) // TODO: Fix added newline output.WriteByte('\n') } return output.String() }