libfic: Refactor flag label parsing
This commit is contained in:
parent
2b26b2b819
commit
721908ee18
@ -85,6 +85,19 @@ func AnalyzeNumberFlag(t string) (min, max, step *float64, err error) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (k *FlagKey) AnalyzeFlagLabel() (label, separator string, ignoreorder bool, nblines uint64) {
|
||||||
|
if k.Label[0] == '`' && len(k.Label) > 4 {
|
||||||
|
label = k.Label[4:]
|
||||||
|
separator = string(k.Label[1])
|
||||||
|
ignoreorder = k.Label[2] == 't'
|
||||||
|
nblines, _ = strconv.ParseUint(string(k.Label[3]), 10, 8)
|
||||||
|
} else {
|
||||||
|
label = k.Label
|
||||||
|
}
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
// GetFlagKeys returns a list of key's flags comming with the challenge.
|
// GetFlagKeys returns a list of key's flags comming with the challenge.
|
||||||
func (e *Exercice) GetFlagKeys() ([]*FlagKey, error) {
|
func (e *Exercice) GetFlagKeys() ([]*FlagKey, error) {
|
||||||
if rows, err := DBQuery("SELECT id_flag, id_exercice, ordre, label, type, placeholder, help, unit, ignorecase, notrim, multiline, validator_regexp, sort_re_grps, cksum, choices_cost, bonus_gain FROM exercice_flags WHERE id_exercice = ?", e.Id); err != nil {
|
if rows, err := DBQuery("SELECT id_flag, id_exercice, ordre, label, type, placeholder, help, unit, ignorecase, notrim, multiline, validator_regexp, sort_re_grps, cksum, choices_cost, bonus_gain FROM exercice_flags WHERE id_exercice = ?", e.Id); err != nil {
|
||||||
|
@ -261,14 +261,7 @@ func MyJSONTeam(t *Team, started bool) (interface{}, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Treat array flags
|
// Treat array flags
|
||||||
if k.Label[0] == '`' && len(k.Label) > 4 {
|
flag.Label, flag.Separator, flag.IgnoreOrder, flag.NbLines = k.AnalyzeFlagLabel()
|
||||||
flag.Label = k.Label[4:]
|
|
||||||
flag.Separator = string(k.Label[1])
|
|
||||||
flag.IgnoreOrder = k.Label[2] == 't'
|
|
||||||
flag.NbLines, _ = strconv.ParseUint(string(k.Label[3]), 10, 8)
|
|
||||||
} else {
|
|
||||||
flag.Label = k.Label
|
|
||||||
}
|
|
||||||
|
|
||||||
// Fill more information if the flag is displaied
|
// Fill more information if the flag is displaied
|
||||||
if flag.Solved == nil {
|
if flag.Solved == nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user