func check_url(substr, str string) bool { var dst []byte substr_bytes := strconv.AppendQuoteToASCII(dst, substr) str_bytes := strconv.AppendQuoteToASCII(dst, str) index := suffixarray.New(str_bytes) offsets := index.Lookup(substr_bytes, -1) if offsets == nil { return false } return offsets[0] == 0 }
// Converts a big.Int into a slice of bytes. func bigIntToSliceOfBytes(bigInt *big.Int) []byte { // Go1.6 introduced the method bigInt.Append() which makes this conversion // a lot easier. // TODO(erez): Use bigInt.Append() once we switch to GO-1.6. result := strconv.AppendQuoteToASCII([]byte{}, bigInt.String()) // AppendQuoteToASCII adds a double-quoted string. We need to remove them. return result[1 : len(result)-1] }
func ExampleAppendQuoteToASCII() { b := []byte("quote (ascii):") b = strconv.AppendQuoteToASCII(b, `"Fran & Freddie's Diner"`) fmt.Println(string(b)) // Output: // quote (ascii):"\"Fran & Freddie's Diner\"" }
func marshalJSON(results []*metricData) []byte { var b []byte b = append(b, '[') var topComma bool for _, r := range results { if r == nil { continue } if topComma { b = append(b, ',') } topComma = true b = append(b, `{"target":`...) b = strconv.AppendQuoteToASCII(b, r.GetName()) b = append(b, `,"datapoints":[`...) var innerComma bool t := r.GetStartTime() for i, v := range r.Values { if innerComma { b = append(b, ',') } innerComma = true b = append(b, '[') if r.IsAbsent[i] || math.IsInf(v, 0) { b = append(b, "null"...) } else { b = strconv.AppendFloat(b, v, 'f', -1, 64) } b = append(b, ',') b = strconv.AppendInt(b, int64(t), 10) b = append(b, ']') t += r.GetStepTime() } b = append(b, `]}`...) } b = append(b, ']') return b }
// 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)) } }
func main() { b := []byte("quote (ascii):") b = strconv.AppendQuoteToASCII(b, `"Fran & Freddie's Diner"`) fmt.Println(string(b)) }