當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。