MCPcopy
hub / github.com/rclone/rclone / parse

Function parse

backend/http/http.go:447–477  ·  view source on GitHub ↗

Parse turns HTML for a directory into names base should be the base URL to resolve any relative names from

(base *url.URL, in io.Reader)

Source from the content-addressed store, hash-verified

445// Parse turns HTML for a directory into names
446// base should be the base URL to resolve any relative names from
447func parse(base *url.URL, in io.Reader) (names []string, err error) {
448 doc, err := html.Parse(in)
449 if err != nil {
450 return nil, err
451 }
452 var (
453 walk func(*html.Node)
454 seen = make(map[string]struct{})
455 )
456 walk = func(n *html.Node) {
457 if n.Type == html.ElementNode && n.Data == "a" {
458 for _, a := range n.Attr {
459 if a.Key == "href" {
460 name, err := parseName(base, a.Val)
461 if err == nil {
462 if _, found := seen[name]; !found {
463 names = append(names, name)
464 seen[name] = struct{}{}
465 }
466 }
467 break
468 }
469 }
470 }
471 for c := n.FirstChild; c != nil; c = c.NextSibling {
472 walk(c)
473 }
474 }
475 walk(doc)
476 return names, nil
477}
478
479// parseFilename extracts the filename from a Content-Disposition header
480func parseFilename(contentDisposition string) (string, error) {

Callers 2

readDirMethod · 0.70
parseHTMLFunction · 0.70

Calls 2

parseNameFunction · 0.85
walkFunction · 0.85

Tested by 1

parseHTMLFunction · 0.56

Used in the wild real call sites across dependent graphs

searching dependent graphs…