fold.go 935 B

12345678910111213141516171819202122232425262728293031323334
  1. // Copyright 2016 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 cases
  5. import "golang.org/x/text/transform"
  6. type caseFolder struct{ transform.NopResetter }
  7. // caseFolder implements the Transformer interface for doing case folding.
  8. func (t *caseFolder) Transform(dst, src []byte, atEOF bool) (nDst, nSrc int, err error) {
  9. c := context{dst: dst, src: src, atEOF: atEOF}
  10. for c.next() {
  11. foldFull(&c)
  12. c.checkpoint()
  13. }
  14. return c.ret()
  15. }
  16. func (t *caseFolder) Span(src []byte, atEOF bool) (n int, err error) {
  17. c := context{src: src, atEOF: atEOF}
  18. for c.next() && isFoldFull(&c) {
  19. c.checkpoint()
  20. }
  21. return c.retSpan()
  22. }
  23. func makeFold(o options) transform.SpanningTransformer {
  24. // TODO: Special case folding, through option Language, Special/Turkic, or
  25. // both.
  26. // TODO: Implement Compact options.
  27. return &caseFolder{}
  28. }