mirror of
https://github.com/fluencelabs/tendermint
synced 2025-06-24 18:21:38 +00:00
IsHex and StripHex
This commit is contained in:
@ -1,6 +1,7 @@
|
|||||||
package common
|
package common
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/hex"
|
||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
@ -22,3 +23,22 @@ func LeftPadString(s string, totalLength int) string {
|
|||||||
}
|
}
|
||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Returns true for non-empty hex-string prefixed with "0x"
|
||||||
|
func IsHex(s string) bool {
|
||||||
|
if len(s) > 2 && s[:2] == "0x" {
|
||||||
|
_, err := hex.DecodeString(s[2:])
|
||||||
|
if err != nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
func StripHex(s string) string {
|
||||||
|
if IsHex(s) {
|
||||||
|
return s[2:]
|
||||||
|
}
|
||||||
|
return s
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user