Created
June 30, 2020 20:19
-
-
Save buzztaiki/45241435e9f1439afac50d7e5cda41d9 to your computer and use it in GitHub Desktop.
NFDをNFCにする
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"flag" | |
"io" | |
"log" | |
"os" | |
"golang.org/x/text/transform" | |
"golang.org/x/text/unicode/norm" | |
) | |
func trans(w io.Writer, r io.Reader) error { | |
tr := transform.NewReader(r, norm.NFC) | |
if _, err := io.Copy(w, tr); err != nil { | |
return err | |
} | |
return nil | |
} | |
func run(args []string) error { | |
if len(args) == 0 { | |
return trans(os.Stdout, os.Stdin) | |
} | |
for _, fname := range flag.Args() { | |
f, err := os.Open(fname) | |
if err != nil { | |
return err | |
} | |
defer f.Close() | |
return trans(os.Stdout, f) | |
} | |
return nil | |
} | |
func main() { | |
flag.Parse() | |
if err := run(flag.Args()); err != nil { | |
log.Fatal(err) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment