MCPcopy Create free account
hub / github.com/sergi/go-diff / commonSuffixBytes

Function commonSuffixBytes

diffmatchpatch/diff.go:464–474  ·  view source on GitHub ↗

commonSuffixBytes returns the length in bytes of the common suffix of two strings, never splitting a rune.

(text1, text2 string)

Source from the content-addressed store, hash-verified

462
463// commonSuffixBytes returns the length in bytes of the common suffix of two strings, never splitting a rune.
464func commonSuffixBytes(text1, text2 string) int {
465 n := 0
466 for n < len(text1) && n < len(text2) {
467 _, size := utf8.DecodeLastRuneInString(text1[:len(text1)-n])
468 if size > len(text2)-n || text1[len(text1)-n-size:len(text1)-n] != text2[len(text2)-n-size:len(text2)-n] {
469 break
470 }
471 n += size
472 }
473 return n
474}
475
476// DiffCommonOverlap determines if the suffix of one string is the prefix of another.
477func (dmp *DiffMatchPatch) DiffCommonOverlap(text1 string, text2 string) int {

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected