1*9b5730f6SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*9b5730f6SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*9b5730f6SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*9b5730f6SAndrew Rist  * distributed with this work for additional information
6*9b5730f6SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*9b5730f6SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*9b5730f6SAndrew Rist  * "License"); you may not use this file except in compliance
9*9b5730f6SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*9b5730f6SAndrew Rist  *
11*9b5730f6SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*9b5730f6SAndrew Rist  *
13*9b5730f6SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*9b5730f6SAndrew Rist  * software distributed under the License is distributed on an
15*9b5730f6SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*9b5730f6SAndrew Rist  * KIND, either express or implied.  See the License for the
17*9b5730f6SAndrew Rist  * specific language governing permissions and limitations
18*9b5730f6SAndrew Rist  * under the License.
19*9b5730f6SAndrew Rist  *
20*9b5730f6SAndrew Rist  *************************************************************/
21*9b5730f6SAndrew Rist 
22*9b5730f6SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_connectivity.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include "file/FStringFunctions.hxx"
28cdf0e10cSrcweir #include <rtl/ustrbuf.hxx>
29cdf0e10cSrcweir #include <rtl/logfile.hxx>
30cdf0e10cSrcweir 
31cdf0e10cSrcweir using namespace connectivity;
32cdf0e10cSrcweir using namespace connectivity::file;
33cdf0e10cSrcweir //------------------------------------------------------------------
operate(const ORowSetValue & lhs) const34cdf0e10cSrcweir ORowSetValue OOp_Upper::operate(const ORowSetValue& lhs) const
35cdf0e10cSrcweir {
36cdf0e10cSrcweir     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OOp_Upper::operate" );
37cdf0e10cSrcweir 	if ( lhs.isNull() )
38cdf0e10cSrcweir 		return lhs;
39cdf0e10cSrcweir 
40cdf0e10cSrcweir 	return lhs.getString().toAsciiUpperCase();
41cdf0e10cSrcweir }
42cdf0e10cSrcweir //------------------------------------------------------------------
operate(const ORowSetValue & lhs) const43cdf0e10cSrcweir ORowSetValue OOp_Lower::operate(const ORowSetValue& lhs) const
44cdf0e10cSrcweir {
45cdf0e10cSrcweir     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OOp_Lower::operate" );
46cdf0e10cSrcweir 	if ( lhs.isNull() )
47cdf0e10cSrcweir 		return lhs;
48cdf0e10cSrcweir 
49cdf0e10cSrcweir 	return lhs.getString().toAsciiLowerCase();
50cdf0e10cSrcweir }
51cdf0e10cSrcweir //------------------------------------------------------------------
operate(const ORowSetValue & lhs) const52cdf0e10cSrcweir ORowSetValue OOp_Ascii::operate(const ORowSetValue& lhs) const
53cdf0e10cSrcweir {
54cdf0e10cSrcweir     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OOp_Ascii::operate" );
55cdf0e10cSrcweir 	if ( lhs.isNull() )
56cdf0e10cSrcweir 		return lhs;
57cdf0e10cSrcweir 	::rtl::OString sStr(::rtl::OUStringToOString(lhs,RTL_TEXTENCODING_ASCII_US));
58cdf0e10cSrcweir 	sal_Int32 nAscii = sStr.toChar();
59cdf0e10cSrcweir 	return nAscii;
60cdf0e10cSrcweir }
61cdf0e10cSrcweir //------------------------------------------------------------------
operate(const ORowSetValue & lhs) const62cdf0e10cSrcweir ORowSetValue OOp_CharLength::operate(const ORowSetValue& lhs) const
63cdf0e10cSrcweir {
64cdf0e10cSrcweir     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OOp_CharLength::operate" );
65cdf0e10cSrcweir 	if ( lhs.isNull() )
66cdf0e10cSrcweir 		return lhs;
67cdf0e10cSrcweir 
68cdf0e10cSrcweir 	return lhs.getString().getLength();
69cdf0e10cSrcweir }
70cdf0e10cSrcweir //------------------------------------------------------------------
operate(const::std::vector<ORowSetValue> & lhs) const71cdf0e10cSrcweir ORowSetValue OOp_Char::operate(const ::std::vector<ORowSetValue>& lhs) const
72cdf0e10cSrcweir {
73cdf0e10cSrcweir     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OOp_Char::operate" );
74cdf0e10cSrcweir 	if ( lhs.empty() )
75cdf0e10cSrcweir 		return ORowSetValue();
76cdf0e10cSrcweir 
77cdf0e10cSrcweir 	::rtl::OUString sRet;
78cdf0e10cSrcweir 	::std::vector<ORowSetValue>::const_reverse_iterator aIter = lhs.rbegin();
79cdf0e10cSrcweir 	::std::vector<ORowSetValue>::const_reverse_iterator aEnd = lhs.rend();
80cdf0e10cSrcweir 	for (; aIter != aEnd; ++aIter)
81cdf0e10cSrcweir 	{
82cdf0e10cSrcweir 		if ( !aIter->isNull() )
83cdf0e10cSrcweir 		{
84cdf0e10cSrcweir 			sal_Char c = static_cast<sal_Char>(static_cast<sal_Int32>(*aIter));
85cdf0e10cSrcweir 
86cdf0e10cSrcweir 			sRet += ::rtl::OUString(&c,1,RTL_TEXTENCODING_ASCII_US);
87cdf0e10cSrcweir 		}
88cdf0e10cSrcweir 	}
89cdf0e10cSrcweir 
90cdf0e10cSrcweir 	return sRet;
91cdf0e10cSrcweir }
92cdf0e10cSrcweir //------------------------------------------------------------------
operate(const::std::vector<ORowSetValue> & lhs) const93cdf0e10cSrcweir ORowSetValue OOp_Concat::operate(const ::std::vector<ORowSetValue>& lhs) const
94cdf0e10cSrcweir {
95cdf0e10cSrcweir     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OOp_Concat::operate" );
96cdf0e10cSrcweir 	if ( lhs.empty() )
97cdf0e10cSrcweir 		return ORowSetValue();
98cdf0e10cSrcweir 
99cdf0e10cSrcweir 	::rtl::OUStringBuffer sRet;
100cdf0e10cSrcweir 	::std::vector<ORowSetValue>::const_reverse_iterator aIter = lhs.rbegin();
101cdf0e10cSrcweir 	::std::vector<ORowSetValue>::const_reverse_iterator aEnd = lhs.rend();
102cdf0e10cSrcweir 	for (; aIter != aEnd; ++aIter)
103cdf0e10cSrcweir 	{
104cdf0e10cSrcweir 		if ( aIter->isNull() )
105cdf0e10cSrcweir 			return ORowSetValue();
106cdf0e10cSrcweir 
107cdf0e10cSrcweir 		sRet.append(aIter->operator ::rtl::OUString());
108cdf0e10cSrcweir 	}
109cdf0e10cSrcweir 
110cdf0e10cSrcweir 	return sRet.makeStringAndClear();
111cdf0e10cSrcweir }
112cdf0e10cSrcweir //------------------------------------------------------------------
operate(const::std::vector<ORowSetValue> & lhs) const113cdf0e10cSrcweir ORowSetValue OOp_Locate::operate(const ::std::vector<ORowSetValue>& lhs) const
114cdf0e10cSrcweir {
115cdf0e10cSrcweir     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OOp_Locate::operate" );
116cdf0e10cSrcweir 	::std::vector<ORowSetValue>::const_iterator aIter = lhs.begin();
117cdf0e10cSrcweir 	::std::vector<ORowSetValue>::const_iterator aEnd = lhs.end();
118cdf0e10cSrcweir 	for (; aIter != aEnd; ++aIter)
119cdf0e10cSrcweir 	{
120cdf0e10cSrcweir 		if ( aIter->isNull() )
121cdf0e10cSrcweir 			return ORowSetValue();
122cdf0e10cSrcweir 	}
123cdf0e10cSrcweir 	if ( lhs.size() == 2 )
124cdf0e10cSrcweir 		return ::rtl::OUString::valueOf(lhs[0].getString().indexOf(lhs[1].getString())+1);
125cdf0e10cSrcweir 
126cdf0e10cSrcweir 	else if ( lhs.size() != 3 )
127cdf0e10cSrcweir 		return ORowSetValue();
128cdf0e10cSrcweir 
129cdf0e10cSrcweir 	return lhs[1].getString().indexOf(lhs[2].getString(),lhs[0]) + 1;
130cdf0e10cSrcweir }
131cdf0e10cSrcweir //------------------------------------------------------------------
operate(const::std::vector<ORowSetValue> & lhs) const132cdf0e10cSrcweir ORowSetValue OOp_SubString::operate(const ::std::vector<ORowSetValue>& lhs) const
133cdf0e10cSrcweir {
134cdf0e10cSrcweir     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OOp_SubString::operate" );
135cdf0e10cSrcweir 	::std::vector<ORowSetValue>::const_iterator aIter = lhs.begin();
136cdf0e10cSrcweir 	::std::vector<ORowSetValue>::const_iterator aEnd = lhs.end();
137cdf0e10cSrcweir 	for (; aIter != aEnd; ++aIter)
138cdf0e10cSrcweir 	{
139cdf0e10cSrcweir 		if ( aIter->isNull() )
140cdf0e10cSrcweir 			return ORowSetValue();
141cdf0e10cSrcweir 	}
142cdf0e10cSrcweir 	if ( lhs.size() == 2 && static_cast<sal_Int32>(lhs[0]) >= sal_Int32(0) )
143cdf0e10cSrcweir 		return lhs[1].getString().copy(static_cast<sal_Int32>(lhs[0])-1);
144cdf0e10cSrcweir 
145cdf0e10cSrcweir 	else if ( lhs.size() != 3 || static_cast<sal_Int32>(lhs[1]) < sal_Int32(0))
146cdf0e10cSrcweir 		return ORowSetValue();
147cdf0e10cSrcweir 
148cdf0e10cSrcweir 	return lhs[2].getString().copy(static_cast<sal_Int32>(lhs[1])-1,lhs[0]);
149cdf0e10cSrcweir }
150cdf0e10cSrcweir //------------------------------------------------------------------
operate(const ORowSetValue & lhs) const151cdf0e10cSrcweir ORowSetValue OOp_LTrim::operate(const ORowSetValue& lhs) const
152cdf0e10cSrcweir {
153cdf0e10cSrcweir     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OOp_LTrim::operate" );
154cdf0e10cSrcweir 	if ( lhs.isNull() )
155cdf0e10cSrcweir 		return lhs;
156cdf0e10cSrcweir 
157cdf0e10cSrcweir 	::rtl::OUString sRet = lhs;
158cdf0e10cSrcweir 	::rtl::OUString sNew = sRet.trim();
159cdf0e10cSrcweir 	return sRet.copy(sRet.indexOf(sNew));
160cdf0e10cSrcweir }
161cdf0e10cSrcweir //------------------------------------------------------------------
operate(const ORowSetValue & lhs) const162cdf0e10cSrcweir ORowSetValue OOp_RTrim::operate(const ORowSetValue& lhs) const
163cdf0e10cSrcweir {
164cdf0e10cSrcweir     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OOp_RTrim::operate" );
165cdf0e10cSrcweir 	if ( lhs.isNull() )
166cdf0e10cSrcweir 		return lhs;
167cdf0e10cSrcweir 
168cdf0e10cSrcweir 	::rtl::OUString sRet = lhs;
169cdf0e10cSrcweir 	::rtl::OUString sNew = sRet.trim();
170cdf0e10cSrcweir 	return sRet.copy(0,sRet.lastIndexOf(sNew.getStr()[sNew.getLength()-1])+1);
171cdf0e10cSrcweir }
172cdf0e10cSrcweir //------------------------------------------------------------------
operate(const ORowSetValue & lhs) const173cdf0e10cSrcweir ORowSetValue OOp_Space::operate(const ORowSetValue& lhs) const
174cdf0e10cSrcweir {
175cdf0e10cSrcweir     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OOp_Space::operate" );
176cdf0e10cSrcweir 	if ( lhs.isNull() )
177cdf0e10cSrcweir 		return lhs;
178cdf0e10cSrcweir 
179cdf0e10cSrcweir 	const sal_Char c = ' ';
180cdf0e10cSrcweir 	::rtl::OUStringBuffer sRet;
181cdf0e10cSrcweir 	sal_Int32 nCount = lhs;
182cdf0e10cSrcweir 	for (sal_Int32 i=0; i < nCount; ++i)
183cdf0e10cSrcweir 	{
184cdf0e10cSrcweir 		sRet.appendAscii(&c,1);
185cdf0e10cSrcweir 	}
186cdf0e10cSrcweir 	return sRet.makeStringAndClear();
187cdf0e10cSrcweir }
188cdf0e10cSrcweir //------------------------------------------------------------------
operate(const::std::vector<ORowSetValue> & lhs) const189cdf0e10cSrcweir ORowSetValue OOp_Replace::operate(const ::std::vector<ORowSetValue>& lhs) const
190cdf0e10cSrcweir {
191cdf0e10cSrcweir     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OOp_Replace::operate" );
192cdf0e10cSrcweir 	if ( lhs.size() != 3 )
193cdf0e10cSrcweir 		return ORowSetValue();
194cdf0e10cSrcweir 
195cdf0e10cSrcweir 	::rtl::OUString sStr  = lhs[2];
196cdf0e10cSrcweir 	::rtl::OUString sFrom = lhs[1];
197cdf0e10cSrcweir 	::rtl::OUString sTo   = lhs[0];
198cdf0e10cSrcweir 	sal_Int32 nIndexOf = sStr.indexOf(sFrom);
199cdf0e10cSrcweir 	while( nIndexOf != -1 )
200cdf0e10cSrcweir 	{
201cdf0e10cSrcweir 		sStr = sStr.replaceAt(nIndexOf,sFrom.getLength(),sTo);
202cdf0e10cSrcweir 		nIndexOf = sStr.indexOf(sFrom,nIndexOf + sTo.getLength());
203cdf0e10cSrcweir 	}
204cdf0e10cSrcweir 
205cdf0e10cSrcweir 	return sStr;
206cdf0e10cSrcweir }
207cdf0e10cSrcweir //------------------------------------------------------------------
operate(const ORowSetValue & lhs,const ORowSetValue & rhs) const208cdf0e10cSrcweir ORowSetValue OOp_Repeat::operate(const ORowSetValue& lhs,const ORowSetValue& rhs) const
209cdf0e10cSrcweir {
210cdf0e10cSrcweir     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OOp_Repeat::operate" );
211cdf0e10cSrcweir 	if ( lhs.isNull() || rhs.isNull() )
212cdf0e10cSrcweir 		return lhs;
213cdf0e10cSrcweir 
214cdf0e10cSrcweir 	::rtl::OUString sRet;
215cdf0e10cSrcweir 	sal_Int32 nCount = rhs;
216cdf0e10cSrcweir 	for (sal_Int32 i=0; i < nCount; ++i)
217cdf0e10cSrcweir 	{
218cdf0e10cSrcweir 		sRet += lhs;
219cdf0e10cSrcweir 	}
220cdf0e10cSrcweir 	return sRet;
221cdf0e10cSrcweir }
222cdf0e10cSrcweir //------------------------------------------------------------------
operate(const::std::vector<ORowSetValue> & lhs) const223cdf0e10cSrcweir ORowSetValue OOp_Insert::operate(const ::std::vector<ORowSetValue>& lhs) const
224cdf0e10cSrcweir {
225cdf0e10cSrcweir     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OOp_Insert::operate" );
226cdf0e10cSrcweir 	if ( lhs.size() != 4 )
227cdf0e10cSrcweir 		return ORowSetValue();
228cdf0e10cSrcweir 
229cdf0e10cSrcweir 	::rtl::OUString sStr = lhs[3];
230cdf0e10cSrcweir 
231cdf0e10cSrcweir 	sal_Int32 nStart = static_cast<sal_Int32>(lhs[2]);
232cdf0e10cSrcweir 	if ( nStart < 1 )
233cdf0e10cSrcweir 		nStart = 1;
234cdf0e10cSrcweir 	return sStr.replaceAt(nStart-1,static_cast<sal_Int32>(lhs[1]),lhs[0]);
235cdf0e10cSrcweir }
236cdf0e10cSrcweir //------------------------------------------------------------------
operate(const ORowSetValue & lhs,const ORowSetValue & rhs) const237cdf0e10cSrcweir ORowSetValue OOp_Left::operate(const ORowSetValue& lhs,const ORowSetValue& rhs) const
238cdf0e10cSrcweir {
239cdf0e10cSrcweir     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OOp_Left::operate" );
240cdf0e10cSrcweir 	if ( lhs.isNull() || rhs.isNull() )
241cdf0e10cSrcweir 		return lhs;
242cdf0e10cSrcweir 
243cdf0e10cSrcweir 	::rtl::OUString sRet = lhs;
244cdf0e10cSrcweir 	sal_Int32 nCount = rhs;
245cdf0e10cSrcweir 	if ( nCount < 0 )
246cdf0e10cSrcweir 		return ORowSetValue();
247cdf0e10cSrcweir 	return sRet.copy(0,nCount);
248cdf0e10cSrcweir }
249cdf0e10cSrcweir //------------------------------------------------------------------
operate(const ORowSetValue & lhs,const ORowSetValue & rhs) const250cdf0e10cSrcweir ORowSetValue OOp_Right::operate(const ORowSetValue& lhs,const ORowSetValue& rhs) const
251cdf0e10cSrcweir {
252cdf0e10cSrcweir     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OOp_Right::operate" );
253cdf0e10cSrcweir 	if ( lhs.isNull() || rhs.isNull() )
254cdf0e10cSrcweir 		return lhs;
255cdf0e10cSrcweir 
256cdf0e10cSrcweir 	sal_Int32 nCount = rhs;
257cdf0e10cSrcweir 	::rtl::OUString sRet = lhs;
258cdf0e10cSrcweir 	if ( nCount < 0 || nCount >= sRet.getLength() )
259cdf0e10cSrcweir 		return ORowSetValue();
260cdf0e10cSrcweir 
261cdf0e10cSrcweir 	return sRet.copy(sRet.getLength()-nCount,nCount);
262cdf0e10cSrcweir }
263cdf0e10cSrcweir 
264