diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..1a7f706 --- /dev/null +++ b/go.mod @@ -0,0 +1,3 @@ +module morozovad.ddns.net/lnd212/go-xdfx2csv + +go 1.15 diff --git a/main.go b/main.go new file mode 100644 index 0000000..608b3c3 --- /dev/null +++ b/main.go @@ -0,0 +1,97 @@ +package main + +import ( + "bufio" + "fmt" + "log" + "os" + "strings" + "sync" + "time" +) + +var ( + full_name string + lang_from string + lang_to string +) + +const ( + FIRST_LINES = 5 +) + +func main() { + f, err := os.OpenFile("dict.xdxf", os.O_RDONLY, os.ModePerm) + if err != nil { + log.Fatalf("open file error: %v", err) + return + } + defer f.Close() + + fullFile(f) +} + +func fullFile(file *os.File) { + sc := bufio.NewScanner(file) + /*for sc.Scan() { + fmt.Println(sc.Text()) + }*/ + if err := sc.Err(); err != nil { + log.Fatalf("scan file error: %v", err) + return + } + + //skip first lines with some unnessesary data and save full name + first:="" + for sc.Scan() { + line := sc.Text() + if strings.Contains(line, "") { + line = strings.ReplaceAll(line, "full_name>", "") + line = strings.ReplaceAll(line, "") { + first= line + break + } + } + + fmt.Printf("Dict name: %s.\n", full_name) + fmt.Printf("From %s to %s. \n", lang_from, lang_to) + fmt.Println(first) + // read file line by line + var ( + word string + translation string + transcription string + ) + + for sc.Scan() { + line := sc.Text() + if strings.Contains(line, "") { + word = "" + translation = "" + transcription = "" + fmt.Println(word, translation, transcription) + } + if strings.Contains(line, "") { + _, word, _ = strings.Cut(line, "") + } + fmt.Println(sc.Text()) + } +} + +func processChunk(chunk []byte, linesPool *sync.Pool, stringPool *sync.Pool, start time.Time, end time.Time) { + +} + +//readFile opens file in chunks and process to other func. https://medium.com/swlh/processing-16gb-file-in-seconds-go-lang-3982c235dfa2 +func readFile() { + +}