41 lines
778 B
Go
41 lines
778 B
Go
package keyword
|
|
|
|
var intern_map map[string]*Keyword
|
|
|
|
type Keyword struct {
|
|
ns string
|
|
keyword string
|
|
}
|
|
|
|
func Intern(keyword string) *Keyword {
|
|
return Intern_ns("", keyword)
|
|
}
|
|
|
|
func Intern_ns(ns string, keyword string) *Keyword {
|
|
combined_str := ns + "/" + keyword
|
|
existingkeyword, ok := intern_map[combined_str]
|
|
if ok {
|
|
return existingkeyword
|
|
} else {
|
|
newkeyword := new(Keyword)
|
|
newkeyword.ns = ns
|
|
newkeyword.keyword = keyword
|
|
if intern_map == nil {
|
|
intern_map = make(map[string]*Keyword)
|
|
}
|
|
intern_map[combined_str] = newkeyword
|
|
return newkeyword
|
|
}
|
|
}
|
|
|
|
func String(this *Keyword) string {
|
|
if this.ns == "" {
|
|
return ":" + this.keyword
|
|
}
|
|
return ":" + this.ns + "/" + this.keyword
|
|
}
|
|
|
|
func (this *Keyword) String() string {
|
|
return String(this)
|
|
}
|