libfic: add igncorecase flag to regexp related to ignorecase flag

This commit is contained in:
nemunaire 2019-01-25 07:54:27 +01:00
parent c129b2e477
commit 04b42de061
1 changed files with 6 additions and 3 deletions

View File

@ -73,7 +73,10 @@ func getHashedFlag(raw_value []byte) [blake2b.Size]byte {
return hash
}
func ExecValidatorRegexp(vre string, val []byte) ([]byte, error) {
func ExecValidatorRegexp(vre string, val []byte, ignorecase bool) ([]byte, error) {
if (ignorecase) {
vre = "(?i)" + vre
}
if re, err := regexp.Compile(vre); err != nil {
return val, err
} else if res := re.FindSubmatch(val); res == nil {
@ -92,7 +95,7 @@ func (e Exercice) AddRawFlagKey(name string, help string, ignorecase bool, valid
// Check that raw value passes through the regexp
if validator_regexp != nil {
var err error
if raw_value, err = ExecValidatorRegexp(*validator_regexp, raw_value); err != nil {
if raw_value, err = ExecValidatorRegexp(*validator_regexp, raw_value, ignorecase); err != nil {
return FlagKey{}, err
}
}
@ -127,7 +130,7 @@ func (k FlagKey) ComputeChecksum(val []byte) (cksum []byte, err error) {
// Check that raw value passes through the regexp
if k.ValidatorRegexp != nil {
if val, err = ExecValidatorRegexp(*k.ValidatorRegexp, val); err != nil {
if val, err = ExecValidatorRegexp(*k.ValidatorRegexp, val, k.IgnoreCase); err != nil {
return
}
}