-
Notifications
You must be signed in to change notification settings - Fork 0
/
rdf.go
74 lines (64 loc) · 1.13 KB
/
rdf.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package webidrsa
import (
"strings"
rdf "github.com/deiu/rdf2go"
)
var (
ns = struct {
rdf, cert, foaf NS
}{
rdf: NewNS("http://www.w3.org/1999/02/22-rdf-syntax-ns#"),
cert: NewNS("http://www.w3.org/ns/auth/cert#"),
foaf: NewNS("http://xmlns.com/foaf/0.1/"),
}
)
// NS is a generic namespace type
type NS string
// NewNS is used to set a new namespace
func NewNS(base string) (ns NS) {
return NS(base)
}
// Get is used to return the prefix for a namespace
func (ns NS) Get(name string) (term rdf.Term) {
return rdf.NewResource(string(ns) + name)
}
func brack(s string) string {
if len(s) > 0 && s[0] == '<' {
return s
}
if len(s) > 0 && s[len(s)-1] == '>' {
return s
}
return "<" + s + ">"
}
func debrack(s string) string {
if len(s) < 2 {
return s
}
if s[0] != '<' {
return s
}
if s[len(s)-1] != '>' {
return s
}
return s[1 : len(s)-1]
}
func defrag(s string) string {
lst := strings.Split(s, "#")
if len(lst) != 2 {
return s
}
return lst[0]
}
func unquote(s string) string {
if len(s) < 2 {
return s
}
if s[0] != '"' {
return s
}
if s[len(s)-1] != '"' {
return s
}
return s[1 : len(s)-1]
}