本文整理汇总了Golang中strconv.AppendQuote函数的典型用法代码示例。如果您正苦于以下问题:Golang AppendQuote函数的具体用法?Golang AppendQuote怎么用?Golang AppendQuote使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了AppendQuote函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: main
func main() {
newlist := strconv.AppendQuote(make([]byte, 0), "")
fmt.Println(string(newlist))
newlist = strconv.AppendQuote(make([]byte, 0), "abc")
fmt.Println(string(newlist))
newlist = strconv.AppendQuote(make([]byte, 0), "中文")
fmt.Println(string(newlist))
newlist = strconv.AppendQuote(make([]byte, 0), " ") // \t
fmt.Println(string(newlist))
}
示例2: addData
// Add data in the following format:
// [dataId name="value" name2="value2"][dataId2 name="value"].
func addData(b []byte, data map[string]map[string]string) []byte {
if len(data) == 0 {
b = append(b, nilValueByte)
return b
}
for _, dataID := range getSortedMapMapKeys(data) {
params := data[dataID]
b = append(b, dataStart)
b = append(b, dataID...)
// Add name and value in the following format: ` name="value"`
for _, name := range getSortedMapKeys(params) {
value := params[name]
b = append(b, spaceByte)
b = append(b, name...)
b = append(b, equalByte)
b = strconv.AppendQuote(b, value)
}
b = append(b, dataEnd)
}
return b
}
示例3: ExampleAppendQuote
func ExampleAppendQuote() {
b := []byte("quote:")
b = strconv.AppendQuote(b, `"Fran & Freddie's Diner"`)
fmt.Println(string(b))
// Output:
// quote:"\"Fran & Freddie's Diner\""
}
示例4: WriteAccessLog
func (a *App) WriteAccessLog(req *Req, dur time.Duration) {
if a.accessLog == nil {
return
}
logEvery, _ := a.Cfg.GetInt("gop", "access_log_every", 0)
if logEvery > 0 {
a.suppressedAccessLogLines++
if a.suppressedAccessLogLines < logEvery {
a.Debug("Suppressing access log line [%d/%d]", a.suppressedAccessLogLines, logEvery)
return
}
}
a.suppressedAccessLogLines = 0
// Copy an nginx-log access log
/* ---
gaiadev.leedsdev.net 0.022 192.168.111.1 - - [05/Feb/2014:13:39:22 +0000] "GET /bby/sso/login?next_url=https%3A%2F%2Fgaiadev.leedsdev.net%2F HTTP/1.1" 302 0 "-" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:26.0) Gecko/20100101 Firefox/26.0"
--- */
trimPort := func(s string) string {
colonOffset := strings.IndexByte(s, ':')
if colonOffset >= 0 {
s = s[:colonOffset]
}
return s
}
quote := func(s string) string {
return string(strconv.AppendQuote([]byte{}, s))
}
reqFirstLine := fmt.Sprintf("%s %s %s", req.R.Method, req.R.RequestURI, req.R.Proto)
referrerLine := req.R.Referer()
if referrerLine == "" {
referrerLine = "-"
}
uaLine := req.R.Header.Get("User-Agent")
if uaLine == "" {
uaLine = "-"
}
hostname := a.Hostname()
logLine := fmt.Sprintf("%s %.3f %s %s %s %s %s %d %d %s %s\n",
hostname,
dur.Seconds(),
trimPort(req.RealRemoteIP),
"-", // Ident <giggle>
"-", // user
// req.startTime.Format("[02/Jan/2006:15:04:05 -0700]"),
req.startTime.Format("["+time.RFC3339+"]"),
quote(reqFirstLine),
req.W.code,
req.W.size,
quote(referrerLine),
quote(uaLine))
_, err := req.app.accessLog.WriteString(logLine)
if err != nil {
a.Errorf("Failed to write to access log: %s", err.Error())
}
}
示例5: 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))
}
示例6: main
func main() {
/*
/Enter the Key to be Written
/writtenKey : String
*/
writtenKey := inputData()
fmt.Println("Input Key : ", writtenKey)
/*
/Enter the data to be Written
/writtenData : String
*/
writtenData := inputData()
fmt.Println("Input data : ", writtenData)
/*
/Search or Write of the Start Key
/dbKey : []byte
*/
var dbKey []byte
/*
/DATABASE Open
*/
db := dbOpen()
/*
/Convert Key from String to []byte
*/
dbKey = strconv.AppendQuote(dbKey, writtenKey)
fmt.Println("dbKey is ", string(dbKey))
/*
/DATABASE Put
*/
err := dbPut(db, writtenData, dbKey)
if err != 0 {
fmt.Println("DB Put ERROR")
}
/*
/DATABASE All Read
*/
dbAllRead(db, dbKey)
//fmt.Println("key : ", string(dbKey))
//fmt.Println("data : ", string(dbData))
/*
/DATABASE Close
*/
defer db.Close()
}
示例7: keys
// keys returns the keys that associate a trid with a tag.
func keys(trid string, tag string) (tridKey, tagKey []byte) {
quoted := strconv.AppendQuote(nil, tag)
tridKey = make([]byte, len(trid)+len(quoted))
copy(tridKey, trid)
copy(tridKey[len(trid):], quoted)
tagKey = make([]byte, len(quoted)+len(trid))
copy(tagKey, quoted)
copy(tagKey[len(quoted):], trid)
return tridKey, tagKey
}
示例8: fmt_q
// fmt_q formats a string as a double-quoted, escaped Go string constant.
// If f.sharp is set a raw (backquoted) string may be returned instead
// if the string does not contain any control characters other than tab.
func (f *fmt) fmt_q(s string) {
s = f.truncate(s)
if f.sharp && strconv.CanBackquote(s) {
f.padString("`" + s + "`")
return
}
buf := f.intbuf[:0]
if f.plus {
f.pad(strconv.AppendQuoteToASCII(buf, s))
} else {
f.pad(strconv.AppendQuote(buf, s))
}
}
示例9: 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)
}
示例10: 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)
}
示例11: getTrids
func getTrids(tag string) ([]string, error) {
quoted := strconv.AppendQuote(nil, tag)
trids := []string{}
err := db.View(func(tx *bolt.Tx) error {
b := tx.Bucket(tag2trid)
c := b.Cursor()
for k, _ := c.Seek(quoted); k != nil; k, _ = c.Next() {
if !bytes.HasPrefix(k, quoted) {
break
}
trids = append(trids, string(k[len(quoted):]))
}
return nil
})
return trids, err
}
示例12: main
func main() {
for _, truth := range []string{"1", "t", "TRUE", "false", "F", "0", "5"} {
if b, err := strconv.ParseBool(truth); err != nil {
fmt.Printf("\n%v", err)
} else {
fmt.Print(b, " ")
}
}
fmt.Println()
x, err := strconv.ParseFloat("-99.7", 64)
fmt.Printf("%8T %6v %v\n", x, x, err)
y, err := strconv.ParseInt("71309", 10, 16)
fmt.Printf("%8T %6v %v\n", y, y, err)
z, err := strconv.Atoi("71309")
fmt.Printf("%8T %6v %v\n", z, z, err)
fmt.Println()
s := strconv.FormatBool(z > 100)
fmt.Println(s)
i, err := strconv.ParseInt("0xDEED", 0, 32)
fmt.Println(i, err)
j, err := strconv.ParseInt("0707", 0, 32)
fmt.Println(j, err)
k, err := strconv.ParseInt("10111010001", 2, 32)
fmt.Println(k, err)
m := 16769023
fmt.Println(strconv.Itoa(m))
fmt.Println(strconv.FormatInt(int64(m), 10))
fmt.Println(strconv.FormatInt(int64(m), 2))
fmt.Println(strconv.FormatInt(int64(m), 16))
fmt.Println()
s = "Alle ønsker å være fri."
quoted := strconv.QuoteToASCII(s)
fmt.Println(quoted)
fmt.Println(strconv.Unquote(quoted))
var bs []byte
bs = strconv.AppendQuote(bs, ":thumbs_up:")
fmt.Printf("|%s|% #x|%d|\n", string(bs), bs, bs)
}
示例13: logMultiLine
func (c *C) logMultiLine(s string) {
b := make([]byte, 0, len(s)*2)
i := 0
n := len(s)
for i < n {
j := i + 1
for j < n && s[j-1] != '\n' {
j++
}
b = append(b, "... "...)
b = strconv.AppendQuote(b, s[i:j])
if j < n {
b = append(b, " +"...)
}
b = append(b, '\n')
i = j
}
c.writeLog(b)
}
示例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)
}