-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
39 lines (32 loc) · 824 Bytes
/
main.go
File metadata and controls
39 lines (32 loc) · 824 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package main
/*
#cgo LDFLAGS: ./lib/diffgen/target/release/libdiffgen.a -ldl
#include "./lib/diffgen.h"
#include <stdlib.h>
*/
import "C"
import (
"fmt"
"unsafe"
"github.com/hexops/gotextdiff"
"github.com/hexops/gotextdiff/myers"
)
func RustDiff(before, after string) string {
diffStr := C.diff(C.CString(string(before)), C.CString(string(after)))
defer C.free(unsafe.Pointer(diffStr))
return C.GoString(diffStr)
}
func GoDiff(before, after string) string {
edits := myers.ComputeEdits("", before, after)
if len(edits) == 0 {
return ""
}
return fmt.Sprint(gotextdiff.ToUnified("before", "after", before, edits))
}
func main() {
str1 := C.CString("world")
str2 := C.CString("this is code from the static library")
defer C.free(unsafe.Pointer(str1))
defer C.free(unsafe.Pointer(str2))
C.hello(str1)
}