代码拉取完成,页面将自动刷新
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
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。