converter

package
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 19, 2024 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Example (Shift_up_code_point)
package main

import (
	"bytes"
	"fmt"
	"strings"

	"github.com/KEINOS/go-joyokanjis/kanjis/converter"
)

func main() {
	tf := converter.New(
		// This function shifts the code point of the input rune by 1
		func(in rune) rune {
			return in + 1 // e.g. 'a' -> 'b'
		},
	)

	// Input reader
	input := "abcdefgァィゥェォ"
	sReader := strings.NewReader(input)

	// Output writer
	var bWriter bytes.Buffer

	// Convert
	tf.Convert(sReader, &bWriter)

	fmt.Println(bWriter.String())
}
Output:

bcdefghアイウエオ
Example (ToUpper)
package main

import (
	"bytes"
	"fmt"
	"strings"
	"unicode"

	"github.com/KEINOS/go-joyokanjis/kanjis/converter"
)

func main() {
	tf := converter.New(
		// This function converts the input rune to upper case
		func(in rune) rune {
			return unicode.ToUpper(in)
		},
	)

	// Input reader
	input := "Hello, World!"
	sReader := strings.NewReader(input)

	// Output writer
	var bWriter bytes.Buffer

	// Convert
	tf.Convert(sReader, &bWriter)

	fmt.Println(bWriter.String())
}
Output:

HELLO, WORLD!

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Converter

type Converter struct {
	// contains filtered or unexported fields
}

Converter is a wrapper of transform.Transformer. It provides an additional method `Convert` to convert the input to the output.

func New

func New(fn func(in rune) rune) Converter

New returns a new Converter object. The given function will be used to convert the characters. Note that if the given function returns -1, the character will be omitted.

func (*Converter) Convert

func (trns *Converter) Convert(input io.Reader, output io.Writer) error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL