mapa znaków działa w tym programie jak 1:1 czyli każdemu znakowi diakrytycznemu,…
- User
mapa znaków działa w tym programie jak 1:1 czyli każdemu znakowi diakrytycznemu, przypisany jest znak nie diakrytyczny, chciałbym , abyś zmodyfikował ten kod, aby przypisać kilka znaków diakrytycznych w jeden znak nie diakrytycznych np:ą,á":"a", "ć,č":"c", "ę,é,ě":"e", "ś,š":"s", "Á,Ą":"A", "ž,ż,ź":"z",
package main
import ( "flag" "fmt" "io/ioutil" "strings" "path/filepath" )
var ogonki = map[string]string{ "pl":"ąćęłńóśźżĄĆĘŁŃÓŚŹŻ", "cz":"áčďéěíňóřšťúůýžÁČĎÉĚÍŇÓŘŠŤÚŮÝŽ", }
func main() { flagHelp := flag.Bool("help", false, "View Help") flagLang := flag.String("lang", "pl", "The language of diacritic marks: \n (pl, de, fr, es, it, cz, hu, dk, no, fi, el, ro, et, lt, lv, sk, vi, sl, hr, ro, is, mt, sr, nl, al, ba, pt, tr, la, cy, gl, ku, br, fo, fy, gd, gl, hsb, ga, csb, ca, kw, crh, lb, ro, rom, it, gd, )")
codeflag.Parse() if *flagHelp { printHelp() return } inputFiles := flag.Args() if len(inputFiles) == 0 { fmt.Println("OGONKI => Error: No file path specified. \nDisplaying help: OGONKI -help") return } for _, inputFile := range inputFiles { fileExt := strings.ToLower(filepath.Ext(inputFile)) switch fileExt { case ".txt", ".srt", ".yml": content, err := ioutil.ReadFile(inputFile) if err != nil { fmt.Printf("Error loading file %s: %s\n", inputFile, err) continue } newContent := replaceOgonki(string(content), *flagLang) outputFile := strings.TrimSuffix(inputFile, fileExt) + "_modified" + fileExt err = ioutil.WriteFile(outputFile, []byte(newContent), 0644) if err != nil { fmt.Printf("Error for adding support access paths %s: %s\n", outputFile, err) continue } fmt.Printf("Diacritics swap completed successfully. \nNew file saved as %s.\n", outputFile) default: fmt.Printf("Unsupported file format: %s\n", fileExt) }} }
func replaceOgonki(text string, lang string) string { ogonkiLetters, ok := ogonki[lang] if !ok { fmt.Printf("Error: Unknown diacritics language %s.\n", lang) return text }
code - Assistant