本文整理汇总了Golang中strconv.CanBackquote函数的典型用法代码示例。如果您正苦于以下问题:Golang CanBackquote函数的具体用法?Golang CanBackquote怎么用?Golang CanBackquote使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了CanBackquote函数的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: ExampleCanBackquote
func ExampleCanBackquote() {
fmt.Println(strconv.CanBackquote("Fran & Freddie's Diner ☺"))
fmt.Println(strconv.CanBackquote("`can't backquote this`"))
// Output:
// true
// false
}
示例2: replaceStructTag
func replaceStructTag(structField string, replacer func(s string) (string, error)) (string, error) {
pos, end, err := parseStructTag(structField)
if err != nil {
return "", err
}
tag := structField[pos:end]
if tag != "" {
tag, err = strconv.Unquote(tag)
if err != nil {
return "", err
}
}
tag, err = replacer(tag)
if err != nil {
return "", err
}
if strconv.CanBackquote(tag) {
tag = "`" + tag + "`"
} else {
tag = strconv.Quote(tag)
}
if pos == end {
tag = " " + tag
}
return structField[:pos] + tag + structField[end:], nil
}
示例3: fmt_q
// fmt_q formats a string as a double-quoted, escaped Go string constant.
func (f *fmt) fmt_q(s string) {
var quoted string
if f.sharp && strconv.CanBackquote(s) {
quoted = "`" + s + "`"
} else {
quoted = strconv.Quote(s)
}
f.padString(quoted)
}
示例4: Fmt_q
// Fmt_q formats a string as a double-quoted, escaped Go string constant.
func (f *Fmt) Fmt_q(s string) *Fmt {
var quoted string
if f.sharp && strconv.CanBackquote(s) {
quoted = "`" + s + "`"
} else {
quoted = strconv.Quote(s)
}
f.pad(quoted)
f.clearflags()
return f
}
示例5: 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))
}
}
示例6: formatTag
func formatTag(fieldName string) string {
tag := ""
tag = addSubTag(tag, "json", fieldName)
if tag == "" {
return ""
}
if strconv.CanBackquote(tag) {
return "`" + tag + "`"
}
return strconv.Quote(tag)
}
示例7: fmt_q
// fmt_q formats a string as a double-quoted, escaped Go string constant.
func (f *fmt) fmt_q(s string) {
s = f.truncate(s)
var quoted string
if f.sharp && strconv.CanBackquote(s) {
quoted = "`" + s + "`"
} else {
if f.plus {
quoted = strconv.QuoteToASCII(s)
} else {
quoted = strconv.Quote(s)
}
}
f.padString(quoted)
}
示例8: main
func main() {
s := strconv.CanBackquote("C:\\Windows\n")
fmt.Println(s) // false
s = strconv.CanBackquote("C:\\Windows\r")
fmt.Println(s) // false
s = strconv.CanBackquote("C:\\Windows\f")
fmt.Println(s) // false
s = strconv.CanBackquote("C:\\Windows\t")
fmt.Println(s) // true
s = strconv.CanBackquote("C:\\`Windows`")
fmt.Println(s)
fmt.Println(strconv.CanBackquote("Fran & Freddie's Diner ☺"))
fmt.Println(strconv.CanBackquote("`can't backquote this`"))
}
示例9: quote
func quote(s string) string {
if strconv.CanBackquote(s) {
return "`" + s + "`"
}
return strconv.Quote(s)
}