本文整理匯總了Golang中github.com/robertkrimen/otto.Value.IsPrimitive方法的典型用法代碼示例。如果您正苦於以下問題:Golang Value.IsPrimitive方法的具體用法?Golang Value.IsPrimitive怎麽用?Golang Value.IsPrimitive使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/robertkrimen/otto.Value
的用法示例。
在下文中一共展示了Value.IsPrimitive方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: buildIteratorFromValue
func buildIteratorFromValue(val otto.Value, ts graph.TripleStore) graph.Iterator {
if val.IsNull() || val.IsUndefined() {
return ts.GetNodesAllIterator()
}
if val.IsPrimitive() {
thing, _ := val.Export()
switch v := thing.(type) {
case string:
it := ts.MakeFixed()
it.AddValue(ts.GetIdFor(v))
return it
default:
glog.Errorln("Trying to build unknown primitive value.")
}
}
switch val.Class() {
case "Object":
return buildIteratorTree(val.Object(), ts)
case "Array":
// Had better be an array of strings
strings := makeListOfStringsFromArrayValue(val.Object())
it := ts.MakeFixed()
for _, x := range strings {
it.AddValue(ts.GetIdFor(x))
}
return it
case "Number":
fallthrough
case "Boolean":
fallthrough
case "Date":
fallthrough
case "String":
it := ts.MakeFixed()
str, _ := val.ToString()
it.AddValue(ts.GetIdFor(str))
return it
default:
glog.Errorln("Trying to handle unsupported Javascript value.")
return graph.NewNullIterator()
}
}
示例2: buildIteratorFromValue
func buildIteratorFromValue(val otto.Value, qs graph.QuadStore) graph.Iterator {
if val.IsNull() || val.IsUndefined() {
return qs.NodesAllIterator()
}
if val.IsPrimitive() {
thing, _ := val.Export()
switch v := thing.(type) {
case string:
it := qs.FixedIterator()
it.Add(qs.ValueOf(v))
return it
default:
glog.Errorln("Trying to build unknown primitive value.")
}
}
switch val.Class() {
case "Object":
return buildIteratorTree(val.Object(), qs)
case "Array":
// Had better be an array of strings
strings := stringsFrom(val.Object())
it := qs.FixedIterator()
for _, x := range strings {
it.Add(qs.ValueOf(x))
}
return it
case "Number":
fallthrough
case "Boolean":
fallthrough
case "Date":
fallthrough
case "String":
it := qs.FixedIterator()
it.Add(qs.ValueOf(val.String()))
return it
default:
glog.Errorln("Trying to handle unsupported Javascript value.")
return iterator.NewNull()
}
}
示例3: buildPathFromValue
func buildPathFromValue(val otto.Value) (out []interface{}) {
if val.IsNull() || val.IsUndefined() {
return nil
}
if val.IsPrimitive() {
thing, _ := val.Export()
switch v := thing.(type) {
case string:
out = append(out, v)
return
default:
clog.Errorf("Trying to build unknown primitive value.")
}
}
switch val.Class() {
case "Object":
out = append(out, buildPathFromObject(val.Object()))
return
case "Array":
// Had better be an array of strings
for _, x := range stringsFrom(val.Object()) {
out = append(out, x)
}
return
case "Number":
fallthrough
case "Boolean":
fallthrough
case "Date":
fallthrough
case "String":
out = append(out, val.String())
return
default:
clog.Errorf("Trying to handle unsupported Javascript value.")
return nil
}
}