Skip to content
This repository has been archived by the owner on Oct 15, 2022. It is now read-only.

Combine duplicates in file extensions plugin #12

Merged
merged 1 commit into from Apr 15, 2012
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
21 changes: 20 additions & 1 deletion file_formats/parse.go
Expand Up @@ -23,10 +23,12 @@ func main() {
flag.Parse()
lines := make(chan string)
formats := make(chan fileFormat)
uniqFormats := make(chan fileFormat)

go readData(lines)
go parse(lines, formats)
output(formats)
go uniq(formats, uniqFormats)
output(uniqFormats)
}

type fileFormat struct {
Expand Down Expand Up @@ -78,6 +80,23 @@ func abstract(uses []string) string {
return "A file with this extension may be " + a + strings.Join(uses, ", ") + "."
}

func uniq(formats chan fileFormat, uniqFormats chan fileFormat) {
uniq := make(map[string]fileFormat)
for f := range formats {
if existing, ok := uniq[f.ext]; ok {
existing.use = append(existing.use, f.use...)
uniq[f.ext] = existing
} else {
uniq[f.ext] = f
}
}

for _, f := range uniq {
uniqFormats <- f
}
close(uniqFormats)
}

func cleanWikiHTML(s string) string {
return strings.TrimSpace(html.UnescapeString(wikilink(s)))
}
Expand Down