https://github.com/ktnyt/go-moji
A Go library for Zenkaku/Hankaku conversion
https://github.com/ktnyt/go-moji
conversion go japanese
Last synced: 5 months ago
JSON representation
A Go library for Zenkaku/Hankaku conversion
- Host: GitHub
- URL: https://github.com/ktnyt/go-moji
- Owner: ktnyt
- License: mit
- Created: 2018-01-15T14:30:36.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2019-04-17T01:29:45.000Z (about 7 years ago)
- Last Synced: 2024-06-18T23:15:20.055Z (about 2 years ago)
- Topics: conversion, go, japanese
- Language: Go
- Size: 8.79 KB
- Stars: 19
- Watchers: 3
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# go-moji
[](https://circleci.com/gh/ktnyt/go-moji)
[](https://goreportcard.com/report/github.com/ktnyt/go-moji)
[](http://godoc.org/github.com/ktnyt/go-moji)
This package provides a Go interface for converting between Zenkaku (全角 i.e. full-width) and Hankaku (半角 i.e. half-width) characters (mostly for Japanese). The library has been largely influenced by [niwaringo/moji](https://github.com/niwaringo/moji) the JavaScript implementation.
For detailed information of the API, see the [documents](https://godoc.org/github.com/ktnyt/go-moji).
## Installation
Use `go get`:
```sh
$ go get github.com/ktnyt/go-moji
```
## Requirements
This package has only been tested on Go >= 1.8. Beware when using lower versions.
## Example
```go
package main
import (
"fmt"
"github.com/ktnyt/go-moji"
)
func main() {
s := "ABC ABC あがぱ アガパ アガパ"
// Convert Zenkaku Eisuu to Hankaku Eisuu
fmt.Println(moji.Convert(s, moji.ZE, moji.HE))
// Convert Hankaku Eisuu to Zenkaku Eisuu
fmt.Println(moji.Convert(s, moji.HE, moji.ZE))
// Convert HiraGana to KataKana
fmt.Println(moji.Convert(s, moji.HG, moji.KK))
// Convert KataKana to HiraGana
fmt.Println(moji.Convert(s, moji.KK, moji.HG))
// Convert Zenkaku Katakana to Hankaku Katakana
fmt.Println(moji.Convert(s, moji.ZK, moji.HK))
// Convert Hankaku Katakana to Zenkaku Katakana
fmt.Println(moji.Convert(s, moji.HK, moji.ZK))
// Convert Zenkaku Space to Hankaku Space
fmt.Println(moji.Convert(s, moji.ZS, moji.HS))
// Convert Hankaku Space to Zenkaku Space
fmt.Println(moji.Convert(s, moji.HS, moji.ZS))
}
```
## Copyright
Copyright (C) 2018 by Kotone Itaya
go-moji is released under the terms of the MIT License.
See [LICENSE](https://github.com/ktnyt/go-moji/blob/master/LICENSE) for details.