本站源代码
No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

47 líneas
1.8KB

  1. // Copyright (c) 2012-2016 The go-diff authors. All rights reserved.
  2. // https://github.com/sergi/go-diff
  3. // See the included LICENSE file for license details.
  4. //
  5. // go-diff is a Go implementation of Google's Diff, Match, and Patch library
  6. // Original library is Copyright (c) 2006 Google Inc.
  7. // http://code.google.com/p/google-diff-match-patch/
  8. // Package diffmatchpatch offers robust algorithms to perform the operations required for synchronizing plain text.
  9. package diffmatchpatch
  10. import (
  11. "time"
  12. )
  13. // DiffMatchPatch holds the configuration for diff-match-patch operations.
  14. type DiffMatchPatch struct {
  15. // Number of seconds to map a diff before giving up (0 for infinity).
  16. DiffTimeout time.Duration
  17. // Cost of an empty edit operation in terms of edit characters.
  18. DiffEditCost int
  19. // How far to search for a match (0 = exact location, 1000+ = broad match). A match this many characters away from the expected location will add 1.0 to the score (0.0 is a perfect match).
  20. MatchDistance int
  21. // When deleting a large block of text (over ~64 characters), how close do the contents have to be to match the expected contents. (0.0 = perfection, 1.0 = very loose). Note that MatchThreshold controls how closely the end points of a delete need to match.
  22. PatchDeleteThreshold float64
  23. // Chunk size for context length.
  24. PatchMargin int
  25. // The number of bits in an int.
  26. MatchMaxBits int
  27. // At what point is no match declared (0.0 = perfection, 1.0 = very loose).
  28. MatchThreshold float64
  29. }
  30. // New creates a new DiffMatchPatch object with default parameters.
  31. func New() *DiffMatchPatch {
  32. // Defaults.
  33. return &DiffMatchPatch{
  34. DiffTimeout: time.Second,
  35. DiffEditCost: 4,
  36. MatchThreshold: 0.5,
  37. MatchDistance: 1000,
  38. PatchDeleteThreshold: 0.5,
  39. PatchMargin: 4,
  40. MatchMaxBits: 32,
  41. }
  42. }
上海开阖软件有限公司 沪ICP备12045867号-1