go 导入c的 C.cre2_options_t,暂时没跑完

package main

/*
#cgo LDFLAGS: -lre2 -lcre2
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <cre2.h>
*/
import (
	"C"
	"fmt"
	"unsafe"
)

func main() {
	var (
		cre2Opt  *C.cre2_options_t
		set2     *C.cre2_set
		pattern0 = "hello"
		pattern1 = "world"
		pattern2 = "po.*ar"
		pattern3 = "invalid"
		match    [3]C.int
		count    C.size_t
	)
	cre2Opt = (*C.cre2_options_t)(unsafe.Pointer(C.cre2_opt_new()))
	set2 = C.cre2_set_new(unsafe.Pointer(cre2Opt), C.CRE2_UNANCHORED)
	C.cre2_set_add_simple(set2, C.CString(pattern0))
	C.cre2_set_add_simple(set2, C.CString(pattern1))
	C.cre2_set_add_simple(set2, C.CString(pattern2))
	C.cre2_set_add_simple(set2, C.CString(pattern3))
	C.cre2_set_compile(set2)

	// Test second match
	text := "blabla hello polar bear!"
	count = C.cre2_set_match(set2, C.CString(text), C.ulong(len(text)), (*C.int)(unsafe.Pointer(&match)), C.size_t(len(match)))
	if count != 2 || match[0] != 0 || match[1] != 2 {
		fmt.Printf("Failed to match: %s", text)
	} else {
		fmt.Printf("Correctly matched: %s\n", text)
	}

	C.cre2_opt_delete(unsafe.Pointer(cre2Opt))
	C.cre2_set_delete(set2)
}
posted @   ty1539  阅读(17)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 【自荐】一款简洁、开源的在线白板工具 Drawnix
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
· Docker 太简单,K8s 太复杂?w7panel 让容器管理更轻松!
历史上的今天:
2022-03-04 go的rand.Intn()用法和猜年龄, rand.Int()和字符串反转
2022-03-04 go的时间格式和斐波那契函数
2022-03-04 go的字符串处理之分隔
点击右上角即可分享
微信分享提示