Skip to content

Commit

Permalink
README.md: wrote commandlines to do examples
Browse files Browse the repository at this point in the history
  • Loading branch information
hymkor committed Feb 17, 2023
1 parent 0e675ff commit eb4a485
Showing 1 changed file with 65 additions and 2 deletions.
67 changes: 65 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,24 @@ func main() {
}
```

`mbcs.ACP` is the current codepage.

#### On Windows

```
$ chcp 932
$ go run examples\AnsiToUtf8.go < testdata\jugemu-cp932.txt | nkf32 --guess
UTF-8 (LF)
```

#### On Linux

```
$ env LC_ALL=ja_JP.Shift_JIS go run examples/AnsiToUtf8.go < testdata/jugemu-cp932.txt | nkf --guess
UTF-8 (LF)
```

When OS is not Windows, the current encoding is judged with $LC_ALL and $LANG.

Convert from UTF8-strings to ANSI-bytes
---------------------------------------
Expand Down Expand Up @@ -69,6 +87,21 @@ func main() {
}
```

#### On Windows

```
$ chcp 932
$ go run examples\Utf8ToAnsi.go < testdata\jugemu-utf8.txt | nkf32 --guess
Shift_JIS (LF)
```

#### On Linux

```
$ env LC_ALL=ja_JP.Shift_JIS go run examples/Utf8ToAnsi.go < testdata/jugemu-utf8.txt | nkf --guess
Shift_JIS (LF)
```

Use golang.org/x/text/transform
-------------------------------

Expand All @@ -88,7 +121,7 @@ import (
)

func main() {
sc := bufio.NewScanner(transform.NewReader(os.Stdin, mbcs.Decoder{CP: mbcs.ACP}))
sc := bufio.NewScanner(transform.NewReader(os.Stdin, mbcs.NewDecoder(mbcs.ACP)))
for sc.Scan() {
fmt.Println(sc.Text())
}
Expand All @@ -99,6 +132,21 @@ func main() {
}
```

#### On Windows

```
$ chcp 932
$ go run examples\NewDecoder.go < testdata\jugemu-cp932.txt | nkf32 --guess
UTF-8 (LF)
```

#### On Linux

```
$ env LC_ALL=ja_JP.Shift_JIS go run examples/NewDecoder.go < testdata/jugemu-cp932.txt | nkf --guess
UTF-8 (LF)
```

### Convert from UTF8-reader to ANSI-reader

```go
Expand All @@ -115,7 +163,7 @@ import (
)

func main() {
sc := bufio.NewScanner(transform.NewReader(os.Stdin, mbcs.Encoder{CP: mbcs.ACP}))
sc := bufio.NewScanner(transform.NewReader(os.Stdin, mbcs.NewEncoder(mbcs.ACP)))
for sc.Scan() {
os.Stdout.Write(sc.Bytes())
os.Stdout.Write([]byte{'\n'})
Expand All @@ -126,3 +174,18 @@ func main() {
}
}
```

#### On Windows

```
$ chcp 932
$ go run examples\NewEncoder.go < testdata/jugemu-utf8.txt | nkf32 --guess
Shift_JIS (LF)
```

#### On Linux

```
$ env LC_ALL=ja_JP.Shift_JIS go run examples/NewEncoder.go < testdata/jugemu-utf8.txt | nkf --guess
Shift_JIS (LF)
```

0 comments on commit eb4a485

Please sign in to comment.