text_generator

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Aug 26, 2016 License: MIT Imports: 2 Imported by: 0

README

text-generator

Fast text generator on a mask.

Written in Golang. I do not use regular expressions and the fastest. I covered tests and simple! Supporting recursive text generation rules.

Build Status GoDoc

Installation

go get github.com/liderman/text-generator

Usage

An example of a simple template text generation:

tg := text_generator.New()
template := "Good {morning|day}!"

fmt.Print(tg.Generate(template))
// Displays: Good morning!

fmt.Print(tg.Generate(template))
// Displays: Good day!

An example of a complex generation template text:

tg := text_generator.New()
template := "{Good {morning|evening|day}|Goodnight|Hello}, {friend|brother}! {How are you|What's new with you}?"

fmt.Print(tg.Generate(template))
// Displays: Good morning, friend! How are you?

fmt.Print(tg.Generate(template))
// Displays: Good day, brother! What's new with you?

fmt.Print(tg.Generate(template))
// Displays: Hello, friend! How are you?
...

Requirements

  • Need at least go1.2 or newer.

Documentation

You can read package documentation here.

Testing

Unit-tests:

go test -v

Benchmarks:

go test -test.bench .

The test result on computer mac-mini 2012 (Intel Core i5):

PASS
BenchmarkGenerateEasyText-4      1000000              1699 ns/op
BenchmarkGenerateComplexText-4    200000              7430 ns/op
ok      github.com/liderman/text-generator            3.391s

Documentation

Overview

Package text_generator Fast text generator on a mask.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type TextGenerator

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

func New

func New() *TextGenerator

New returns a new instance a text generator.

func (*TextGenerator) Generate

func (t *TextGenerator) Generate(text string) string

Generate generates and returns a new text. Use the rules for generating a plurality of texts. Example mask: `Good {morning|day}!`

Jump to

Keyboard shortcuts

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