()
| 34 | ) |
| 35 | |
| 36 | func init() { |
| 37 | encodeRef := map[byte]byte{ |
| 38 | '\b': 'b', |
| 39 | '\f': 'f', |
| 40 | '\n': 'n', |
| 41 | '\r': 'r', |
| 42 | '\t': 't', |
| 43 | '\\': '\\', |
| 44 | } |
| 45 | |
| 46 | for i := range EncodeMap { |
| 47 | EncodeMap[i] = DontEscape |
| 48 | } |
| 49 | for i := range EncodeMap { |
| 50 | if to, ok := encodeRef[byte(i)]; ok { |
| 51 | EncodeMap[byte(i)] = to |
| 52 | } |
| 53 | } |
| 54 | |
| 55 | // underlyingHexMap contains the string "\x00\x01\x02..." which HexMap and |
| 56 | // RawHexMap then index into. |
| 57 | var underlyingHexMap bytes.Buffer |
| 58 | underlyingHexMap.Grow(1024) |
| 59 | |
| 60 | for i := 0; i < 256; i++ { |
| 61 | underlyingHexMap.WriteString("\\x") |
| 62 | writeHexDigit(&underlyingHexMap, i/16) |
| 63 | writeHexDigit(&underlyingHexMap, i%16) |
| 64 | } |
| 65 | |
| 66 | underlyingHexBytes := underlyingHexMap.Bytes() |
| 67 | |
| 68 | for i := 0; i < 256; i++ { |
| 69 | HexMap[i] = underlyingHexBytes[i*4 : i*4+4] |
| 70 | RawHexMap[i] = underlyingHexBytes[i*4+2 : i*4+4] |
| 71 | } |
| 72 | } |
| 73 | |
| 74 | // EncodeEscapedChar is used internally to write out a character from a larger |
| 75 | // string that needs to be escaped to a buffer. |
nothing calls this directly
no test coverage detected
searching dependent graphs…