drasi_core/evaluation/functions/
text.rs

1// Copyright 2024 The Drasi Authors.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15#[cfg(test)]
16mod tests;
17mod text;
18
19use std::sync::Arc;
20
21use self::text::{
22    LTrim, Left, RTrim, Replace, Reverse, Right, Split, Substring, ToLower, ToString,
23    ToStringOrNull, ToUpper, Trim,
24};
25
26use super::{Function, FunctionRegistry};
27
28pub trait RegisterTextFunctions {
29    fn register_text_functions(&self);
30}
31
32impl RegisterTextFunctions for FunctionRegistry {
33    fn register_text_functions(&self) {
34        self.register_function("toUpper", Function::Scalar(Arc::new(ToUpper {})));
35        self.register_function("toLower", Function::Scalar(Arc::new(ToLower {})));
36        self.register_function("trim", Function::Scalar(Arc::new(Trim {})));
37        self.register_function("ltrim", Function::Scalar(Arc::new(LTrim {})));
38        self.register_function("rtrim", Function::Scalar(Arc::new(RTrim {})));
39        self.register_function("reverse", Function::Scalar(Arc::new(Reverse {})));
40        self.register_function("left", Function::Scalar(Arc::new(Left {})));
41        self.register_function("right", Function::Scalar(Arc::new(Right {})));
42        self.register_function("replace", Function::Scalar(Arc::new(Replace {})));
43        self.register_function("split", Function::Scalar(Arc::new(Split {})));
44        self.register_function("substring", Function::Scalar(Arc::new(Substring {})));
45        self.register_function("toString", Function::Scalar(Arc::new(ToString {})));
46        self.register_function(
47            "toStringOrNull",
48            Function::Scalar(Arc::new(ToStringOrNull {})),
49        );
50    }
51}