1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
21 #include "file/FStringFunctions.hxx"
22 #include <rtl/ustrbuf.hxx>
24 using namespace connectivity
;
25 using namespace connectivity::file
;
27 ORowSetValue
OOp_Upper::operate(const ORowSetValue
& lhs
) const
32 return lhs
.getString().toAsciiUpperCase();
35 ORowSetValue
OOp_Lower::operate(const ORowSetValue
& lhs
) const
40 return lhs
.getString().toAsciiLowerCase();
43 ORowSetValue
OOp_Ascii::operate(const ORowSetValue
& lhs
) const
47 OString
sStr(OUStringToOString(lhs
,RTL_TEXTENCODING_ASCII_US
));
48 sal_Int32 nAscii
= sStr
.toChar();
52 ORowSetValue
OOp_CharLength::operate(const ORowSetValue
& lhs
) const
57 return lhs
.getString().getLength();
60 ORowSetValue
OOp_Char::operate(const ::std::vector
<ORowSetValue
>& lhs
) const
63 return ORowSetValue();
66 ::std::vector
<ORowSetValue
>::const_reverse_iterator aIter
= lhs
.rbegin();
67 ::std::vector
<ORowSetValue
>::const_reverse_iterator aEnd
= lhs
.rend();
68 for (; aIter
!= aEnd
; ++aIter
)
70 if ( !aIter
->isNull() )
72 sal_Char c
= static_cast<sal_Char
>(static_cast<sal_Int32
>(*aIter
));
74 sRet
+= OUString(&c
,1,RTL_TEXTENCODING_ASCII_US
);
81 ORowSetValue
OOp_Concat::operate(const ::std::vector
<ORowSetValue
>& lhs
) const
84 return ORowSetValue();
87 ::std::vector
<ORowSetValue
>::const_reverse_iterator aIter
= lhs
.rbegin();
88 ::std::vector
<ORowSetValue
>::const_reverse_iterator aEnd
= lhs
.rend();
89 for (; aIter
!= aEnd
; ++aIter
)
91 if ( aIter
->isNull() )
92 return ORowSetValue();
94 sRet
.append(aIter
->operator OUString());
97 return sRet
.makeStringAndClear();
100 ORowSetValue
OOp_Locate::operate(const ::std::vector
<ORowSetValue
>& lhs
) const
102 ::std::vector
<ORowSetValue
>::const_iterator aIter
= lhs
.begin();
103 ::std::vector
<ORowSetValue
>::const_iterator aEnd
= lhs
.end();
104 for (; aIter
!= aEnd
; ++aIter
)
106 if ( aIter
->isNull() )
107 return ORowSetValue();
109 if ( lhs
.size() == 2 )
110 return OUString::number(lhs
[0].getString().indexOf(lhs
[1].getString())+1);
112 else if ( lhs
.size() != 3 )
113 return ORowSetValue();
115 return lhs
[1].getString().indexOf(lhs
[2].getString(),lhs
[0]) + 1;
118 ORowSetValue
OOp_SubString::operate(const ::std::vector
<ORowSetValue
>& lhs
) const
120 ::std::vector
<ORowSetValue
>::const_iterator aIter
= lhs
.begin();
121 ::std::vector
<ORowSetValue
>::const_iterator aEnd
= lhs
.end();
122 for (; aIter
!= aEnd
; ++aIter
)
124 if ( aIter
->isNull() )
125 return ORowSetValue();
127 if ( lhs
.size() == 2 && static_cast<sal_Int32
>(lhs
[0]) >= sal_Int32(0) )
128 return lhs
[1].getString().copy(static_cast<sal_Int32
>(lhs
[0])-1);
130 else if ( lhs
.size() != 3 || static_cast<sal_Int32
>(lhs
[1]) < sal_Int32(0))
131 return ORowSetValue();
133 return lhs
[2].getString().copy(static_cast<sal_Int32
>(lhs
[1])-1,lhs
[0]);
136 ORowSetValue
OOp_LTrim::operate(const ORowSetValue
& lhs
) const
142 OUString sNew
= sRet
.trim();
143 return sRet
.copy(sRet
.indexOf(sNew
));
146 ORowSetValue
OOp_RTrim::operate(const ORowSetValue
& lhs
) const
152 OUString sNew
= sRet
.trim();
153 return sRet
.copy(0,sRet
.lastIndexOf(sNew
[sNew
.getLength()-1])+1);
156 ORowSetValue
OOp_Space::operate(const ORowSetValue
& lhs
) const
161 const sal_Char c
= ' ';
163 sal_Int32 nCount
= lhs
;
164 for (sal_Int32 i
=0; i
< nCount
; ++i
)
166 sRet
.appendAscii(&c
,1);
168 return sRet
.makeStringAndClear();
171 ORowSetValue
OOp_Replace::operate(const ::std::vector
<ORowSetValue
>& lhs
) const
173 if ( lhs
.size() != 3 )
174 return ORowSetValue();
176 OUString sStr
= lhs
[2];
177 OUString sFrom
= lhs
[1];
178 OUString sTo
= lhs
[0];
179 sal_Int32 nIndexOf
= sStr
.indexOf(sFrom
);
180 while( nIndexOf
!= -1 )
182 sStr
= sStr
.replaceAt(nIndexOf
,sFrom
.getLength(),sTo
);
183 nIndexOf
= sStr
.indexOf(sFrom
,nIndexOf
+ sTo
.getLength());
189 ORowSetValue
OOp_Repeat::operate(const ORowSetValue
& lhs
,const ORowSetValue
& rhs
) const
191 if ( lhs
.isNull() || rhs
.isNull() )
195 sal_Int32 nCount
= rhs
;
196 for (sal_Int32 i
=0; i
< nCount
; ++i
)
203 ORowSetValue
OOp_Insert::operate(const ::std::vector
<ORowSetValue
>& lhs
) const
205 if ( lhs
.size() != 4 )
206 return ORowSetValue();
208 OUString sStr
= lhs
[3];
210 sal_Int32 nStart
= static_cast<sal_Int32
>(lhs
[2]);
213 return sStr
.replaceAt(nStart
-1,static_cast<sal_Int32
>(lhs
[1]),lhs
[0]);
216 ORowSetValue
OOp_Left::operate(const ORowSetValue
& lhs
,const ORowSetValue
& rhs
) const
218 if ( lhs
.isNull() || rhs
.isNull() )
222 sal_Int32 nCount
= rhs
;
224 return ORowSetValue();
225 return sRet
.copy(0,nCount
);
228 ORowSetValue
OOp_Right::operate(const ORowSetValue
& lhs
,const ORowSetValue
& rhs
) const
230 if ( lhs
.isNull() || rhs
.isNull() )
233 sal_Int32 nCount
= rhs
;
235 if ( nCount
< 0 || nCount
>= sRet
.getLength() )
236 return ORowSetValue();
238 return sRet
.copy(sRet
.getLength()-nCount
,nCount
);
241 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */