1
1
mirror of https://github.com/go-gitea/gitea synced 2024-12-25 18:14:28 +00:00
gitea/modules/mahonia/mahoniconv/mahoniconv.go

41 lines
702 B
Go
Raw Normal View History

2014-09-07 23:58:01 +00:00
package main
import (
"flag"
"io"
"log"
"os"
2014-09-08 00:11:13 +00:00
"github.com/gogits/gogs/modules/mahonia"
2014-09-07 23:58:01 +00:00
)
// An iconv workalike using mahonia.
var from = flag.String("f", "utf-8", "source character set")
var to = flag.String("t", "utf-8", "destination character set")
func main() {
flag.Parse()
var r io.Reader = os.Stdin
var w io.Writer = os.Stdout
if *from != "utf-8" {
decode := mahonia.NewDecoder(*from)
if decode == nil {
log.Fatalf("Could not create decoder for %s", *from)
}
r = decode.NewReader(r)
}
if *to != "utf-8" {
encode := mahonia.NewEncoder(*to)
if encode == nil {
log.Fatalf("Could not create decoder for %s", *to)
}
w = encode.NewWriter(w)
}
io.Copy(w, r)
}