beta

package module
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: May 29, 2020 License: ISC Imports: 6 Imported by: 0

README

Beta - Betacode converter

Version 0.3: Might change, but is usable just fine

Beta is a library for converting TypeGreek-flavoured Betacode to polytonic Greek. It can generate UTF-8 text with precomposed characters (NFC) or combining diacritics (NFD). Read this Go blog entry for more information about text normalisation.

This implementation is independent of TypeGreek, but implements the same rules: diacritics can appear in any order after the base character, capital Betacode letters form capital Greek letters (no asterisk), and a sigma followed by whitespace or punctuation becomes a terminal sigma automatically.

Sort-of parsing the Greek subset of Standard Betacode is now implemented. This means interpreting asterisks and putting up with diacritics after the asterisk and before the base character, but unlike Standard Betacode, this implementation is never case-insensitive.

The directory beta contains a minimal example program that uses beta.Writer.

Documentation

Overview

Package beta implements TypeGreek-flavoured and Standard Betacode parsing.

TypeGreek (www.typegreek.com) is a JavaScript implementation of Betacode that relaxes some rules to ease text entry (and implementation). This implementation is independent, but allows the same:

  • Uppercase Betacode characters form uppercase Greek characters.

  • The order of diacritics is unimportant.

  • The diacritics follow the base character.

  • Whether a sigma is final or not depends on the next character in streaming mode (beta.Writer). When using beta.Sym, we can't know the next character, so this is moot.

When an asterisk is encountered, the symbol is coerced to uppercase and breathing and accent may appear before the base character, emulating Standard Betacode as used by the Perseus Project.

Index

Constants

View Source
const (
	// Vowels in Betacode. Most diacritics apply to vowels only.
	Vowels = "aehowiu"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Sym

type Sym struct {
	Base     rune // Betacode character (A-Z, a-z)
	Accent   rune // none, /, \, =
	Spiritus rune // Breathing: none, ), (
	Iota     bool // Iota subscriptum/adscriptum
	Trema    bool // Diaeresis
	// contains filtered or unexported fields
}

A Sym is a parsed Betacode character.

func (*Sym) Add

func (sym *Sym) Add(r rune) bool

Add adds r to the symbol if it is a valid Betacode/TypeGreek base character or modifier. It returns true if the character has been added. If it returns false and if sym.Err() is nil, the start of a new symbol was detected. If sym.Err() is not nil, a true error occurred.

func (Sym) Combining

func (sym Sym) Combining() []byte

Combining returns the combining diacritics Unicode form as a UTF-8 byte slice.

func (Sym) CombiningString

func (sym Sym) CombiningString() string

CombiningString returns the combining diacritics Unicode form as a UTF-8 string.

func (Sym) Empty

func (sym Sym) Empty() bool

Empty returns true if the symbol is empty, i.e. diacritics can't be applied.

func (Sym) Err

func (sym Sym) Err() error

Err returns the error that caused Add to return false. If !sym.Empty() and sym.Err() == nil, this means the Sym is complete and the start of the next symbol was encountered.

func (Sym) Precombined

func (sym Sym) Precombined() []byte

Precombined returns the NFC normalised Unicode form (precombined code point) as a UTF-8 byte slice. This is the usual form.

func (Sym) PrecombinedString

func (sym Sym) PrecombinedString() string

PrecombinedString returns the NFC normalised Unicode form (precombined code point) as a UTF-8 string. This is the usual form.

func (*Sym) Reset

func (sym *Sym) Reset()

Reset clears the Sym so that it can be re-used.

func (Sym) String

func (sym Sym) String() string

String returns the sym as TypeGreek betacode (all diacritics after the symbol, even for capitals).

type Writer

type Writer struct {
	// Precombined UTF-8 (NFC) if false, combining diacritics otherwise.
	Combining bool
	// contains filtered or unexported fields
}

Writer converts Betacode to UTF-8 Greek.

func NewWriter

func NewWriter(w io.Writer) *Writer

func (*Writer) Flush

func (w *Writer) Flush() error

Flush flushes the underlying buffer.

func (*Writer) Write

func (w *Writer) Write(p []byte) (n int, err error)

Write converts Betacode in p to Greek. The last symbol must be complete: this Writer does not retain partial symbols between writes. The Writer must also be Flushed for the Write to take effect.

Directories

Path Synopsis
Command beta reads Betacode lines and spews out precombined Greek.
Command beta reads Betacode lines and spews out precombined Greek.

Jump to

Keyboard shortcuts

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