export_test.go 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. // Copyright 2011 The Go Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style
  3. // license that can be found in the LICENSE file.
  4. package strings
  5. func (r *Replacer) Replacer() any {
  6. r.once.Do(r.buildOnce)
  7. return r.r
  8. }
  9. func (r *Replacer) PrintTrie() string {
  10. r.once.Do(r.buildOnce)
  11. gen := r.r.(*genericReplacer)
  12. return gen.printNode(&gen.root, 0)
  13. }
  14. func (r *genericReplacer) printNode(t *trieNode, depth int) (s string) {
  15. if t.priority > 0 {
  16. s += "+"
  17. } else {
  18. s += "-"
  19. }
  20. s += "\n"
  21. if t.prefix != "" {
  22. s += Repeat(".", depth) + t.prefix
  23. s += r.printNode(t.next, depth+len(t.prefix))
  24. } else if t.table != nil {
  25. for b, m := range r.mapping {
  26. if int(m) != r.tableSize && t.table[m] != nil {
  27. s += Repeat(".", depth) + string([]byte{byte(b)})
  28. s += r.printNode(t.table[m], depth+1)
  29. }
  30. }
  31. }
  32. return
  33. }
  34. func StringFind(pattern, text string) int {
  35. return makeStringFinder(pattern).next(text)
  36. }
  37. func DumpTables(pattern string) ([]int, []int) {
  38. finder := makeStringFinder(pattern)
  39. return finder.badCharSkip[:], finder.goodSuffixSkip
  40. }