Example #1
0
func ExampleCanBackquote() {
	fmt.Println(strconv.CanBackquote("Fran & Freddie's Diner ☺"))
	fmt.Println(strconv.CanBackquote("`can't backquote this`"))

	// Output:
	// true
	// false
}
Example #2
0
File: struct.go Project: oov/sqruct
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
}
Example #3
0
// 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)
}
Example #4
0
// 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
}
Example #5
0
// 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))
	}
}
Example #6
0
File: type.go Project: kego/ke
func formatTag(fieldName string) string {

	tag := ""
	tag = addSubTag(tag, "json", fieldName)

	if tag == "" {
		return ""
	}
	if strconv.CanBackquote(tag) {
		return "`" + tag + "`"
	}
	return strconv.Quote(tag)
}
Example #7
0
// 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)
}
Example #8
0
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`"))
}
Example #9
0
File: regexp.go Project: ds2dev/gcc
func quote(s string) string {
	if strconv.CanBackquote(s) {
		return "`" + s + "`"
	}
	return strconv.Quote(s)
}