github.com/phpdave11/gofpdf@v1.4.2/list/list.go (about) 1 package main 2 3 import ( 4 "fmt" 5 "os" 6 "path/filepath" 7 "strings" 8 ) 9 10 func matchTail(str, tailStr string) (match bool, headStr string) { 11 sln := len(str) 12 ln := len(tailStr) 13 if sln > ln { 14 match = str[sln-ln:] == tailStr 15 if match { 16 headStr = str[:sln-ln] 17 } 18 } 19 return 20 } 21 22 func matchHead(str, headStr string) (match bool, tailStr string) { 23 ln := len(headStr) 24 if len(str) > ln { 25 match = str[:ln] == headStr 26 if match { 27 tailStr = str[ln:] 28 } 29 } 30 return 31 } 32 33 func main() { 34 var err error 35 var ok bool 36 var showStr, name string 37 err = filepath.Walk("pdf/reference", func(path string, info os.FileInfo, err error) error { 38 if info.Mode().IsRegular() { 39 name = filepath.Base(path) 40 ok, name = matchTail(name, ".pdf") 41 if ok { 42 name = strings.Replace(name, "_", " ", -1) 43 ok, showStr = matchHead(name, "Fpdf ") 44 if ok { 45 fmt.Printf("[%s](%s)\n", showStr, path) 46 } else { 47 ok, showStr = matchHead(name, "contrib ") 48 if ok { 49 fmt.Printf("[%s](%s)\n", showStr, path) 50 } 51 } 52 } 53 } 54 return nil 55 }) 56 if err != nil { 57 fmt.Println(err) 58 } 59 }