Branch data 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 : : #include <rtl/logfile.hxx>
24 : :
25 : : using namespace connectivity;
26 : : using namespace connectivity::file;
27 : : //------------------------------------------------------------------
28 : 0 : ORowSetValue OOp_Upper::operate(const ORowSetValue& lhs) const
29 : : {
30 : : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OOp_Upper::operate" );
31 [ # # ]: 0 : if ( lhs.isNull() )
32 : 0 : return lhs;
33 : :
34 [ # # ]: 0 : return lhs.getString().toAsciiUpperCase();
35 : : }
36 : : //------------------------------------------------------------------
37 : 0 : ORowSetValue OOp_Lower::operate(const ORowSetValue& lhs) const
38 : : {
39 : : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OOp_Lower::operate" );
40 [ # # ]: 0 : if ( lhs.isNull() )
41 : 0 : return lhs;
42 : :
43 [ # # ]: 0 : return lhs.getString().toAsciiLowerCase();
44 : : }
45 : : //------------------------------------------------------------------
46 : 0 : ORowSetValue OOp_Ascii::operate(const ORowSetValue& lhs) const
47 : : {
48 : : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OOp_Ascii::operate" );
49 [ # # ]: 0 : if ( lhs.isNull() )
50 [ # # ]: 0 : return lhs;
51 [ # # ][ # # ]: 0 : ::rtl::OString sStr(::rtl::OUStringToOString(lhs,RTL_TEXTENCODING_ASCII_US));
52 : 0 : sal_Int32 nAscii = sStr.toChar();
53 [ # # ]: 0 : return nAscii;
54 : : }
55 : : //------------------------------------------------------------------
56 : 0 : ORowSetValue OOp_CharLength::operate(const ORowSetValue& lhs) const
57 : : {
58 : : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OOp_CharLength::operate" );
59 [ # # ]: 0 : if ( lhs.isNull() )
60 : 0 : return lhs;
61 : :
62 [ # # ]: 0 : return lhs.getString().getLength();
63 : : }
64 : : //------------------------------------------------------------------
65 : 0 : ORowSetValue OOp_Char::operate(const ::std::vector<ORowSetValue>& lhs) const
66 : : {
67 : : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OOp_Char::operate" );
68 [ # # ]: 0 : if ( lhs.empty() )
69 : 0 : return ORowSetValue();
70 : :
71 : 0 : ::rtl::OUString sRet;
72 : 0 : ::std::vector<ORowSetValue>::const_reverse_iterator aIter = lhs.rbegin();
73 : 0 : ::std::vector<ORowSetValue>::const_reverse_iterator aEnd = lhs.rend();
74 [ # # ][ # # ]: 0 : for (; aIter != aEnd; ++aIter)
[ # # ]
75 : : {
76 [ # # ][ # # ]: 0 : if ( !aIter->isNull() )
77 : : {
78 [ # # ][ # # ]: 0 : sal_Char c = static_cast<sal_Char>(static_cast<sal_Int32>(*aIter));
79 : :
80 [ # # ]: 0 : sRet += ::rtl::OUString(&c,1,RTL_TEXTENCODING_ASCII_US);
81 : : }
82 : : }
83 : :
84 [ # # ]: 0 : return sRet;
85 : : }
86 : : //------------------------------------------------------------------
87 : 0 : ORowSetValue OOp_Concat::operate(const ::std::vector<ORowSetValue>& lhs) const
88 : : {
89 : : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OOp_Concat::operate" );
90 [ # # ]: 0 : if ( lhs.empty() )
91 : 0 : return ORowSetValue();
92 : :
93 : 0 : ::rtl::OUStringBuffer sRet;
94 : 0 : ::std::vector<ORowSetValue>::const_reverse_iterator aIter = lhs.rbegin();
95 : 0 : ::std::vector<ORowSetValue>::const_reverse_iterator aEnd = lhs.rend();
96 [ # # ][ # # ]: 0 : for (; aIter != aEnd; ++aIter)
[ # # ]
97 : : {
98 [ # # ][ # # ]: 0 : if ( aIter->isNull() )
99 : 0 : return ORowSetValue();
100 : :
101 [ # # ][ # # ]: 0 : sRet.append(aIter->operator ::rtl::OUString());
[ # # ]
102 : : }
103 : :
104 [ # # ][ # # ]: 0 : return sRet.makeStringAndClear();
105 : : }
106 : : //------------------------------------------------------------------
107 : 0 : ORowSetValue OOp_Locate::operate(const ::std::vector<ORowSetValue>& lhs) const
108 : : {
109 : : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OOp_Locate::operate" );
110 : 0 : ::std::vector<ORowSetValue>::const_iterator aIter = lhs.begin();
111 : 0 : ::std::vector<ORowSetValue>::const_iterator aEnd = lhs.end();
112 [ # # ][ # # ]: 0 : for (; aIter != aEnd; ++aIter)
[ # # ]
113 : : {
114 [ # # ][ # # ]: 0 : if ( aIter->isNull() )
115 : 0 : return ORowSetValue();
116 : : }
117 [ # # ]: 0 : if ( lhs.size() == 2 )
118 [ # # ][ # # ]: 0 : return ::rtl::OUString::valueOf(lhs[0].getString().indexOf(lhs[1].getString())+1);
[ # # ][ # # ]
[ # # ]
119 : :
120 [ # # ]: 0 : else if ( lhs.size() != 3 )
121 : 0 : return ORowSetValue();
122 : :
123 [ # # ][ # # ]: 0 : return lhs[1].getString().indexOf(lhs[2].getString(),lhs[0]) + 1;
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
124 : : }
125 : : //------------------------------------------------------------------
126 : 0 : ORowSetValue OOp_SubString::operate(const ::std::vector<ORowSetValue>& lhs) const
127 : : {
128 : : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OOp_SubString::operate" );
129 : 0 : ::std::vector<ORowSetValue>::const_iterator aIter = lhs.begin();
130 : 0 : ::std::vector<ORowSetValue>::const_iterator aEnd = lhs.end();
131 [ # # ][ # # ]: 0 : for (; aIter != aEnd; ++aIter)
[ # # ]
132 : : {
133 [ # # ][ # # ]: 0 : if ( aIter->isNull() )
134 : 0 : return ORowSetValue();
135 : : }
136 [ # # ][ # # ]: 0 : if ( lhs.size() == 2 && static_cast<sal_Int32>(lhs[0]) >= sal_Int32(0) )
[ # # ][ # # ]
[ # # ]
137 [ # # ][ # # ]: 0 : return lhs[1].getString().copy(static_cast<sal_Int32>(lhs[0])-1);
[ # # ][ # # ]
[ # # ]
138 : :
139 [ # # ][ # # ]: 0 : else if ( lhs.size() != 3 || static_cast<sal_Int32>(lhs[1]) < sal_Int32(0))
[ # # ][ # # ]
[ # # ]
140 : 0 : return ORowSetValue();
141 : :
142 [ # # ][ # # ]: 0 : return lhs[2].getString().copy(static_cast<sal_Int32>(lhs[1])-1,lhs[0]);
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
143 : : }
144 : : //------------------------------------------------------------------
145 : 0 : ORowSetValue OOp_LTrim::operate(const ORowSetValue& lhs) const
146 : : {
147 : : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OOp_LTrim::operate" );
148 [ # # ]: 0 : if ( lhs.isNull() )
149 [ # # ]: 0 : return lhs;
150 : :
151 [ # # ]: 0 : ::rtl::OUString sRet = lhs;
152 : 0 : ::rtl::OUString sNew = sRet.trim();
153 [ # # ]: 0 : return sRet.copy(sRet.indexOf(sNew));
154 : : }
155 : : //------------------------------------------------------------------
156 : 0 : ORowSetValue OOp_RTrim::operate(const ORowSetValue& lhs) const
157 : : {
158 : : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OOp_RTrim::operate" );
159 [ # # ]: 0 : if ( lhs.isNull() )
160 [ # # ]: 0 : return lhs;
161 : :
162 [ # # ]: 0 : ::rtl::OUString sRet = lhs;
163 : 0 : ::rtl::OUString sNew = sRet.trim();
164 [ # # ]: 0 : return sRet.copy(0,sRet.lastIndexOf(sNew.getStr()[sNew.getLength()-1])+1);
165 : : }
166 : : //------------------------------------------------------------------
167 : 0 : ORowSetValue OOp_Space::operate(const ORowSetValue& lhs) const
168 : : {
169 : : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OOp_Space::operate" );
170 [ # # ]: 0 : if ( lhs.isNull() )
171 [ # # ]: 0 : return lhs;
172 : :
173 : 0 : const sal_Char c = ' ';
174 : 0 : ::rtl::OUStringBuffer sRet;
175 [ # # ]: 0 : sal_Int32 nCount = lhs;
176 [ # # ]: 0 : for (sal_Int32 i=0; i < nCount; ++i)
177 : : {
178 [ # # ]: 0 : sRet.appendAscii(&c,1);
179 : : }
180 [ # # ][ # # ]: 0 : return sRet.makeStringAndClear();
181 : : }
182 : : //------------------------------------------------------------------
183 : 0 : ORowSetValue OOp_Replace::operate(const ::std::vector<ORowSetValue>& lhs) const
184 : : {
185 : : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OOp_Replace::operate" );
186 [ # # ]: 0 : if ( lhs.size() != 3 )
187 : 0 : return ORowSetValue();
188 : :
189 [ # # ][ # # ]: 0 : ::rtl::OUString sStr = lhs[2];
190 [ # # ][ # # ]: 0 : ::rtl::OUString sFrom = lhs[1];
191 [ # # ][ # # ]: 0 : ::rtl::OUString sTo = lhs[0];
192 : 0 : sal_Int32 nIndexOf = sStr.indexOf(sFrom);
193 [ # # ]: 0 : while( nIndexOf != -1 )
194 : : {
195 : 0 : sStr = sStr.replaceAt(nIndexOf,sFrom.getLength(),sTo);
196 : 0 : nIndexOf = sStr.indexOf(sFrom,nIndexOf + sTo.getLength());
197 : : }
198 : :
199 [ # # ]: 0 : return sStr;
200 : : }
201 : : //------------------------------------------------------------------
202 : 0 : ORowSetValue OOp_Repeat::operate(const ORowSetValue& lhs,const ORowSetValue& rhs) const
203 : : {
204 : : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OOp_Repeat::operate" );
205 [ # # ][ # # ]: 0 : if ( lhs.isNull() || rhs.isNull() )
[ # # ]
206 [ # # ]: 0 : return lhs;
207 : :
208 : 0 : ::rtl::OUString sRet;
209 [ # # ]: 0 : sal_Int32 nCount = rhs;
210 [ # # ]: 0 : for (sal_Int32 i=0; i < nCount; ++i)
211 : : {
212 [ # # ]: 0 : sRet += lhs;
213 : : }
214 [ # # ]: 0 : return sRet;
215 : : }
216 : : //------------------------------------------------------------------
217 : 0 : ORowSetValue OOp_Insert::operate(const ::std::vector<ORowSetValue>& lhs) const
218 : : {
219 : : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OOp_Insert::operate" );
220 [ # # ]: 0 : if ( lhs.size() != 4 )
221 : 0 : return ORowSetValue();
222 : :
223 [ # # ][ # # ]: 0 : ::rtl::OUString sStr = lhs[3];
224 : :
225 [ # # ][ # # ]: 0 : sal_Int32 nStart = static_cast<sal_Int32>(lhs[2]);
226 [ # # ]: 0 : if ( nStart < 1 )
227 : 0 : nStart = 1;
228 [ # # ][ # # ]: 0 : return sStr.replaceAt(nStart-1,static_cast<sal_Int32>(lhs[1]),lhs[0]);
[ # # ][ # # ]
[ # # ]
229 : : }
230 : : //------------------------------------------------------------------
231 : 0 : ORowSetValue OOp_Left::operate(const ORowSetValue& lhs,const ORowSetValue& rhs) const
232 : : {
233 : : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OOp_Left::operate" );
234 [ # # ][ # # ]: 0 : if ( lhs.isNull() || rhs.isNull() )
[ # # ]
235 [ # # ]: 0 : return lhs;
236 : :
237 [ # # ]: 0 : ::rtl::OUString sRet = lhs;
238 [ # # ]: 0 : sal_Int32 nCount = rhs;
239 [ # # ]: 0 : if ( nCount < 0 )
240 : 0 : return ORowSetValue();
241 [ # # ]: 0 : return sRet.copy(0,nCount);
242 : : }
243 : : //------------------------------------------------------------------
244 : 0 : ORowSetValue OOp_Right::operate(const ORowSetValue& lhs,const ORowSetValue& rhs) const
245 : : {
246 : : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OOp_Right::operate" );
247 [ # # ][ # # ]: 0 : if ( lhs.isNull() || rhs.isNull() )
[ # # ]
248 [ # # ]: 0 : return lhs;
249 : :
250 [ # # ]: 0 : sal_Int32 nCount = rhs;
251 [ # # ]: 0 : ::rtl::OUString sRet = lhs;
252 [ # # ][ # # ]: 0 : if ( nCount < 0 || nCount >= sRet.getLength() )
[ # # ]
253 : 0 : return ORowSetValue();
254 : :
255 [ # # ]: 0 : return sRet.copy(sRet.getLength()-nCount,nCount);
256 : : }
257 : :
258 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|