zhao
2021-06-04 c7ec496f9e41c2227103b3ef776e4a3f91bce6b2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
/*
* Licensed to the Apache Software Foundation (ASF) Under one or more
* contributor license agreements.  See the NOTICE file distributed with
* this work for Additional information regarding copyright ownership.
* The ASF licenses this file to You Under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License.  You may obtain a copy of the License at
*
*     http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed Under the License is distributed on an "AS Is" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations Under the License.
*/
/*
 * Created on May 22, 2005
 *
 */
namespace HH.WMS.Utils.NPOI.SS.Formula.Functions
{
    using System;
    using HH.WMS.Utils.NPOI.SS.Formula.Eval;
 
    public abstract class SingleArgTextFunc : TextFunction
    {
 
        protected SingleArgTextFunc()
        {
            // no fields to initialise
        }
        public override ValueEval EvaluateFunc(ValueEval[] args, int srcCellRow, int srcCellCol)
        {
            if (args.Length != 1)
            {
                return ErrorEval.VALUE_INVALID;
            }
            String arg = EvaluateStringArg(args[0], srcCellRow, srcCellCol);
            return Evaluate(arg);
        }
        public abstract ValueEval Evaluate(String arg);
    }
 
    /**
     * @author Amol S. Deshmukh < amolweb at ya hoo dot com >
     */
    public abstract class TextFunction : Function
    {
 
        protected static String EMPTY_STRING = "";
 
        public static String EvaluateStringArg(ValueEval eval, int srcRow, int srcCol)
        {
            ValueEval ve = OperandResolver.GetSingleValue(eval, srcRow, srcCol);
            return OperandResolver.CoerceValueToString(ve);
        }
        public static int EvaluateIntArg(ValueEval arg, int srcCellRow, int srcCellCol)
        {
            ValueEval ve = OperandResolver.GetSingleValue(arg, srcCellRow, srcCellCol);
            return OperandResolver.CoerceValueToInt(ve);
        }
        public static double EvaluateDoubleArg(ValueEval arg, int srcCellRow, int srcCellCol) {
            ValueEval ve = OperandResolver.GetSingleValue(arg, srcCellRow, srcCellCol);
            return OperandResolver.CoerceValueToDouble(ve);
        }
 
        public ValueEval Evaluate(ValueEval[] args, int srcCellRow, int srcCellCol)
        {
            try
            {
                return EvaluateFunc(args, srcCellRow, srcCellCol);
            }
            catch (EvaluationException e)
            {
                return e.GetErrorEval();
            }
        }
        internal static bool IsPrintable(char c)
        {
            int charCode = (int)c;
            return charCode >= 32;
        }
        public abstract ValueEval EvaluateFunc(ValueEval[] args, int srcCellRow, int srcCellCol);
 
        /* ---------------------------------------------------------------------- */
 
 
 
        public static Function LEN = new Len();
        public static Function LOWER = new Lower();
        public static Function UPPER = new Upper();
        /**
         * @author Manda Wilson < wilson at c bio dot msk cc dot org >
         */
        ///<summary>
        ///An implementation of the TRIM function:
        ///<para>
        /// Removes leading and trailing spaces from value if evaluated operand value is string.
        ///</para>
        ///</summary>
        public static Function TRIM = new Trim();
 
        /*
         * @author Manda Wilson &lt; wilson at c bio dot msk cc dot org &gt;
        */
        ///<summary>
        ///An implementation of the MID function
        ///
        ///MID returns a specific number of
        ///characters from a text string, starting at the specified position.
        ///
        /// Syntax: MID(text, start_num, num_chars)
        ///</summary>
        public static Function MID = new Mid();
 
 
 
        public static Function LEFT = new LeftRight(true);
        public static Function RIGHT = new LeftRight(false);
 
        public static Function CONCATENATE = new Concatenate();
 
        public static Function EXACT = new Exact();
 
        public static Function TEXT = new Text();
        /**
         * @author Torstein Tauno Svendsen (torstei@officenet.no)
         */
        ///<summary>
        ///Implementation of the FIND() function.
        ///<para>
        /// Syntax: FIND(Find_text, within_text, start_num)
        ///</para>
        ///<para> FIND returns the character position of the first (case sensitive) occurrence of
        /// Find_text inside within_text.  The third parameter,
        /// start_num, is optional (default=1) and specifies where to start searching
        /// from.  Character positions are 1-based.</para>
        ///</summary>
        public static Function FIND = new SearchFind(true);
        ///<summary>
        ///Implementation of the FIND() function. SEARCH is a case-insensitive version of FIND()
        ///<para>
        /// Syntax: SEARCH(Find_text, within_text, start_num)
        ///</para>
        ///</summary>
        public static Function SEARCH = new SearchFind(false);
 
        public static Function CLEAN = new Clean();
        public static Function CHAR = new CHAR();
 
    }
}