/
custom_hex_prefix.go
65 lines (59 loc) · 1.57 KB
/
custom_hex_prefix.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
// Copyright 2018 The gttc Authors
// This file is part of the gttc library.
//
// The gttc library is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// The gttc library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with the gttc library. If not, see <http://www.gnu.org/licenses/>.
// PM want to change the prefix of hex from 0x to anything they want, @#$%@#$%@#%^ ;-)
// Just set the CustomHashPrefix to "0x" , everything will back to normal.
package hexutil
const CustomHexPrefix = "t0"
var PossibleCustomHexPrefixMap = map[string]bool{
"0x": true,
"0X": true,
"t0": true,
"t1": true,
"t2": true,
"t3": true,
"t4": true,
"t5": true,
"t6": true,
"t7": true,
"t8": true,
"t9": true,
"T0": true,
"T1": true,
"T2": true,
"T3": true,
"T4": true,
"T5": true,
"T6": true,
"T7": true,
"T8": true,
"T9": true,
}
func CPToHex(s string) string {
if len(s) > len(CustomHexPrefix) {
if _, ok := PossibleCustomHexPrefixMap[s[:2]]; ok {
return "0x" + s[2:]
}
}
return s
}
func HexToCP(s string) string {
if len(s) > 2 {
if s[:2] == "0x" || s[:2] == "0X" {
return CustomHexPrefix + s[2:]
}
}
return s
}