本文整理汇总了Golang中strconv.AppendBool函数的典型用法代码示例。如果您正苦于以下问题:Golang AppendBool函数的具体用法?Golang AppendBool怎么用?Golang AppendBool使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了AppendBool函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: encodeDefault
func encodeDefault(object interface{}) (buffer []byte, err error) {
switch object.(type) {
case bool:
buffer = strconv.AppendBool(buffer, object.(bool))
case int:
buffer = strconv.AppendInt(buffer, int64(object.(int)), _NUMERIC_BASE)
case int8:
buffer = strconv.AppendInt(buffer, int64(object.(int8)), _NUMERIC_BASE)
case int16:
buffer = strconv.AppendInt(buffer, int64(object.(int16)), _NUMERIC_BASE)
case int32:
buffer = strconv.AppendInt(buffer, int64(object.(int32)), _NUMERIC_BASE)
case int64:
buffer = strconv.AppendInt(buffer, object.(int64), _NUMERIC_BASE)
case uint:
buffer = strconv.AppendUint(buffer, uint64(object.(uint)), _NUMERIC_BASE)
case uint8:
buffer = strconv.AppendUint(buffer, uint64(object.(uint8)), _NUMERIC_BASE)
case uint16:
buffer = strconv.AppendUint(buffer, uint64(object.(uint16)), _NUMERIC_BASE)
case uint32:
buffer = strconv.AppendUint(buffer, uint64(object.(uint32)), _NUMERIC_BASE)
case uint64:
buffer = strconv.AppendUint(buffer, object.(uint64), _NUMERIC_BASE)
case string:
buffer = []byte(object.(string))
case []byte:
buffer = object.([]byte)
default:
err = errors.New("Invalid object for default encode")
}
return
}
示例2: encode
func encode(parameterStatus *parameterStatus, x interface{}, pgtypOid oid.Oid) []byte {
switch v := x.(type) {
case int64:
return strconv.AppendInt(nil, v, 10)
case float64:
return strconv.AppendFloat(nil, v, 'f', -1, 64)
case []byte:
if pgtypOid == oid.T_bytea {
return encodeBytea(parameterStatus.serverVersion, v)
}
return v
case string:
if pgtypOid == oid.T_bytea {
return encodeBytea(parameterStatus.serverVersion, []byte(v))
}
return []byte(v)
case bool:
return strconv.AppendBool(nil, v)
case time.Time:
return formatTs(v)
default:
errorf("encode: unknown type for %T", v)
}
panic("not reached")
}
示例3: appendField
func appendField(b []byte, k string, v interface{}) []byte {
b = append(b, []byte(escape.String(k))...)
b = append(b, '=')
// check popular types first
switch v := v.(type) {
case float64:
b = strconv.AppendFloat(b, v, 'f', -1, 64)
case int64:
b = strconv.AppendInt(b, v, 10)
b = append(b, 'i')
case string:
b = append(b, '"')
b = append(b, []byte(EscapeStringField(v))...)
b = append(b, '"')
case bool:
b = strconv.AppendBool(b, v)
case int32:
b = strconv.AppendInt(b, int64(v), 10)
b = append(b, 'i')
case int16:
b = strconv.AppendInt(b, int64(v), 10)
b = append(b, 'i')
case int8:
b = strconv.AppendInt(b, int64(v), 10)
b = append(b, 'i')
case int:
b = strconv.AppendInt(b, int64(v), 10)
b = append(b, 'i')
case uint32:
b = strconv.AppendInt(b, int64(v), 10)
b = append(b, 'i')
case uint16:
b = strconv.AppendInt(b, int64(v), 10)
b = append(b, 'i')
case uint8:
b = strconv.AppendInt(b, int64(v), 10)
b = append(b, 'i')
// TODO: 'uint' should be considered just as "dangerous" as a uint64,
// perhaps the value should be checked and capped at MaxInt64? We could
// then include uint64 as an accepted value
case uint:
b = strconv.AppendInt(b, int64(v), 10)
b = append(b, 'i')
case float32:
b = strconv.AppendFloat(b, float64(v), 'f', -1, 32)
case []byte:
b = append(b, v...)
case nil:
// skip
default:
// Can't determine the type, so convert to string
b = append(b, '"')
b = append(b, []byte(EscapeStringField(fmt.Sprintf("%v", v)))...)
b = append(b, '"')
}
return b
}
示例4: appendEncodedText
// appendEncodedText encodes item in text format as required by COPY
// and appends to buf
func appendEncodedText(parameterStatus *parameterStatus, buf []byte, x interface{}) []byte {
switch v := x.(type) {
case int64:
return strconv.AppendInt(buf, v, 10)
case float32:
return strconv.AppendFloat(buf, float64(v), 'f', -1, 32)
case float64:
return strconv.AppendFloat(buf, v, 'f', -1, 64)
case []byte:
encodedBytea := encodeBytea(parameterStatus.serverVersion, v)
return appendEscapedText(buf, string(encodedBytea))
case string:
return appendEscapedText(buf, v)
case bool:
return strconv.AppendBool(buf, v)
case time.Time:
return append(buf, v.Format(time.RFC3339Nano)...)
case nil:
return append(buf, "\\N"...)
default:
errorf("encode: unknown type for %T", v)
}
panic("not reached")
}
示例5: ExampleAppendBool
func ExampleAppendBool() {
b := []byte("bool:")
b = strconv.AppendBool(b, true)
fmt.Println(string(b))
// Output:
// bool:true
}
示例6: AppendTest
func AppendTest() {
//Append 系列函数将整数等转换为字符串后,添加到现有的字节数组中。
str := make([]byte, 0, 100)
str = strconv.AppendInt(str, 4567, 10)
str = strconv.AppendBool(str, false)
str = strconv.AppendQuote(str, "abcdefg")
str = strconv.AppendQuoteRune(str, '单')
fmt.Println(string(str))
}
示例7: String
func (b boolParser) String() string {
w := []byte{}
for i, t := range b {
if i > 0 {
w = append(w, ' ')
}
w = strconv.AppendBool(w, t)
}
return string(w)
}
示例8: bytesFromIf
func bytesFromIf(v interface{}) (b []byte, err error) {
switch v := v.(type) {
case []byte:
b = v
case *[]byte:
b = *v
case string:
b = []byte(v)
case *string:
b = []byte(*v)
case int64:
b = strconv.AppendInt(b, v, 10)
case *int64:
b = strconv.AppendInt(b, *v, 10)
case int32:
b = strconv.AppendInt(b, int64(v), 10)
case *int32:
b = strconv.AppendInt(b, int64(*v), 10)
case int:
b = strconv.AppendInt(b, int64(v), 10)
case *int:
b = strconv.AppendInt(b, int64(*v), 10)
case float64:
b = strconv.AppendFloat(b, v, 'f', -1, 64)
case *float64:
b = strconv.AppendFloat(b, *v, 'f', -1, 64)
case float32:
b = strconv.AppendFloat(b, float64(v), 'f', -1, 64)
case *float32:
b = strconv.AppendFloat(b, float64(*v), 'f', -1, 64)
case bool:
b = strconv.AppendBool(b, v)
case *bool:
b = strconv.AppendBool(b, *v)
case fmt.Stringer:
b = []byte(v.String())
case Interfacer:
b, err = bytesFromIf(v.Interface())
default:
return b, errors.New("[]byte value expected")
}
return
}
示例9: MarshalJSON
func (v *Value) MarshalJSON() ([]byte, error) {
b := []byte{}
switch v.t {
case BoolType:
return strconv.AppendBool(b, *v.b), nil
case FloatType:
return strconv.AppendFloat(b, *v.f, 'f', -1, 64), nil
case MapType:
return json.Marshal(v.m)
default:
return nil, fmt.Errorf("unsupported Value type")
}
}
示例10: Teststrings
func Teststrings() {
//字符串s中是否包含substr,返回bool值
fmt.Println(strings.Contains("seafood", "foo"))
fmt.Println(strings.Contains("seafood", "bar"))
fmt.Println(strings.Contains("seafood", ""))
fmt.Println(strings.Contains("", ""))
s := []string{"foo", "bar", "baz"}
//字符串链接,把slice a通过sep链接起来
fmt.Println(strings.Join(s, ", "))
//在字符串s中查找sep所在的位置,返回位置值,找不到返回-1
fmt.Println(strings.Index("chicken", "ken"))
fmt.Println(strings.Index("chicken", "dmr"))
//重复s字符串count次,最后返回重复的字符串
fmt.Println("ba" + strings.Repeat("na", 2))
//在s字符串中,把old字符串替换为new字符串,n表示替换的次数,小于0表示全部替换
fmt.Println(strings.Replace("oink oink oink", "k", "ky", 2))
fmt.Println(strings.Replace("oink oink oink", "oink", "moo", -1))
//把s字符串按照sep分割,返回slice
fmt.Printf("%q\n", strings.Split("a,b,c", ","))
fmt.Printf("%q\n", strings.Split("a man a plan a canal panama", "a "))
fmt.Printf("%q\n", strings.Split(" xyz ", ""))
fmt.Printf("%q\n", strings.Split("", "Bernardo O'Higgins"))
//在s字符串中去除cutset指定的字符串
fmt.Printf("[%q]\n", strings.Trim(" !!! Achtung !!! ", "! "))
//去除s字符串的空格符,并且按照空格分割返回slice
fmt.Printf("Fields are: %q\n", strings.Fields(" foo bar baz "))
//Append 系列函数将整数等转换为字符串后,添加到现有的字节数组中。
str := make([]byte, 0, 100)
str = strconv.AppendInt(str, 4567, 10)
str = strconv.AppendBool(str, false)
str = strconv.AppendQuote(str, "abcdefg")
str = strconv.AppendQuoteRune(str, '单')
fmt.Println(string(str))
//Format 系列函数把其他类型的转换为字符串
a := strconv.FormatBool(false)
b := strconv.FormatFloat(123.23, 'g', 12, 64)
c := strconv.FormatInt(1234, 10)
d := strconv.FormatUint(12345, 10)
e := strconv.Itoa(1023)
fmt.Println(a, b, c, d, e)
}
示例11: main
func main() {
var s []byte = make([]byte, 0)
s = strconv.AppendBool(s, true)
fmt.Println(string(s)) // true: true를 문자열로 변환하여 "true"
s = strconv.AppendFloat(s, 1.3, 'f', -1, 32) // dst, f, fmt, prec, bitSize
fmt.Println(string(s)) // true1.3: 1.3을 문자열로 변환하여 "1.3", 슬라이스 뒤에 붙여서 true1.3
s = strconv.AppendInt(s, -10, 10)
fmt.Println(string(s)) // true1.3-10: -10을 10진수로된 문자열로 변환하여 "-10",
// 슬라이스 뒤에 붙여서 true1.3-10
s = strconv.AppendUint(s, 32, 16)
fmt.Println(string(s)) // true1.3-1020: 32를 16진수로된 문자열로 변환하여 "20",
// 슬라이스 뒤에 붙여서 true1.3-1020
}
示例12: main
func main() {
str := make([]byte, 0, 100)
str = strconv.AppendInt(str, 4567, 10)
str = strconv.AppendBool(str, false)
str = strconv.AppendQuote(str, "adcdef")
str = strconv.AppendQuoteRune(str, '中')
fmt.Println(string(str))
fl := strconv.FormatFloat(123.23, 'g', 12, 64)
fmt.Println(fl)
ui, err := strconv.ParseUint("12345", 10, 64)
if err != nil {
fmt.Println(err)
}
fmt.Println(ui + 10)
}
示例13: asBytes
func asBytes(buf []byte, rv reflect.Value) (b []byte, ok bool) {
switch rv.Kind() {
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
return strconv.AppendInt(buf, rv.Int(), 10), true
case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64:
return strconv.AppendUint(buf, rv.Uint(), 10), true
case reflect.Float32:
return strconv.AppendFloat(buf, rv.Float(), 'g', -1, 32), true
case reflect.Float64:
return strconv.AppendFloat(buf, rv.Float(), 'g', -1, 64), true
case reflect.Bool:
return strconv.AppendBool(buf, rv.Bool()), true
case reflect.String:
s := rv.String()
return append(buf, s...), true
}
return
}
示例14: processString
func processString() {
str := make([]byte, 0, 100)
// str := ""
fmt.Println(str)
str = strconv.AppendInt(str, 4567, 10)
str = strconv.AppendBool(str, false)
str = strconv.AppendQuote(str, "abcde")
str = strconv.AppendQuoteRune(str, '周')
fmt.Println(str)
fmt.Println(string(str))
str1 := strconv.FormatBool(false)
fmt.Println(str1)
str1 = strings.Repeat(str1, 2)
fmt.Println(str1)
fmt.Println(strings.Contains(str1, "al"))
fmt.Println(strings.Index(str1, "al"))
fmt.Println(strings.Trim("!a james May !a", "!a"))
}
示例15: main
func main() {
// Append , 转换并添加到现有字符串
str := make([]byte, 0, 1000)
str = strconv.AppendInt(str, 4567, 10)
str = strconv.AppendBool(str, false)
str = strconv.AppendQuote(str, "abcdefg")
str = strconv.AppendQuoteRune(str, '单')
fmt.Println(string(str))
// Format 把其他类型转成字符串
a := strconv.FormatBool(false)
b := strconv.FormatFloat(123.23, 'g', 12, 64)
c := strconv.FormatInt(1234, 10)
d := strconv.FormatUint(12345, 10)
e := strconv.Itoa(1023)
fmt.Println(a, b, c, d, e)
// Parse 把字符串转为其他类型
a1, err := strconv.ParseBool("false")
if err != nil {
fmt.Println(err)
} else {
fmt.Println(a1)
}
b1, err := strconv.ParseFloat("123.23", 64)
c1, err := strconv.ParseInt("1234", 10, 64)
d1, err := strconv.ParseUint("12345", 10, 64)
fmt.Println(a1, b1, c1, d1)
}