2016-07-20 18:58:48 +00:00
|
|
|
package mtree
|
|
|
|
|
|
|
|
// #include "vis.h"
|
2016-07-21 01:18:27 +00:00
|
|
|
// #include <stdlib.h>
|
2016-07-20 18:58:48 +00:00
|
|
|
import "C"
|
2016-07-21 01:18:27 +00:00
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"unsafe"
|
|
|
|
)
|
2016-07-20 18:58:48 +00:00
|
|
|
|
2016-07-21 01:18:27 +00:00
|
|
|
// Unvis is a wrapper for the C implementation of unvis, which decodes a string
|
|
|
|
// that potentially has characters that are encoded with Vis
|
|
|
|
func Unvis(src string) (string, error) {
|
|
|
|
cDst, cSrc := C.CString(string(make([]byte, len(src)+1))), C.CString(src)
|
|
|
|
defer C.free(unsafe.Pointer(cDst))
|
|
|
|
defer C.free(unsafe.Pointer(cSrc))
|
|
|
|
ret := C.strunvis(cDst, cSrc)
|
|
|
|
if ret == -1 {
|
|
|
|
return "", fmt.Errorf("failed to decode: %q", src)
|
2016-07-20 18:58:48 +00:00
|
|
|
}
|
2016-07-21 01:18:27 +00:00
|
|
|
return C.GoString(cDst), nil
|
2016-07-20 18:58:48 +00:00
|
|
|
}
|