summaryrefslogtreecommitdiff
path: root/list/list.go
blob: 8099404a7b09aa48245e8f27cd7ed69e17394f7d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
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)
	}
}