cat / 012
clone

a spreadsheet for the terminal: lotus 1-2-3 looks, google sheets keys and formulas, one go binary

main
012 / internal / sheet / values.go
values.go 2.9K
1package sheet23import (4 "src.rest/cat/012/internal/functions"5 "src.rest/cat/012/internal/value"6)78// Values, formats and the parsing of typed entries live in9// internal/value, below the function library and the engine; functions10// in internal/functions. The engine's API keeps their names, as it does11// the formula package's, so callers see one package.1213type (14 // Kind is the type of a computed cell value.15 Kind = value.Kind16 // Value is the computed contents of a cell.17 Value = value.Value18 // FormatKind is a number format from Sheets' Format > Number menu.19 FormatKind = value.FormatKind20 // Format is a cell's number format.21 Format = value.Format22 // FuncDef describes a spreadsheet function.23 FuncDef = functions.FuncDef24)2526// Kinds of values.27const (28 Empty = value.Empty29 Number = value.Number30 Text = value.Text31 Bool = value.Bool32 Error = value.Error33)3435// Error values, using Google Sheets codes.36var (37 ErrDiv0 = value.ErrDiv038 ErrValue = value.ErrValue39 ErrName = value.ErrName40 ErrNA = value.ErrNA41 ErrNum = value.ErrNum42 ErrRef = value.ErrRef // also circular references43)4445// Number formats.46const (47 FmtAuto = value.FmtAuto48 FmtText = value.FmtText49 FmtNumber = value.FmtNumber50 FmtPercent = value.FmtPercent51 FmtScientific = value.FmtScientific52 FmtAccounting = value.FmtAccounting53 FmtFinancial = value.FmtFinancial54 FmtCurrency = value.FmtCurrency55 FmtDate = value.FmtDate56 FmtTime = value.FmtTime57 FmtDateTime = value.FmtDateTime58 FmtDuration = value.FmtDuration59 FmtCustom = value.FmtCustom60 FmtSize = value.FmtSize6162 // MaxDecimals caps Increase decimal places.63 MaxDecimals = value.MaxDecimals64)6566// Preset returns kind with Sheets' default decimals: two for the number67// kinds.68func Preset(k FormatKind) Format { return value.Preset(k) }6970// ParseFormatKind is the inverse of FormatKind.String.71func ParseFormatKind(s string) (FormatKind, bool) { return value.ParseFormatKind(s) }7273// ParseNumber recognizes numbers the way Google Sheets does on entry.74func ParseNumber(s string) (float64, bool) { return value.ParseNumber(s) }7576// ParseValue recognizes everything Sheets turns into a number on entry:77// numbers, currency, percentages, dates and times, with the format78// Sheets applies.79func ParseValue(s string) (float64, Format, bool) { return value.ParseValue(s) }8081// LookupFunc finds a function by name or alias; callers pass upper case.82func LookupFunc(name string) (*FuncDef, bool) { return functions.LookupFunc(name) }8384// Funcs returns every function, sorted by name.85func Funcs() []*FuncDef { return functions.Funcs() }8687func num(v float64) Value { return value.Num(v) }88func boolean(b bool) Value { return value.Boolean(b) }89func text(v Value) string { return value.AsText(v) }90func compare(l, r Value) int { return value.Compare(l, r) }9192func clampInt(v, lo, hi int) int { return max(lo, min(v, hi)) }