当前仓库属于暂停状态,部分功能使用受限,详情请查阅 仓库状态说明
1 Star 0 Fork 0

Simbory / mego
暂停

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
annotation.go 1.15 KB
一键复制 编辑 原始数据 按行查看 历史
package common
import (
"bytes"
"errors"
"fmt"
"regexp"
"strings"
)
type AnnotationMap map[string]string
func (ann AnnotationMap) ContainsKey(key string) bool {
_, ok := ann[key]
return ok
}
func (ann AnnotationMap) String() string {
sb := &bytes.Buffer{}
for key, value := range ann {
if sb.Len() > 0 {
sb.WriteString(", ")
}
if len(value) == 0 {
sb.WriteString(key)
} else {
sb.WriteString(fmt.Sprintf("%s=%s", key, value))
}
}
return "// " + sb.String()
}
func ParseAnnotation(line string) (result AnnotationMap, err error) {
reg1 := regexp.MustCompile("^//[\t ]*@.+")
reg2 := regexp.MustCompile("^@[a-zA-Z][a-zA-Z0-9_]*(=.+)?$")
if !reg1.MatchString(line) {
return nil, nil
}
line = strings.Trim(line, "/\t ")
lines := strings.Split(line, ",")
result = make(AnnotationMap)
for _, annotation := range lines {
annotation = strings.TrimSpace(annotation)
if !reg2.MatchString(annotation) {
return nil, errors.New("invalid annotation: " + annotation)
}
eqIndex := strings.Index(annotation, "=")
if eqIndex > 0 {
result[annotation[0:eqIndex]] = annotation[eqIndex+1:]
} else {
result[annotation] = ""
}
}
return
}
Go
1
https://gitee.com/simbory/mego.git
git@gitee.com:simbory/mego.git
simbory
mego
mego
v1.1.1

搜索帮助

53164aa7 5694891 3bd8fe86 5694891