Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 :
21 : #include "file/FStringFunctions.hxx"
22 : #include <rtl/ustrbuf.hxx>
23 :
24 : using namespace connectivity;
25 : using namespace connectivity::file;
26 :
27 0 : ORowSetValue OOp_Upper::operate(const ORowSetValue& lhs) const
28 : {
29 : SAL_INFO( "connectivity.drivers", "file Ocke.Janssen@sun.com OOp_Upper::operate" );
30 0 : if ( lhs.isNull() )
31 0 : return lhs;
32 :
33 0 : return lhs.getString().toAsciiUpperCase();
34 : }
35 :
36 0 : ORowSetValue OOp_Lower::operate(const ORowSetValue& lhs) const
37 : {
38 : SAL_INFO( "connectivity.drivers", "file Ocke.Janssen@sun.com OOp_Lower::operate" );
39 0 : if ( lhs.isNull() )
40 0 : return lhs;
41 :
42 0 : return lhs.getString().toAsciiLowerCase();
43 : }
44 :
45 0 : ORowSetValue OOp_Ascii::operate(const ORowSetValue& lhs) const
46 : {
47 : SAL_INFO( "connectivity.drivers", "file Ocke.Janssen@sun.com OOp_Ascii::operate" );
48 0 : if ( lhs.isNull() )
49 0 : return lhs;
50 0 : OString sStr(OUStringToOString(lhs,RTL_TEXTENCODING_ASCII_US));
51 0 : sal_Int32 nAscii = sStr.toChar();
52 0 : return nAscii;
53 : }
54 :
55 0 : ORowSetValue OOp_CharLength::operate(const ORowSetValue& lhs) const
56 : {
57 : SAL_INFO( "connectivity.drivers", "file Ocke.Janssen@sun.com OOp_CharLength::operate" );
58 0 : if ( lhs.isNull() )
59 0 : return lhs;
60 :
61 0 : return lhs.getString().getLength();
62 : }
63 :
64 0 : ORowSetValue OOp_Char::operate(const ::std::vector<ORowSetValue>& lhs) const
65 : {
66 : SAL_INFO( "connectivity.drivers", "file Ocke.Janssen@sun.com OOp_Char::operate" );
67 0 : if ( lhs.empty() )
68 0 : return ORowSetValue();
69 :
70 0 : OUString sRet;
71 0 : ::std::vector<ORowSetValue>::const_reverse_iterator aIter = lhs.rbegin();
72 0 : ::std::vector<ORowSetValue>::const_reverse_iterator aEnd = lhs.rend();
73 0 : for (; aIter != aEnd; ++aIter)
74 : {
75 0 : if ( !aIter->isNull() )
76 : {
77 0 : sal_Char c = static_cast<sal_Char>(static_cast<sal_Int32>(*aIter));
78 :
79 0 : sRet += OUString(&c,1,RTL_TEXTENCODING_ASCII_US);
80 : }
81 : }
82 :
83 0 : return sRet;
84 : }
85 :
86 0 : ORowSetValue OOp_Concat::operate(const ::std::vector<ORowSetValue>& lhs) const
87 : {
88 : SAL_INFO( "connectivity.drivers", "file Ocke.Janssen@sun.com OOp_Concat::operate" );
89 0 : if ( lhs.empty() )
90 0 : return ORowSetValue();
91 :
92 0 : OUStringBuffer sRet;
93 0 : ::std::vector<ORowSetValue>::const_reverse_iterator aIter = lhs.rbegin();
94 0 : ::std::vector<ORowSetValue>::const_reverse_iterator aEnd = lhs.rend();
95 0 : for (; aIter != aEnd; ++aIter)
96 : {
97 0 : if ( aIter->isNull() )
98 0 : return ORowSetValue();
99 :
100 0 : sRet.append(aIter->operator OUString());
101 : }
102 :
103 0 : return sRet.makeStringAndClear();
104 : }
105 :
106 0 : ORowSetValue OOp_Locate::operate(const ::std::vector<ORowSetValue>& lhs) const
107 : {
108 : SAL_INFO( "connectivity.drivers", "file Ocke.Janssen@sun.com OOp_Locate::operate" );
109 0 : ::std::vector<ORowSetValue>::const_iterator aIter = lhs.begin();
110 0 : ::std::vector<ORowSetValue>::const_iterator aEnd = lhs.end();
111 0 : for (; aIter != aEnd; ++aIter)
112 : {
113 0 : if ( aIter->isNull() )
114 0 : return ORowSetValue();
115 : }
116 0 : if ( lhs.size() == 2 )
117 0 : return OUString::number(lhs[0].getString().indexOf(lhs[1].getString())+1);
118 :
119 0 : else if ( lhs.size() != 3 )
120 0 : return ORowSetValue();
121 :
122 0 : return lhs[1].getString().indexOf(lhs[2].getString(),lhs[0]) + 1;
123 : }
124 :
125 0 : ORowSetValue OOp_SubString::operate(const ::std::vector<ORowSetValue>& lhs) const
126 : {
127 : SAL_INFO( "connectivity.drivers", "file Ocke.Janssen@sun.com OOp_SubString::operate" );
128 0 : ::std::vector<ORowSetValue>::const_iterator aIter = lhs.begin();
129 0 : ::std::vector<ORowSetValue>::const_iterator aEnd = lhs.end();
130 0 : for (; aIter != aEnd; ++aIter)
131 : {
132 0 : if ( aIter->isNull() )
133 0 : return ORowSetValue();
134 : }
135 0 : if ( lhs.size() == 2 && static_cast<sal_Int32>(lhs[0]) >= sal_Int32(0) )
136 0 : return lhs[1].getString().copy(static_cast<sal_Int32>(lhs[0])-1);
137 :
138 0 : else if ( lhs.size() != 3 || static_cast<sal_Int32>(lhs[1]) < sal_Int32(0))
139 0 : return ORowSetValue();
140 :
141 0 : return lhs[2].getString().copy(static_cast<sal_Int32>(lhs[1])-1,lhs[0]);
142 : }
143 :
144 0 : ORowSetValue OOp_LTrim::operate(const ORowSetValue& lhs) const
145 : {
146 : SAL_INFO( "connectivity.drivers", "file Ocke.Janssen@sun.com OOp_LTrim::operate" );
147 0 : if ( lhs.isNull() )
148 0 : return lhs;
149 :
150 0 : OUString sRet = lhs;
151 0 : OUString sNew = sRet.trim();
152 0 : return sRet.copy(sRet.indexOf(sNew));
153 : }
154 :
155 0 : ORowSetValue OOp_RTrim::operate(const ORowSetValue& lhs) const
156 : {
157 : SAL_INFO( "connectivity.drivers", "file Ocke.Janssen@sun.com OOp_RTrim::operate" );
158 0 : if ( lhs.isNull() )
159 0 : return lhs;
160 :
161 0 : OUString sRet = lhs;
162 0 : OUString sNew = sRet.trim();
163 0 : return sRet.copy(0,sRet.lastIndexOf(sNew[sNew.getLength()-1])+1);
164 : }
165 :
166 0 : ORowSetValue OOp_Space::operate(const ORowSetValue& lhs) const
167 : {
168 : SAL_INFO( "connectivity.drivers", "file Ocke.Janssen@sun.com OOp_Space::operate" );
169 0 : if ( lhs.isNull() )
170 0 : return lhs;
171 :
172 0 : const sal_Char c = ' ';
173 0 : OUStringBuffer sRet;
174 0 : sal_Int32 nCount = lhs;
175 0 : for (sal_Int32 i=0; i < nCount; ++i)
176 : {
177 0 : sRet.appendAscii(&c,1);
178 : }
179 0 : return sRet.makeStringAndClear();
180 : }
181 :
182 0 : ORowSetValue OOp_Replace::operate(const ::std::vector<ORowSetValue>& lhs) const
183 : {
184 : SAL_INFO( "connectivity.drivers", "file Ocke.Janssen@sun.com OOp_Replace::operate" );
185 0 : if ( lhs.size() != 3 )
186 0 : return ORowSetValue();
187 :
188 0 : OUString sStr = lhs[2];
189 0 : OUString sFrom = lhs[1];
190 0 : OUString sTo = lhs[0];
191 0 : sal_Int32 nIndexOf = sStr.indexOf(sFrom);
192 0 : while( nIndexOf != -1 )
193 : {
194 0 : sStr = sStr.replaceAt(nIndexOf,sFrom.getLength(),sTo);
195 0 : nIndexOf = sStr.indexOf(sFrom,nIndexOf + sTo.getLength());
196 : }
197 :
198 0 : return sStr;
199 : }
200 :
201 0 : ORowSetValue OOp_Repeat::operate(const ORowSetValue& lhs,const ORowSetValue& rhs) const
202 : {
203 : SAL_INFO( "connectivity.drivers", "file Ocke.Janssen@sun.com OOp_Repeat::operate" );
204 0 : if ( lhs.isNull() || rhs.isNull() )
205 0 : return lhs;
206 :
207 0 : OUString sRet;
208 0 : sal_Int32 nCount = rhs;
209 0 : for (sal_Int32 i=0; i < nCount; ++i)
210 : {
211 0 : sRet += lhs;
212 : }
213 0 : return sRet;
214 : }
215 :
216 0 : ORowSetValue OOp_Insert::operate(const ::std::vector<ORowSetValue>& lhs) const
217 : {
218 : SAL_INFO( "connectivity.drivers", "file Ocke.Janssen@sun.com OOp_Insert::operate" );
219 0 : if ( lhs.size() != 4 )
220 0 : return ORowSetValue();
221 :
222 0 : OUString sStr = lhs[3];
223 :
224 0 : sal_Int32 nStart = static_cast<sal_Int32>(lhs[2]);
225 0 : if ( nStart < 1 )
226 0 : nStart = 1;
227 0 : return sStr.replaceAt(nStart-1,static_cast<sal_Int32>(lhs[1]),lhs[0]);
228 : }
229 :
230 0 : ORowSetValue OOp_Left::operate(const ORowSetValue& lhs,const ORowSetValue& rhs) const
231 : {
232 : SAL_INFO( "connectivity.drivers", "file Ocke.Janssen@sun.com OOp_Left::operate" );
233 0 : if ( lhs.isNull() || rhs.isNull() )
234 0 : return lhs;
235 :
236 0 : OUString sRet = lhs;
237 0 : sal_Int32 nCount = rhs;
238 0 : if ( nCount < 0 )
239 0 : return ORowSetValue();
240 0 : return sRet.copy(0,nCount);
241 : }
242 :
243 0 : ORowSetValue OOp_Right::operate(const ORowSetValue& lhs,const ORowSetValue& rhs) const
244 : {
245 : SAL_INFO( "connectivity.drivers", "file Ocke.Janssen@sun.com OOp_Right::operate" );
246 0 : if ( lhs.isNull() || rhs.isNull() )
247 0 : return lhs;
248 :
249 0 : sal_Int32 nCount = rhs;
250 0 : OUString sRet = lhs;
251 0 : if ( nCount < 0 || nCount >= sRet.getLength() )
252 0 : return ORowSetValue();
253 :
254 0 : return sRet.copy(sRet.getLength()-nCount,nCount);
255 : }
256 :
257 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|