func importStatement(archive *formats.ProblemArchiveReader, problem *model.Problem, statement *Statement) { data, err := archive.ReadFile(statement.Path) PanicIf(err, "Cannot read statement %s: %s", statement.Path, err) getTeX := func(src []byte) model.FormattedText { return model.RawText(src) } if match := statementRe.FindSubmatch(data); match != nil { problem.Statement = getTeX(match[1]) problem.InputFormat = getTeX(match[2]) problem.OutputFormat = getTeX(match[3]) } matches := exampleRe.FindAllSubmatch(data, -1) problem.Samples = make([]model.Sample, len(matches)) for i, match := range matches { problem.Samples[i].Input = string(match[1]) problem.Samples[i].Output = string(match[2]) } }
func (self *ProblemArchiveReader) LoadTests(problem *model.Problem, inPattern, outPattern string) error { inRe, err := regexp.Compile(inPattern) if err != nil { return err } outRe, err := regexp.Compile(outPattern) if err != nil { return err } tests := make(map[string]int) getData := func(name, file string) (id int, data []byte, err error) { id, ok := tests[name] if !ok { problem.Tests = append(problem.Tests, model.Test{}) id = len(problem.Tests) - 1 tests[name] = id } data, err = self.ReadFile(file) return } for _, file := range self.FileList() { in := inRe.FindStringSubmatch(file) if in != nil { id, data, err := getData(in[1], file) if err != nil { return err } problem.Tests[id].Input = model.ConstTestData(data) } out := outRe.FindStringSubmatch(file) if out != nil { id, data, err := getData(out[1], file) if err != nil { return err } problem.Tests[id].Output = model.ConstSolutionData(data) } } return nil }