Files

54 lines
2.1 KiB
C++
Raw Permalink Normal View History

#pragma once
#include "engine/evaluator.hpp"
#include <memory>
#include <optional>
#include <string>
#include <string_view>
#include <variant>
#include <vector>
namespace htab::fn {
inline EvalResult err_res(ErrorCode e) {
return EvalResult::from_value(Value::make_error(e));
}
std::optional<Value> eval_scalar_arg(const std::shared_ptr<Expr>& expr,
const EvalContext& ctx);
std::optional<double> eval_number_arg(const std::shared_ptr<Expr>& expr,
const EvalContext& ctx,
ErrorCode& err_out);
std::optional<bool> eval_bool_arg(const std::shared_ptr<Expr>& expr,
const EvalContext& ctx,
ErrorCode& err_out);
std::optional<std::string> eval_string_arg(const std::shared_ptr<Expr>& expr,
const EvalContext& ctx,
ErrorCode& err_out);
// Collects numeric values from variadic arguments following spreadsheet semantics:
// - Range/Array args: only numbers (ignoring Empty, String, Bool); Error propagates.
// - Direct scalar args: coerces numbers, booleans, numeric strings; Empty ignored;
// invalid text -> #VALUE!; Error propagates.
std::optional<ErrorCode> collect_numeric_args(
const std::vector<std::shared_ptr<Expr>>& args,
const EvalContext& ctx,
std::vector<double>& out_nums);
// Converts a single EvalResult (CellRange or Value) to Array2D.
std::variant<Array2D, ErrorCode> result_to_array2d(const EvalResult& res,
const Workbook& wb);
// Shared criteria matcher used by SUMIF/SUMIFS/COUNTIF/COUNTIFS/Database.
bool matches_criteria(const Value& cell_val, const Value& criteria_val);
bool wildcard_match_ci(std::string_view pattern, std::string_view text);
// UTF-8 codepoint helpers
std::vector<std::string_view> utf8_codepoints(std::string_view s);
std::string utf8_join(const std::vector<std::string_view>& cps, size_t start, size_t count);
} // namespace htab::fn