MCPcopy Create free account
hub / github.com/EndlessCheng/codeforces-go / parseCodeAndExamples

Function parseCodeAndExamples

copypasta/template/nowcoder/generator.go:92–126  ·  view source on GitHub ↗

examples 为输入输出交替

(session *grequests.Session, problemURL string)

Source from the content-addressed store, hash-verified

90
91// examples 为输入输出交替
92func parseCodeAndExamples(session *grequests.Session, problemURL string) (code string, examples []string, err error) {
93 resp, err := session.Get(problemURL, nil)
94 if err != nil {
95 return
96 }
97 if !resp.Ok {
98 return "", nil, fmt.Errorf("%d", resp.StatusCode)
99 }
100
101 root, err := html.Parse(resp)
102 if err != nil {
103 return
104 }
105
106 var f func(o *html.Node)
107 f = func(o *html.Node) {
108 if o.DataAtom == atom.Textarea {
109 for _, attribute := range o.Attr {
110 if attribute.Val == "input" || attribute.Val == "output" {
111 examples = append(examples, strings.TrimSpace(o.FirstChild.Data))
112 break
113 }
114 if attribute.Val == "goTpl" {
115 code = o.FirstChild.Data
116 break
117 }
118 }
119 }
120 for c := o.FirstChild; c != nil; c = c.NextSibling {
121 f(c)
122 }
123 }
124 f(root)
125 return
126}
127
128func genMainFileContent(code, funcComment string) string {
129 code = strings.TrimSpace(code)

Callers 1

GenNowCoderTemplatesFunction · 0.85

Calls 2

fFunction · 0.50
GetMethod · 0.45

Tested by

no test coverage detected