refactor: tag getter

This commit is contained in:
mzz2017
2023-02-12 11:33:12 +08:00
parent a2bc4793a3
commit c43b6887d7
3 changed files with 16 additions and 27 deletions

View File

@ -340,3 +340,16 @@ func MapKeys(m interface{}) (keys []string, err error) {
}
return keys, nil
}
func GetTagFromLinkLikePlaintext(link string) (tag string, afterTag string) {
iColon := strings.Index(link, ":")
if iColon == -1 {
return "", link
}
// If first colon is like "://" in "scheme://linkbody", no tag is present.
if strings.HasPrefix(link[iColon:], "://") {
return "", link
}
// Else tag is the part before colon.
return link[:iColon], link[iColon+1:]
}