trimCurlyBrackets is the faster equivalent of bytes.TrimRight(bytes.TrimLeft(s, "{"), "}"). The function also returns the number of curly brackets trimmed from the left and the right.
(s []byte)
| 1188 | // also returns the number of curly brackets trimmed from the |
| 1189 | // left and the right. |
| 1190 | func trimCurlyBrackets(s []byte) (int, []byte, int) { |
| 1191 | i, j := 0, len(s) |
| 1192 | for ; i < j; i++ { |
| 1193 | if s[i] != '{' { |
| 1194 | break |
| 1195 | } |
| 1196 | } |
| 1197 | for ; i < j; j-- { |
| 1198 | if s[j-1] != '}' { |
| 1199 | break |
| 1200 | } |
| 1201 | } |
| 1202 | return i, s[i:j], len(s) - j |
| 1203 | } |
| 1204 | |
| 1205 | // unsafeString performs an unsafe conversion from a []byte to a string. The |
| 1206 | // returned string will share the underlying memory with the []byte which thus |
no outgoing calls
searching dependent graphs…