algorithmic

package
v2.14.0 Latest Latest
Warning

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

Go to latest
Published: Jun 3, 2024 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package algorithmic implements parsing and formatting of common non-decimal number systems, such as roman numerals and traditional tamil numbers.

These correspond to the rules in CLDR 41.0 at "rbnf/root.xml" (and does not include every algorithmic numbering system mentioned in "numberingSystems.xml").

Example (RulesetNames)
package main

import (
	"fmt"

	"github.com/tawesoft/golib/v2/must"
	"github.com/tawesoft/golib/v2/text/number/algorithmic"
)

func main() {
	const v = int64(1234)
	fmt.Printf("Supported rulesets and example(%d):\n", v)
	for _, name := range algorithmic.RulesetNames {
		str := must.Result(algorithmic.Format(name, v))
		fmt.Printf("> %s; %s\n", name, str)
	}

}
Output:

Supported rulesets and example(1234):
> armenian-lower; ռմլդ
> armenian-upper; ՌՄԼԴ
> cyrillic-lower; ҂асл҃д
> ethiopic; ፩፻፪፻፴፬
> georgian; შსლდ
> greek-lower; ͵ασλδ´
> greek-upper; ͵ΑΣΛΔ´
> hebrew; א׳רל״ד
> hebrew-item; תתתלד
> roman-lower; mccxxxiv
> roman-upper; MCCXXXIV
> tamil; ௲௨௱௩௰௪

Index

Examples

Constants

This section is empty.

Variables

View Source
var RulesetNames = func() []string {
	xs := group.RulesetNames()
	sort.Strings(xs)
	return xs
}()

RulesetNames is a slice of all algorithmic rulesets implemented by this package.

Functions

func Format

func Format(name string, number int64) (string, error)

Format formats a number using a given algorithmic ruleset such as "roman-upper".

Example
package main

import (
	"fmt"

	"github.com/tawesoft/golib/v2/text/number/algorithmic"
)

func main() {
	print := func(system string, n int64) {
		if s, err := algorithmic.Format(system, n); err == nil {
			fmt.Printf("algorithmic.Format(%q, %d): %q\n", system, n, s)
		} else {
			fmt.Printf("algorithmic.Format(%q, %d): error: %v\n", system, n, err)
		}
	}

	print("roman-upper", 2023)

}
Output:

algorithmic.Format("roman-upper", 2023): "MMXXIII"

func Formatter added in v2.8.5

func Formatter(name string) (rbnf.Formatter, bool)

Formatter returns a new rbnf.Formatter for a given algorithmic ruleset such as "roman-upper".

Types

This section is empty.

Jump to

Keyboard shortcuts

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