You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

40 lines
702 B

10 years ago
10 years ago
10 years ago
  1. package main
  2. import (
  3. "flag"
  4. "io"
  5. "log"
  6. "os"
  7. "github.com/gogits/gogs/modules/mahonia"
  8. )
  9. // An iconv workalike using mahonia.
  10. var from = flag.String("f", "utf-8", "source character set")
  11. var to = flag.String("t", "utf-8", "destination character set")
  12. func main() {
  13. flag.Parse()
  14. var r io.Reader = os.Stdin
  15. var w io.Writer = os.Stdout
  16. if *from != "utf-8" {
  17. decode := mahonia.NewDecoder(*from)
  18. if decode == nil {
  19. log.Fatalf("Could not create decoder for %s", *from)
  20. }
  21. r = decode.NewReader(r)
  22. }
  23. if *to != "utf-8" {
  24. encode := mahonia.NewEncoder(*to)
  25. if encode == nil {
  26. log.Fatalf("Could not create decoder for %s", *to)
  27. }
  28. w = encode.NewWriter(w)
  29. }
  30. io.Copy(w, r)
  31. }