xref: /trunk/main/connectivity/source/inc/file/FStringFunctions.hxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 #ifndef _CONNECTIVITY_FILE_FSTRINGFUNCTIONS_HXX_
29 #define _CONNECTIVITY_FILE_FSTRINGFUNCTIONS_HXX_
30 
31 #include "file/fcode.hxx"
32 #include "file/filedllapi.hxx"
33 
34 namespace connectivity
35 {
36     class OSQLParseNode;
37     namespace file
38     {
39         /** UCASE(str)
40             UPPER(str)
41                 Returns the string str with all characters changed to uppercase according to the current character set mapping (the default is ISO-8859-1 Latin1):
42 
43             > SELECT UCASE('Hej');
44                     -> 'HEJ'
45 
46         */
47         class OOp_Upper : public OUnaryOperator
48         {
49         protected:
50             virtual ORowSetValue operate(const ORowSetValue& lhs) const;
51         };
52 
53         /** LCASE(str)
54             LOWER(str)
55                 Returns the string str with all characters changed to lowercase according to the current character set mapping (the default is ISO-8859-1 Latin1):
56 
57             > SELECT LCASE('QUADRATICALLY');
58                     -> 'quadratically'
59 
60         */
61         class OOp_Lower : public OUnaryOperator
62         {
63         protected:
64             virtual ORowSetValue operate(const ORowSetValue& lhs) const;
65         };
66 
67         /** ASCII(str)
68             Returns the ASCII code value of the leftmost character of the string str. Returns 0 if str is the empty string. Returns NULL if str is NULL:
69 
70             > SELECT ASCII('2');
71                 -> 50
72             > SELECT ASCII(2);
73                 -> 50
74             > SELECT ASCII('dx');
75                 -> 100
76 
77         */
78         class OOp_Ascii : public OUnaryOperator
79         {
80         protected:
81             virtual ORowSetValue operate(const ORowSetValue& lhs) const;
82         };
83 
84         /** LENGTH(str)
85             OCTET_LENGTH(str)
86             CHAR_LENGTH(str)
87             CHARACTER_LENGTH(str)
88                 Returns the length of the string str:
89 
90             > SELECT LENGTH('text');
91                     -> 4
92             > SELECT OCTET_LENGTH('text');
93                     -> 4
94 
95         */
96         class OOp_CharLength : public OUnaryOperator
97         {
98         protected:
99             virtual ORowSetValue operate(const ORowSetValue& lhs) const;
100         };
101 
102         /** CHAR(N,...)
103             CHAR() interprets the arguments as integers and returns a string consisting of the characters given by the ASCII code values of those integers. NULL values are skipped:
104 
105             > SELECT CHAR(ascii('t'),ascii('e'),ascii('s'),ascii('t'));
106                 -> 'test'
107             > SELECT CHAR(77,77.3,'77.3');
108                 -> 'MMM'
109 
110         */
111         class OOp_Char : public ONthOperator
112         {
113         protected:
114             virtual ORowSetValue operate(const ::std::vector<ORowSetValue>& lhs) const;
115         };
116 
117         /** CONCAT(str1,str2,...)
118             Returns the string that results from concatenating the arguments. Returns NULL if any argument is NULL. May have more than 2 arguments. A numeric argument is converted to the equivalent string form:
119 
120             > SELECT CONCAT('OO', 'o', 'OO');
121                 -> 'OOoOO'
122             > SELECT CONCAT('OO', NULL, 'OO');
123                 -> NULL
124             > SELECT CONCAT(14.3);
125                 -> '14.3'
126 
127         */
128         class OOp_Concat : public ONthOperator
129         {
130         protected:
131             virtual ORowSetValue operate(const ::std::vector<ORowSetValue>& lhs) const;
132         };
133 
134         /** LOCATE(substr,str)
135             POSITION(substr IN str)
136             Returns the position of the first occurrence of substring substr in string str. Returns 0 if substr is not in str:
137 
138             > SELECT LOCATE('bar', 'foobarbar');
139                     -> 4
140             > SELECT LOCATE('xbar', 'foobar');
141                     -> 0
142             LOCATE(substr,str,pos)
143             Returns the position of the first occurrence of substring substr in string str, starting at position pos. Returns 0 if substr is not in str:
144 
145             > SELECT LOCATE('bar', 'foobarbar',5);
146                 -> 7
147 
148         */
149         class OOp_Locate : public ONthOperator
150         {
151         protected:
152             virtual ORowSetValue operate(const ::std::vector<ORowSetValue>& lhs) const;
153         };
154 
155         /** SUBSTRING(str,pos)
156             SUBSTRING(str FROM pos)
157                 Returns a substring from string str starting at position pos:
158 
159             > SELECT SUBSTRING('Quadratically',5);
160                     -> 'ratically'
161             > SELECT SUBSTRING('foobarbar' FROM 4);
162                     -> 'barbar'
163             SUBSTRING(str,pos,len)
164             SUBSTRING(str FROM pos FOR len)
165                 Returns a substring len characters long from string str, starting at position pos. The variant form that uses FROM is SQL-92 syntax:
166 
167             > SELECT SUBSTRING('Quadratically',5,6);
168                     -> 'ratica'
169 
170         */
171         class OOp_SubString : public ONthOperator
172         {
173         protected:
174             virtual ORowSetValue operate(const ::std::vector<ORowSetValue>& lhs) const;
175         };
176 
177         /** LTRIM(str)
178             Returns the string str with leading space characters removed:
179 
180             > SELECT LTRIM('  barbar');
181                 -> 'barbar'
182 
183         */
184         class OOp_LTrim : public OUnaryOperator
185         {
186         protected:
187             virtual ORowSetValue operate(const ORowSetValue& lhs) const;
188         };
189 
190         /** RTRIM(str)
191             Returns the string str with trailing space characters removed:
192 
193             > SELECT RTRIM('barbar   ');
194                 -> 'barbar'
195 
196         */
197         class OOp_RTrim : public OUnaryOperator
198         {
199         protected:
200             virtual ORowSetValue operate(const ORowSetValue& lhs) const;
201         };
202 
203         /** SPACE(N)
204             Returns a string consisting of N space characters:
205 
206             > SELECT SPACE(6);
207                 -> '      '
208 
209         */
210         class OOp_Space : public OUnaryOperator
211         {
212         protected:
213             virtual ORowSetValue operate(const ORowSetValue& lhs) const;
214         };
215 
216         /** REPLACE(str,from_str,to_str)
217             Returns the string str with all occurrences of the string from_str replaced by the string to_str:
218 
219             > SELECT REPLACE('www.OOo.com', 'w', 'Ww');
220                 -> 'WwWwWw.OOo.com'
221 
222         */
223         class OOp_Replace : public ONthOperator
224         {
225         protected:
226             virtual ORowSetValue operate(const ::std::vector<ORowSetValue>& lhs) const;
227         };
228 
229         /** REPEAT(str,count)
230             Returns a string consisting of the string str repeated count times. If count <= 0, returns an empty string. Returns NULL if str or count are NULL:
231 
232             > SELECT REPEAT('OOo', 3);
233                 -> 'OOoOOoOOo'
234 
235         */
236         class OOp_Repeat : public OBinaryOperator
237         {
238         protected:
239             virtual ORowSetValue operate(const ORowSetValue& lhs,const ORowSetValue& rhs) const;
240         };
241 
242         /** INSERT(str,pos,len,newstr)
243             Returns the string str, with the substring beginning at position pos and len characters long replaced by the string newstr:
244 
245             > SELECT INSERT('Quadratic', 3, 4, 'What');
246                 -> 'QuWhattic'
247 
248         */
249         class OOp_Insert : public ONthOperator
250         {
251         protected:
252             virtual ORowSetValue operate(const ::std::vector<ORowSetValue>& lhs) const;
253         };
254 
255         /** LEFT(str,len)
256             Returns the leftmost len characters from the string str:
257 
258             > SELECT LEFT('foobarbar', 5);
259                 -> 'fooba'
260 
261         */
262         class OOp_Left : public OBinaryOperator
263         {
264         protected:
265             virtual ORowSetValue operate(const ORowSetValue& lhs,const ORowSetValue& rhs) const;
266         };
267 
268         /** RIGHT(str,len)
269             Returns the rightmost len characters from the string str:
270 
271             > SELECT RIGHT('foobarbar', 4);
272                 -> 'rbar'
273         */
274         class OOp_Right : public OBinaryOperator
275         {
276         protected:
277             virtual ORowSetValue operate(const ORowSetValue& lhs,const ORowSetValue& rhs) const;
278         };
279     }
280 }
281 
282 #endif // _CONNECTIVITY_FILE_FCODE_HXX_
283 
284