package util

import (
	"unicode"
)

func IsHexString(s string, upper bool) bool {
	exclude := unicode.IsUpper
	if upper {
		exclude = unicode.IsLower
	}
	for _, r := range s {
		if !unicode.In(r, unicode.ASCII_Hex_Digit) || exclude(r) {
			return false
		}
	}
	return true
}

func MatchCommitHash(s string) bool {
	return len(s) == 40 && IsHexString(s, false)
}
