[Golang] Find Pāli Word in Velthuis Scheme


Find Pāli word in Velthuis scheme via Golang.

find.go | repository | view raw
 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
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
	})
}
find_test.go | repository | view raw
1
2
3
4
5
6
7
package velthuis

import "testing"

func TestFindPaliWordsInVelthuisScheme(t *testing.T) {
	FindPaliWordsInVelthuisScheme("/home/foo/articles/anya/visuddhimagga/")
}

Tested on: Ubuntu Linux 15.10, Go 1.6.


References:

[1]Coping with Diacritics
[2]Representing Pali diacritics using the Velthuis method
[3]Key Mapping of Pali fonts from Foreign 1 fonts
[4]Learning Pali
[5]Pali
[6][Golang] Walk All Files in Directory
[7]