expr

package
v0.0.0-...-f0b4dbc Latest Latest
Warning

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

Go to latest
Published: Mar 22, 2024 License: Apache-2.0 Imports: 4 Imported by: 0

README

expr

import "github.com/GeoNet/delta/internal/expr"

Overview

Package expr provides helpful conversion of mathematic expressions to base types.

The goal of this package is to behave in a similar manner to the strconv package for numerical type conversion.

It allows for code like this:

v, err := ToFloat64("1.0 + 1.0")
// v == 2.0

Index

Package files

doc.go expr.go

Variables

var ErrEvalIsUnknown = errors.New("expression is unknown")
var ErrEvalNotBool = errors.New("expression does not return a bool expression")
var ErrEvalNotComplex = errors.New("expression does not return a complex expression")
var ErrEvalNotFloat = errors.New("expression does not return a float expression")
var ErrEvalNotInt = errors.New("expression does not return an int expression")
var ErrEvalNotString = errors.New("expression does not return a string expression")

func ToBool

func ToBool(s string) (bool, error)

ToBool evaluates the given string as a bool, or it returns an error if the expression is Unknown.

func ToComplex128

func ToComplex128(s string) (complex128, error)

ToComplex128 evaluates the given string as a complex value, or it returns an error if the expression is Unknown.

func ToComplex64

func ToComplex64(s string) (complex64, error)

ToComplex64 evaluates the given string as a complex value, or it returns an error if the expression is Unknown.

func ToFloat32

func ToFloat32(s string) (float32, error)

ToFloat32 evaluates the given string as a float32, or it returns an error if the result is invalid or the expression is Unknown.

func ToFloat64

func ToFloat64(s string) (float64, error)

ToFloat64 evaluates the given string as a float64, or it returns an error if the result is invalid or the expression is Unknown.

func ToInt

func ToInt(s string) (int, error)

ToInt evaluates the given string as an int, or it returns an error if the result is invalid or the expression is Unknown.

func ToInt64

func ToInt64(s string) (int64, error)

ToInt64 evaluates the given string as an int64, or it returns an error if the result is invalid or the expression is Unknown.

func ToString

func ToString(s string) (string, error)

ToString evaluates the given string as a string, or it returns an error if the expression is Unknown.

func ToUint

func ToUint(s string) (uint, error)

ToUint evaluates the given string as a uint, or it returns an error if the result is invalid or the expression is Unknown.

func ToUint64

func ToUint64(s string) (uint64, error)

ToUint64 evaluates the given string as an uint64, or it returns an error if the result is invalid or the expression is Unknown.


Generated by godoc2md

Documentation

Overview

Package expr provides helpful conversion of mathematic expressions to base types.

The goal of this package is to behave in a similar manner to the strconv package for numerical type conversion.

It allows for code like this:

v, err := ToFloat64("1.0 + 1.0")
// v == 2.0

Index

Constants

This section is empty.

Variables

View Source
var ErrEvalIsUnknown = errors.New("expression is unknown")
View Source
var ErrEvalNotBool = errors.New("expression does not return a bool expression")
View Source
var ErrEvalNotComplex = errors.New("expression does not return a complex expression")
View Source
var ErrEvalNotFloat = errors.New("expression does not return a float expression")
View Source
var ErrEvalNotInt = errors.New("expression does not return an int expression")
View Source
var ErrEvalNotString = errors.New("expression does not return a string expression")

Functions

func ToBool

func ToBool(s string) (bool, error)

ToBool evaluates the given string as a bool, or it returns an error if the expression is Unknown.

func ToComplex128

func ToComplex128(s string) (complex128, error)

ToComplex128 evaluates the given string as a complex value, or it returns an error if the expression is Unknown.

func ToComplex64

func ToComplex64(s string) (complex64, error)

ToComplex64 evaluates the given string as a complex value, or it returns an error if the expression is Unknown.

func ToFloat32

func ToFloat32(s string) (float32, error)

ToFloat32 evaluates the given string as a float32, or it returns an error if the result is invalid or the expression is Unknown.

func ToFloat64

func ToFloat64(s string) (float64, error)

ToFloat64 evaluates the given string as a float64, or it returns an error if the result is invalid or the expression is Unknown.

func ToInt

func ToInt(s string) (int, error)

ToInt evaluates the given string as an int, or it returns an error if the result is invalid or the expression is Unknown.

func ToInt64

func ToInt64(s string) (int64, error)

ToInt64 evaluates the given string as an int64, or it returns an error if the result is invalid or the expression is Unknown.

func ToString

func ToString(s string) (string, error)

ToString evaluates the given string as a string, or it returns an error if the expression is Unknown.

func ToUint

func ToUint(s string) (uint, error)

ToUint evaluates the given string as a uint, or it returns an error if the result is invalid or the expression is Unknown.

func ToUint64

func ToUint64(s string) (uint64, error)

ToUint64 evaluates the given string as an uint64, or it returns an error if the result is invalid or the expression is Unknown.

Types

This section is empty.

Jump to

Keyboard shortcuts

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