Skip to content

pcre/8.45 #43

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 79 additions & 0 deletions pcre/_demo/html/html.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
package main

import (
"fmt"
"unsafe"

"github.com/goplus/llgo/c"
"github.com/goplus/llpkg/pcre"
)

func main() {
pattern := "Hello (\\w+)"
subject := "Hello World, test."

patternC := c.AllocaCStr(pattern)

subjectC := c.AllocaCStr(subject)

var (
errPtr *int8
erroffset c.Int
errorcode c.Int
)

re := pcre.Compile2(
(*int8)(unsafe.Pointer(patternC)),
0,
&errorcode,
&errPtr,
&erroffset,
nil,
)

if re == nil {
fmt.Printf("Compile fail (code=%d) at offset %d: %s\n",
errorcode,
erroffset,
c.GoString((*c.Char)(unsafe.Pointer(errPtr))),
)
return
}

var ovector [30]c.Int

rc := re.Exec(
nil,
(*int8)(unsafe.Pointer(subjectC)),
c.Int(len(subject)),
0,
0,
&ovector[0],
c.Int(len(ovector)),
)

if rc < 0 {
fmt.Printf("Match fail: %d\n", rc)
return
}

for i := 0; i < int(rc); i++ {
var substrPtr *int8

ret := pcre.GetSubstring(
(*int8)(unsafe.Pointer(subjectC)),
&ovector[0],
c.Int(rc),
c.Int(i),
&substrPtr,
)
if ret < 0 {
fmt.Printf("Submatch fail: %d\n", ret)
continue
}
matchedStr := c.GoString((*c.Char)(unsafe.Pointer(substrPtr)))
fmt.Printf("Capture group #%d = %s\n", i, matchedStr)

pcre.FreeSubstring(substrPtr)
}
}
5 changes: 5 additions & 0 deletions pcre/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module github.com/goplus/llpkg/pcre

go 1.20

require github.com/goplus/llgo v0.10.0
2 changes: 2 additions & 0 deletions pcre/go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
github.com/goplus/llgo v0.10.0 h1:s3U3cnO3cploF1xCCJleAb16NQFAmHxdUmdrNhRH3hY=
github.com/goplus/llgo v0.10.0/go.mod h1:YfOHsT/g3lc9b4GclLj812YzdSsJr0kd3CCB830TqHE=
23 changes: 23 additions & 0 deletions pcre/llcppg.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"name": "pcre",
"cflags": "$(pkg-config --cflags pcre)",
"libs": "$(pkg-config --libs pcre)",
"include": [
"pcre.h",
"pcreposix.h"
],
"trimPrefixes": ["pcre16_", "pcre32_", "pcre_"],
"cplusplus": false,
"deps": ["c/os", "github.com/goplus/llpkg/[email protected]", "github.com/goplus/llpkg/[email protected]"],
"keepUnderScore": false,
"impl": [
{
"files": [],
"cond": {
"os": [],
"arch": []
}
}
],
"mix": false
}
23 changes: 23 additions & 0 deletions pcre/llcppg.pub
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
pcre Pcre
pcre16 Pcre16
pcre16_callout_block CalloutBlock__1
pcre16_extra Extra__1
pcre16_jit_callback JitCallback__1
pcre16_jit_stack JitStack__1
pcre32 Pcre32
pcre32_callout_block CalloutBlock__2
pcre32_extra Extra__2
pcre32_jit_callback JitCallback__2
pcre32_jit_stack JitStack__2
pcre_callout_block CalloutBlock
pcre_extra Extra
pcre_jit_callback JitCallback
pcre_jit_stack JitStack
real_pcre16_jit_stack RealPcre16JitStack
real_pcre32 RealPcre32
real_pcre32_jit_stack RealPcre32JitStack
real_pcre8_or_16 RealPcre8Or16
real_pcre_jit_stack RealPcreJitStack
regex_t RegexT
regmatch_t RegmatchT
regoff_t RegoffT
Loading
Loading