go-diff Documentation

repository·master·Indexed 24 days ago

https://github.com/sergi/go-diff

A Go language port of Neil Fraser's google-diff-match-patch. The library provides algorithms for comparing texts, performing fuzzy matching, and applying patches to synchronize plain text via the diffmatchpatch package.

Tokens
344
Snippets
2
Records
3
Agent score
35%

What's inside go-diff

  1. Core capabilities of go-diff

    master

    The go-diff library provides algorithms for synchronizing plain text through three primary operations:

    • Comparison: Comparing two texts to identify their differences.
    • Fuzzy Matching: Performing fuzzy matching of text.
    • Patching: Applying patches onto text to synchronize it.
  2. Compare two texts and display differences

    master

    To compare two strings and visualize the differences, use the diffmatchpatch package.

    1. Initialize a new instance using diffmatchpatch.New().
    2. Generate the differences using DiffMain(text1, text2, semantic).
    3. Convert the differences into a human-readable format using DiffPrettyText(diffs).
    package main
    
    import (
    	"fmt"
    
    	"github.com/sergi/go-diff/diffmatchpatch"
    )
    
    const (
    	text1 = "Lorem ipsum dolor."
    	text2 = "Lorem dolor sit amet."
    )
    
    func main() {
    	dmp := diffmatchpatch.New()
    
    	diffs := dmp.DiffMain(text1, text2, false)
    
    	fmt.Println(dmp.DiffPrettyText(diffs))
    }