本文整理汇总了Golang中go/constant.Value.String方法的典型用法代码示例。如果您正苦于以下问题:Golang Value.String方法的具体用法?Golang Value.String怎么用?Golang Value.String使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类go/constant.Value
的用法示例。
在下文中一共展示了Value.String方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: valString
// valString returns the string representation for the value v.
// Setting floatFmt forces an integer value to be formatted in
// normalized floating-point format.
// TODO(gri) Move this code into package exact.
func valString(v exact.Value, floatFmt bool) string {
switch v.Kind() {
case exact.Int:
if floatFmt {
return floatString(v)
}
case exact.Float:
return floatString(v)
case exact.Complex:
re := exact.Real(v)
im := exact.Imag(v)
var s string
if exact.Sign(re) != 0 {
s = floatString(re)
if exact.Sign(im) >= 0 {
s += " + "
} else {
s += " - "
im = exact.UnaryOp(token.SUB, im, 0) // negate im
}
}
// im != 0, otherwise v would be exact.Int or exact.Float
return s + floatString(im) + "i"
}
return v.String()
}
示例2: constValString
// constValString emulates Go 1.6's go/constant.ExactString well enough
// to make the tests pass. This is just a stopgap until we throw away
// all the *15.go files.
func constValString(v exact.Value) string {
if v.Kind() == exact.Float {
f, _ := exact.Float64Val(v)
return fmt.Sprintf("%g", f)
}
return v.String()
}
示例3: constValString
// Helper function to adjust go1.5 numeric go/constant formatting.
// Can be removed once we give up compatibility with go1.5.
func constValString(v exact.Value) string {
if v.Kind() == exact.Float {
// In go1.5, go/constant floating-point values are printed
// as fractions. Make them appear as floating-point numbers.
f, _ := exact.Float64Val(v)
return fmt.Sprintf("%g", f)
}
return v.String()
}
示例4: convertConstantValue
func (c *converter) convertConstantValue(v goconstant.Value) constant.Value {
if v == nil {
return nil
}
if v, ok := c.converted[v]; ok {
return v.(constant.Value)
}
var ret constant.Value
switch v.Kind() {
case goconstant.Bool:
ret = constant.MakeBool(goconstant.BoolVal(v))
case goconstant.String:
ret = constant.MakeString(goconstant.StringVal(v))
case goconstant.Int:
ret = constant.MakeFromLiteral(v.String(), token.INT, 0)
case goconstant.Float:
ret = constant.MakeFromLiteral(v.String(), token.FLOAT, 0)
case goconstant.Complex:
ret = constant.MakeFromLiteral(v.String(), token.IMAG, 0)
}
c.converted[v] = ret
return ret
}