Categorygithub.com/ktnyt/go-moji
modulepackage
1.0.0
Repository: https://github.com/ktnyt/go-moji.git
Documentation: pkg.go.dev

# README

go-moji

Build Status Go Report Card GoDoc

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 the JavaScript implementation.

For detailed information of the API, see the documents.

Installation

Use go get:

$ go get github.com/ktnyt/go-moji

Requirements

This package has only been tested on Go >= 1.8. Beware when using lower versions.

Example

package main

import (
	"fmt"

	"github.com/ktnyt/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 [email protected]

go-moji is released under the terms of the MIT License. See LICENSE for details.

# Functions

Convert a string between two Dictionaries.
NewDictionary creates a dictionary from the given string slice.
NewRangeDictionary creates a dictionary from the given range.

# Variables

HE defines the Hankaku Eisuu (i.e.
HG defines the HiraGana Dictionary.
HK defines the Hankaku Katakana (i.e.
HS defines the Hankaku Space (i.e.
KK defines the KataKana Dictionary.
ZE defines the Zenkaku Eisuu (i.e.
ZK defines the Zenkaku Katakana (i.e.
ZS defines the Zenkaku Space (i.e.

# Structs

MaybeIndex may be an index or a rune.

# Interfaces

Dictionary defines an interface for mapping between a string and index.