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

	// Output:
	// true
	// false
}
Ejemplo n.º 2
0
Archivo: struct.go Proyecto: 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
}
Ejemplo n.º 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)
}
Ejemplo n.º 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
}
Ejemplo n.º 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))
	}
}
Ejemplo n.º 6
0
Archivo: type.go Proyecto: 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)
}
Ejemplo n.º 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)
}
Ejemplo n.º 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`"))
}
Ejemplo n.º 9
0
Archivo: regexp.go Proyecto: ds2dev/gcc
func quote(s string) string {
	if strconv.CanBackquote(s) {
		return "`" + s + "`"
	}
	return strconv.Quote(s)
}