libfic: add igncorecase flag to regexp related to ignorecase flag
This commit is contained in:
parent
db22c4af1b
commit
e97cf884ce
@ -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
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user