當前位置: 首頁>>代碼示例>>Golang>>正文


Golang strconv.AppendBool函數代碼示例

本文整理匯總了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
}
開發者ID:varstr,項目名稱:gomc,代碼行數:33,代碼來源:encoding.go

示例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")
}
開發者ID:slamice,項目名稱:potb,代碼行數:29,代碼來源:encode.go

示例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
}
開發者ID:li-ang,項目名稱:influxdb,代碼行數:60,代碼來源:points.go

示例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")
}
開發者ID:ericcapricorn,項目名稱:flynn,代碼行數:27,代碼來源:encode.go

示例5: ExampleAppendBool

func ExampleAppendBool() {
	b := []byte("bool:")
	b = strconv.AppendBool(b, true)
	fmt.Println(string(b))

	// Output:
	// bool:true
}
開發者ID:RajibTheKing,項目名稱:gcc,代碼行數:8,代碼來源:example_test.go

示例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))
}
開發者ID:yunkaiyueming,項目名稱:go_code,代碼行數:9,代碼來源:strconv.go

示例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)
}
開發者ID:gamesbrainiac,項目名稱:lemon,代碼行數:10,代碼來源:parser.go

示例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
}
開發者ID:rowland,項目名稱:go-fb,代碼行數:43,代碼來源:support.go

示例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")
	}
}
開發者ID:zgiber,項目名稱:tree,代碼行數:13,代碼來源:value.go

示例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)

}
開發者ID:jackyfan,項目名稱:gostudy,代碼行數:51,代碼來源:teststrings.go

示例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
}
開發者ID:jemoonkim,項目名稱:golangbook,代碼行數:17,代碼來源:strconv_Append.go

示例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)
}
開發者ID:Ferrari,項目名稱:playground,代碼行數:17,代碼來源:string.go

示例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
}
開發者ID:chanxuehong,項目名稱:database,代碼行數:18,代碼來源:convert.go

示例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"))
}
開發者ID:zhouzhefu,項目名稱:go-projects-src,代碼行數:21,代碼來源:TextProcess.go

示例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)

}
開發者ID:hycxa,項目名稱:KeepLearning,代碼行數:39,代碼來源:stringconvtest.go


注:本文中的strconv.AppendBool函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。