
4

[Golang] Find Pāli Word in Velthuis Scheme
source link: http://siongui.github.io/2016/03/17/go-find-pali-word-in-velthuis-scheme/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

[Golang] Find Pāli Word in Velthuis Scheme
Find Pāli word in Velthuis scheme via Golang.
find.go | repository | view raw
package velthuis import ( "fmt" "io/ioutil" "os" "path/filepath" "regexp" "strings" ) var paliWordsInVelthuisScheme = regexp.MustCompile(`[abcdeghijklmnoprstuvyABCDEGHIJKLMNOPRSTUVY"~.]+`) func replacePaliWordsInVelthuisScheme(b []byte) []byte { if len(b) == 1 { return b } if string(b) == ".." { return b } fmt.Println(string(b)) return b } func processRst(path string) { fmt.Println("processing " + path + " ...") b, err := ioutil.ReadFile(path) if err != nil { panic(err) } paliWordsInVelthuisScheme.ReplaceAllFunc(b, replacePaliWordsInVelthuisScheme) } func FindPaliWordsInVelthuisScheme(dirname string) { // walk all files in directory filepath.Walk(dirname, func(path string, info os.FileInfo, err error) error { if !info.IsDir() && strings.HasSuffix(info.Name(), ".rst") { processRst(path) } return nil }) }
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK