-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathantpath.go
95 lines (78 loc) · 1.86 KB
/
antpath.go
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
package main
//#include <stdlib.h>
import "C"
import (
"encoding/json"
. "github.com/vibrantbyte/go-antpath/antpath"
"unsafe"
)
//pMatcher
var pMatcher PathMatcher
//init
func init(){
pMatcher = New()
}
//export Version
func Version() *C.char{
var cmsg = C.CString("v1.0")
defer C.free(unsafe.Pointer(cmsg))
return cmsg
}
//export Increment
func Increment(value *int) {
*value = *value + 1
}
//export IsPattern
func IsPattern(path string) bool {
return pMatcher.IsPattern(path)
}
//export Match
func Match(pattern,path string) bool{
return pMatcher.Match(pattern,path)
}
//export MatchStart
func MatchStart(pattern,path string) bool{
return pMatcher.MatchStart(pattern,path)
}
//export ExtractPathWithinPattern
func ExtractPathWithinPattern(pattern,path string) *C.char {
result := C.CString(pMatcher.ExtractPathWithinPattern(pattern,path))
defer C.free(unsafe.Pointer(result))
return result
}
//export ExtractUriTemplateVariables
func ExtractUriTemplateVariables(pattern,path string) *C.char {
result := pMatcher.ExtractUriTemplateVariables(pattern,path)
target := "{}"
if result != nil {
b,_ := json.Marshal(result)
target = Bytes2Str(b)
}
cChar := C.CString(target)
defer C.free(unsafe.Pointer(cChar))
return cChar
}
//export Combine
func Combine(pattern1,pattern2 string) *C.char {
result := C.CString(pMatcher.Combine(pattern1,pattern2))
defer C.free(unsafe.Pointer(result))
return result
}
//export SetPathSeparator
func SetPathSeparator(pathSeparator string){
pMatcher.SetPathSeparator(pathSeparator)
}
//export SetCaseSensitive
func SetCaseSensitive(caseSensitive bool){
pMatcher.SetCaseSensitive(caseSensitive)
}
//export SetTrimTokens
func SetTrimTokens(trimTokens bool){
pMatcher.SetTrimTokens(trimTokens)
}
//export SetCachePatterns
func SetCachePatterns(cachePatterns bool){
pMatcher.SetCachePatterns(cachePatterns)
}
//main
func main(){}