<commit_before>package sirius

import (
	"strings"
)

/*
TextEditAction represents a series of
edits to the message Text property

Usage:

var msg Message

edit := msg.EditText()
edit.Substitute("foo", "bar")
edit.Append("-ending")

 */
type TextEditAction struct {
	mutations []TextMutation
}

func (*Message) EditText() *TextEditAction {
	return &TextEditAction{}
}

func (edit *TextEditAction) Perform(msg *Message) error {
	for _, m := range edit.mutations {
		msg.Text = m.Apply(msg.Text)
	}

	return nil
}

func (edit *TextEditAction) Substitute(search string, sub string) *TextEditAction {
	edit.add(&SubMutation{
		Search: search,
		Sub:    sub,
	})

	return edit
}

func (edit *TextEditAction) Append(app string) *TextEditAction {
	edit.add(&AppendMutation{
		Appendix: app,
	})

	return edit
}

func (edit *TextEditAction) add(m TextMutation) {
	edit.mutations = append(edit.mutations, m)
}

/*
TextTransform represents a string mutation
*/
type TextMutation interface {
	Apply(text string) string
}

type SubMutation struct {
	Search string
	Sub    string
}

type AppendMutation struct {
	Appendix string
}

func (st *SubMutation) Apply(text string) string {
	return strings.Replace(text, st.Search, st.Sub, -1)
}

func (at *AppendMutation) Apply(text string) string {
	if len(at.Appendix) == 0 {
		return text
	}

	return text + at.Appendix
}<commit_msg>Add ReplaceMutation<commit_after>package sirius

import (
	"strings"
)

/*
TextEditAction represents a series of
edits to the message Text property

Usage:

var msg Message

edit := msg.EditText()
edit.Substitute("foo", "bar")
edit.Append("-ending")

 */
type TextEditAction struct {
	mutations []TextMutation
}

func (*Message) EditText() *TextEditAction {
	return &TextEditAction{}
}

func (edit *TextEditAction) Perform(msg *Message) error {
	for _, m := range edit.mutations {
		msg.Text = m.Apply(msg.Text)
	}

	return nil
}

func (edit *TextEditAction) ReplaceWith(replacement string) *TextEditAction {
	edit.add(&ReplaceMutation{
		Replacement: replacement,
	})

	return edit
}

func (edit *TextEditAction) Substitute(search string, sub string) *TextEditAction {
	edit.add(&SubMutation{
		Search: search,
		Sub:    sub,
	})

	return edit
}

func (edit *TextEditAction) Append(app string) *TextEditAction {
	edit.add(&AppendMutation{
		Appendix: app,
	})

	return edit
}

func (edit *TextEditAction) add(m TextMutation) {
	edit.mutations = append(edit.mutations, m)
}

/*
TextTransform represents a string mutation
*/
type TextMutation interface {
	Apply(text string) string
}

type ReplaceMutation struct {
	Replacement string
}

type SubMutation struct {
	Search string
	Sub    string
}

type AppendMutation struct {
	Appendix string
}

func (rm *ReplaceMutation) Apply(text string) string {
	return rm.Replacement
}

func (sm *SubMutation) Apply(text string) string {
	return strings.Replace(text, sm.Search, sm.Sub, -1)
}

func (am *AppendMutation) Apply(text string) string {
	if len(am.Appendix) == 0 {
		return text
	}

	return text + am.Appendix
}
{'fraction_non_alphanumeric': 0.11298315163528246, 'fraction_numerical': 0.0013214403700033035, 'mean_word_length': 4.525547445255475, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1593804', 'n_tokens_mistral': 1050, 'n_tokens_neox': 1013, 'n_words': 287}