init commit
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
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)
|
||||
}
|
||||
Reference in New Issue
Block a user