Every line of 'golang backtick string' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your Go code is secure.
103 func addBackticks(arg string) string { 104 reg := regexp.MustCompile(`^\w+$`) 105 if reg.MatchString(arg) { 106 return fmt.Sprintf("`%s`", arg) 107 } 108 return arg 109 }
46 func formatFloatTick(v float64, prec int) string { 47 return strconv.FormatFloat(scalar.Round(v, prec), 'g', displayPrecision, 64) 48 }
556 func naivelyquote(s string) string { 557 return fmt.Sprintf("'%s'", strings.Replace(s, "'", "''", -1)) 558 }
220 func (f *StringFuncs) Quote(in interface{}) string { 221 return fmt.Sprintf("%q", conv.ToString(in)) 222 }
29 func plan9quote(s string) string { 30 if s == "" { 31 return "''" 32 } 33 for _, c := range s { 34 if c <= ' ' || c == '\'' { 35 return "'" + strings.Replace(s, "'", "''", -1) + "'" 36 } 37 } 38 return s 39 }
120 func wrapWithDoubleQuotes(val string) string { 121 return fmt.Sprintf(`"%s"`, val) 122 }
139 func htmlGoQuoteString(s string) string { 140 141 var buf bytes.Buffer 142 143 for _, c := range fmt.Sprintf("%q", s) { 144 switch c { 145 case '<', '>', '&': 146 var qc string 147 qc = fmt.Sprintf("\\x%X", uint8(c)) 148 buf.WriteString(qc) 149 default: 150 buf.WriteRune(c) 151 } 152 153 } 154 155 return buf.String() 156 }
63 func standaloneDollarString(varNameTokenStatus varNameTokenStatus, state state) string { 64 switch { 65 case state == readingVarName: 66 return "$" 67 case varNameTokenStatus == incomplete: 68 return "${" 69 } 70 71 return "${}" 72 }
75 func quoteTo(buf *bytes.Buffer, s string) { 76 buf.Grow(2 + len(s)) 77 buf.WriteByte('"') 78 for i, c := range s { 79 switch { 80 case unicode.IsControl(c): 81 if s, ok := ctrlMap[c]; ok { 82 buf.WriteString(s) 83 } else { 84 fmt.Fprintf(buf, "\\u%04x", c) 85 } 86 case c == '"', c == '\\', c == '\'': 87 buf.WriteByte('\\') 88 buf.WriteRune(c) 89 case c <= unicode.MaxASCII: 90 buf.WriteRune(c) 91 case c == unicode.ReplacementChar: 92 // In correctly-encoded UTF-8, we should never see a replacement 93 // char. Some text in the wild has valid Unicode characters that 94 // aren't UTF-8, and this case lets us be more forgiving of those. 95 fmt.Fprintf(buf, "\\u%04x", s[i]) 96 case c <= 0xffff: 97 fmt.Fprintf(buf, "\\u%04x", c) 98 default: 99 fmt.Fprintf(buf, "\\U%08x", c) 100 } 101 } 102 buf.WriteByte('"') 103 }
123 func unescapeCommandProperty(arg string) string { 124 escapeMap := map[string]string{ 125 "%25": "%", 126 "%0D": "\r", 127 "%0A": "\n", 128 "%3A": ":", 129 "%2C": ",", 130 } 131 for k, v := range escapeMap { 132 arg = strings.ReplaceAll(arg, k, v) 133 } 134 return arg 135 }