2019-07-25 19:43:46 +03:00
|
|
|
// Copyright 2017 FoxyUtils ehf. All rights reserved.
|
2017-09-14 18:59:07 -05:00
|
|
|
//
|
|
|
|
// Use of this source code is governed by the terms of the Affero GNU General
|
|
|
|
// Public License version 3.0 as published by the Free Software Foundation and
|
|
|
|
// appearing in the file LICENSE included in the packaging of this file. A
|
Functions2 (#348)
* MATCH, IFS, MAXA, MINA
* OFFSET fixed
* ISBLANK, ISERR, ISERROR, ISEVEN ,ISFORMULA, ISNONTEXT, ISNUMBER, ISODD, ISTEXT
* ISLEAPYEAR, ISLOGICAL, ISNA, ISREF
* FIND, FINDB
* SEARCH, SEARCHB
* CONCAT, CONCATENATE
* YEAR, YEARFRAC
* CONCAT is fixed, now TRUE and FALSE are concatenated instead of 1 and 0 in case of boolean results
* NOW, TODAY, TIME, TIMEVALUE
* DATE
* DATEDIF
2019-11-21 02:21:00 +03:00
|
|
|
// commercial license can be purchased on https://unidoc.io.
|
2017-09-14 18:59:07 -05:00
|
|
|
|
|
|
|
package formula
|
|
|
|
|
|
|
|
import (
|
|
|
|
"strconv"
|
2017-09-29 20:56:40 -05:00
|
|
|
|
2019-05-04 11:18:06 +03:00
|
|
|
"github.com/unidoc/unioffice"
|
2020-02-11 22:47:08 +03:00
|
|
|
"github.com/unidoc/unioffice/spreadsheet/update"
|
2017-09-14 18:59:07 -05:00
|
|
|
)
|
|
|
|
|
2020-01-29 13:43:43 +03:00
|
|
|
// Bool is a boolean expression.
|
2017-09-14 18:59:07 -05:00
|
|
|
type Bool struct {
|
|
|
|
b bool
|
|
|
|
}
|
|
|
|
|
2020-01-29 13:43:43 +03:00
|
|
|
// NewBool constructs a new boolean expression.
|
2017-09-14 18:59:07 -05:00
|
|
|
func NewBool(v string) Expression {
|
|
|
|
b, err := strconv.ParseBool(v)
|
|
|
|
if err != nil {
|
2019-05-04 13:54:29 +00:00
|
|
|
unioffice.Log("error parsing formula bool %s: %s", v, err)
|
2017-09-14 18:59:07 -05:00
|
|
|
}
|
|
|
|
return Bool{b}
|
|
|
|
}
|
|
|
|
|
2020-01-29 13:43:43 +03:00
|
|
|
// Eval evaluates and returns a boolean.
|
2017-09-14 18:59:07 -05:00
|
|
|
func (b Bool) Eval(ctx Context, ev Evaluator) Result {
|
|
|
|
return MakeBoolResult(b.b)
|
|
|
|
}
|
|
|
|
|
2020-01-29 13:43:43 +03:00
|
|
|
// Reference returns an invalid reference for Bool.
|
2017-09-14 18:59:07 -05:00
|
|
|
func (b Bool) Reference(ctx Context, ev Evaluator) Reference {
|
|
|
|
return ReferenceInvalid
|
|
|
|
}
|
2020-02-11 22:47:08 +03:00
|
|
|
|
|
|
|
// String returns a string representation for Bool.
|
|
|
|
func (b Bool) String() string {
|
|
|
|
if b.b {
|
|
|
|
return "TRUE"
|
|
|
|
} else {
|
|
|
|
return "FALSE"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Update returns the same object as updating sheet references does not affect Bool.
|
|
|
|
func (b Bool) Update(q *update.UpdateQuery) Expression {
|
|
|
|
return b
|
|
|
|
}
|