diff options
author | 2021-12-23 13:15:26 +0100 | |
---|---|---|
committer | 2021-12-23 13:55:38 +0100 | |
commit | 57311daf54ab12f7a1af5a844ad60fa6af0e7283 (patch) | |
tree | dcdd424a68485b67df5f117d2a243748eed8e7f4 /cbinding.go | |
download | translate-highlight-from-c-to-go-master.tar.xz translate-highlight-from-c-to-go-master.zip |
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to 'cbinding.go')
-rw-r--r-- | cbinding.go | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/cbinding.go b/cbinding.go new file mode 100644 index 0000000..7866539 --- /dev/null +++ b/cbinding.go @@ -0,0 +1,27 @@ +/* SPDX-License-Identifier: MIT + * + * Copyright (C) 2019-2021 WireGuard LLC. All Rights Reserved. + */ + +package syntax + +// #include "highlighter.h" +// #include <stdlib.h> +import "C" +import ( + "unsafe" +) + +func highlightConfigC(config string) []highlightSpan { + b := append([]byte(config), 0) + highlights := C.highlight_config((*C.char)(unsafe.Pointer(&b[0]))) + if highlights == nil { + return nil + } + var ret []highlightSpan + for i := highlights; i._type != C.HighlightEnd; i = (*C.struct_highlight_span)(unsafe.Add(unsafe.Pointer(i), unsafe.Sizeof(*i))) { + ret = append(ret, highlightSpan{highlight(i._type), int(i.start), int(i.len)}) + } + C.free(unsafe.Pointer(highlights)) + return ret +} |