<commit_before>package triematcher

import (
	"os"
	"text/template"
)

var templateFile = template.Must(template.New("file").Parse(`
// DO NOT EDIT!
// Code generated by go-triematcher <https://github.com/Maki-Daisuke/go-triematcher>
// DO NOT EDIT!

package {{ .PackageName }}

import (
  "strings"
)

func {{ .FuncName }}(str string) bool {
  defer func(){
    recover() // Must be "index out of range" error for string.
              // Ignore and return false.
  }()

  goto STATE_{{ with index .States 0 }}{{ .Id }}{{ end }}
{{ range .States }}
  STATE_{{ .Id }}:
  {{ if .IsGoal }}
      return len(str) == 0
  {{ else }}
    switch{
    {{ range .OutBounds }}
      case strings.HasPrefix(str, {{ printf "%q" .Key }}):
        str = str[{{ .Key | len }}:]
        goto STATE_{{ .State.Id }}
    {{ end }}
      default:
        return false
    }
  {{ end }}
{{ end }}
}
`))

func generate(pkg_name, func_name string, st *state) {
	err := templateFile.Execute(os.Stdout, map[string]interface{}{
		"PackageName": pkg_name,
		"FuncName":    func_name,
		"States":      allStates(st),
	})
	if err != nil {
		panic(err)
	}
}
<commit_msg>generate() receives io.Writer for output.<commit_after>package triematcher

import (
	"io"
	"text/template"
)

var templateFile = template.Must(template.New("file").Parse(`
// DO NOT EDIT!
// Code generated by go-triematcher <https://github.com/Maki-Daisuke/go-triematcher>
// DO NOT EDIT!

package {{ .PackageName }}

import (
  "strings"
)

func {{ .FuncName }}(str string) bool {
  defer func(){
    recover() // Must be "index out of range" error for string.
              // Ignore and return false.
  }()

  goto STATE_{{ with index .States 0 }}{{ .Id }}{{ end }}
{{ range .States }}
  STATE_{{ .Id }}:
  {{ if .IsGoal }}
      return len(str) == 0
  {{ else }}
    switch{
    {{ range .OutBounds }}
      case strings.HasPrefix(str, {{ printf "%q" .Key }}):
        str = str[{{ .Key | len }}:]
        goto STATE_{{ .State.Id }}
    {{ end }}
      default:
        return false
    }
  {{ end }}
{{ end }}
}
`))

func generate(w io.Writer, pkg_name, func_name string, st *state) error {
	err := templateFile.Execute(w, map[string]interface{}{
		"PackageName": pkg_name,
		"FuncName":    func_name,
		"States":      allStates(st),
	})
	if err != nil {
		return err
	} else {
		return nil
	}
}

{'fraction_non_alphanumeric': 0.17634500426985483, 'fraction_numerical': 0.0017079419299743809, 'mean_word_length': 2.6438569206842923, 'pattern_counts': {'":': 6, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 2, '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': '5845915', 'n_tokens_mistral': 844, 'n_tokens_neox': 803, 'n_words': 215}