当前位置: 首页>>代码示例>>Golang>>正文


Golang Value.String方法代码示例

本文整理汇总了Golang中github.com/robertkrimen/otto.Value.String方法的典型用法代码示例。如果您正苦于以下问题:Golang Value.String方法的具体用法?Golang Value.String怎么用?Golang Value.String使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/robertkrimen/otto.Value的用法示例。


在下文中一共展示了Value.String方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: formatOneLine

func formatOneLine(v otto.Value, limit int, seen map[otto.Value]bool) (string, error) {
	if limit == 0 {
		return "...", nil
	}

	switch {
	case v.IsBoolean(), v.IsNull(), v.IsNumber(), v.IsUndefined():
		return v.String(), nil
	case v.IsString():
		return fmt.Sprintf("%q", v.String()), nil
	case v.IsFunction():
		n, err := v.Object().Get("name")
		if err != nil {
			return "", err
		}
		if n.IsUndefined() {
			return "function", nil
		}
		return fmt.Sprintf("function %s", n.String()), nil
	case v.IsObject():
		switch v.Class() {
		case "Array":
			return formatArrayOneLine(v, limit, seen)
		default:
			return formatObjectOneLine(v, limit, seen)
		}
	default:
		return "", fmt.Errorf("couldn't format type %s", v.Class())
	}
}
开发者ID:deoxxa,项目名称:ottoext,代码行数:30,代码来源:print.go

示例2: execScript

// Execute Javascript
func (sh *Shell) execScript(editor bool) stateFn {
	var out string
	var value otto.Value
	var err error

	if !editor {
		tmp := strings.TrimPrefix(sh.input, RunJavascript) // remove script meta-command
		value, err = sh.jsengine.Run(tmp)
	} else {
		value, err = sh.jsengine.Run(sh.input)
	}

	if err != nil {
		out = err.Error()
	} else if value.IsDefined() {
		out = value.String()
	}

	sh.write(out)
	if !editor {
		sh.line.AppendHistory(sh.input)
	}

	return bqlPrompt
}
开发者ID:carriercomm,项目名称:bytengine,代码行数:26,代码来源:shell.go

示例3: inspect

func inspect(v otto.Value, width, indent int) string {
	switch {
	case v.IsBoolean(), v.IsNull(), v.IsNumber(), v.IsString(), v.IsUndefined(), v.IsNaN():
		return fmt.Sprintf("%s%q", strings.Repeat("  ", indent), v.String())
	default:
		return ""
	}
}
开发者ID:deoxxa,项目名称:ottoext,代码行数:8,代码来源:repl.go

示例4: buildIteratorFromValue

func buildIteratorFromValue(val otto.Value, ts graph.TripleStore) graph.Iterator {
	if val.IsNull() || val.IsUndefined() {
		return ts.NodesAllIterator()
	}
	if val.IsPrimitive() {
		thing, _ := val.Export()
		switch v := thing.(type) {
		case string:
			it := ts.FixedIterator()
			it.Add(ts.ValueOf(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 := stringsFrom(val.Object())
		it := ts.FixedIterator()
		for _, x := range strings {
			it.Add(ts.ValueOf(x))
		}
		return it
	case "Number":
		fallthrough
	case "Boolean":
		fallthrough
	case "Date":
		fallthrough
	case "String":
		it := ts.FixedIterator()
		it.Add(ts.ValueOf(val.String()))
		return it
	default:
		glog.Errorln("Trying to handle unsupported Javascript value.")
		return iterator.NewNull()
	}
}
开发者ID:Joeento,项目名称:cayley,代码行数:41,代码来源:build_iterator.go

示例5: 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
	}
}
开发者ID:RamboWANG,项目名称:cayley,代码行数:38,代码来源:build_iterator.go

示例6: TriggerEvent

func (s *Scripting) TriggerEvent(eventName string, rawArguments ...interface{}) (err error) {
	var (
		present   bool
		callbacks []otto.Value
		callback  otto.Value
		response  otto.Value
		arguments []interface{}
	)
	if callbacks, present = s.listeners[eventName]; !present {
		return // Not an error to have no listeners.
	}
	if arguments, err = s.convertArguments(rawArguments); err != nil {
		return
	}
	for _, callback = range callbacks {
		if response, err = callback.Call(callback, arguments...); err != nil {
			return
		}
		if response.IsString() {
			fmt.Printf("Response from callback: %s\n", response.String())
		}
	}
	return
}
开发者ID:pikkpoiss,项目名称:twodee,代码行数:24,代码来源:script.go

示例7: formatIndent

func formatIndent(v otto.Value, width, indent, limit, level, additional int, seen map[otto.Value]bool) (string, error) {
	if limit == 0 {
		return "...", nil
	}

	switch {
	case v.IsBoolean(), v.IsNull(), v.IsNumber(), v.IsUndefined():
		return v.String(), nil
	case v.IsString():
		return fmt.Sprintf("%q", v.String()), nil
	case v.IsFunction():
		n, err := v.Object().Get("name")
		if err != nil {
			return "", err
		}
		if n.IsUndefined() {
			return "function", nil
		}
		return fmt.Sprintf("function %s", n.String()), nil
	case v.IsObject():
		if d, err := formatOneLine(v, limit, seen); err != nil {
			return "", err
		} else if level*indent+additional+len(d) <= width {
			return d, nil
		}

		switch v.Class() {
		case "Array":
			return formatArray(v, width, indent, limit, level, seen)
		default:
			return formatObject(v, width, indent, limit, level, seen)
		}
	default:
		return "", fmt.Errorf("couldn't format type %s", v.Class())
	}
}
开发者ID:deoxxa,项目名称:ottoext,代码行数:36,代码来源:print.go


注:本文中的github.com/robertkrimen/otto.Value.String方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。