diff options
author | Kurt Jung <kurt.w.jung@gmail.com> | 2015-10-20 12:26:10 -0400 |
---|---|---|
committer | Kurt Jung <kurt.w.jung@gmail.com> | 2015-10-20 12:26:10 -0400 |
commit | e2d935b7215daa9476f1ca385a15227f5f5a7011 (patch) | |
tree | 56b837702a1d3b036e081506513d79913389875f /list | |
parent | 26baf7d305543d6afe39d38f0b2c30054c9fa4e3 (diff) | |
parent | f45e5e9196bb313883f36e0ccc72f052f46aa37e (diff) |
Merge pull request #49 from jung-kurt/compare-reference-pdf
Compare example PDFs with reference copies
Diffstat (limited to 'list')
-rw-r--r-- | list/list.go | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/list/list.go b/list/list.go new file mode 100644 index 0000000..8099404 --- /dev/null +++ b/list/list.go @@ -0,0 +1,59 @@ +package main + +import ( + "fmt" + "os" + "path/filepath" + "strings" +) + +func matchTail(str, tailStr string) (match bool, headStr string) { + sln := len(str) + ln := len(tailStr) + if sln > ln { + match = str[sln-ln:] == tailStr + if match { + headStr = str[:sln-ln] + } + } + return +} + +func matchHead(str, headStr string) (match bool, tailStr string) { + ln := len(headStr) + if len(str) > ln { + match = str[:ln] == headStr + if match { + tailStr = str[ln:] + } + } + return +} + +func main() { + var err error + var ok bool + var showStr, name string + err = filepath.Walk("pdf/reference", func(path string, info os.FileInfo, err error) error { + if info.Mode().IsRegular() { + name = filepath.Base(path) + ok, name = matchTail(name, ".pdf") + if ok { + name = strings.Replace(name, "_", " ", -1) + ok, showStr = matchHead(name, "Fpdf ") + if ok { + fmt.Printf("[%s](%s)\n", showStr, path) + } else { + ok, showStr = matchHead(name, "contrib ") + if ok { + fmt.Printf("[%s](%s)\n", showStr, path) + } + } + } + } + return nil + }) + if err != nil { + fmt.Println(err) + } +} |