当前位置: 首页>>代码示例>>Golang>>正文


Golang strconv.CanBackquote函数代码示例

本文整理汇总了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
}
开发者ID:RajibTheKing,项目名称:gcc,代码行数:8,代码来源:example_test.go

示例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
}
开发者ID:oov,项目名称:sqruct,代码行数:29,代码来源:struct.go

示例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)
}
开发者ID:ivanwyc,项目名称:google-go,代码行数:10,代码来源:format.go

示例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
}
开发者ID:edisonwsk,项目名称:golang-on-cygwin,代码行数:12,代码来源:format.go

示例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))
	}
}
开发者ID:Samurais,项目名称:go,代码行数:16,代码来源:format.go

示例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)
}
开发者ID:kego,项目名称:ke,代码行数:13,代码来源:type.go

示例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)
}
开发者ID:ptriller,项目名称:dcpu-gcc,代码行数:15,代码来源:format.go

示例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`"))
}
开发者ID:cwen-coder,项目名称:study-gopkg,代码行数:14,代码来源:CanBackquote.go

示例9: quote

func quote(s string) string {
	if strconv.CanBackquote(s) {
		return "`" + s + "`"
	}
	return strconv.Quote(s)
}
开发者ID:ds2dev,项目名称:gcc,代码行数:6,代码来源:regexp.go


注:本文中的strconv.CanBackquote函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。