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 .
20 #include <file/FStringFunctions.hxx>
21 #include <rtl/ustrbuf.hxx>
23 using namespace connectivity
;
24 using namespace connectivity::file
;
26 ORowSetValue
OOp_Upper::operate(const ORowSetValue
& lhs
) const
31 return lhs
.getString().toAsciiUpperCase();
34 ORowSetValue
OOp_Lower::operate(const ORowSetValue
& lhs
) const
39 return lhs
.getString().toAsciiLowerCase();
42 ORowSetValue
OOp_Ascii::operate(const ORowSetValue
& lhs
) const
46 OString
sStr(OUStringToOString(lhs
, RTL_TEXTENCODING_ASCII_US
));
47 sal_Int32 nAscii
= sStr
.toChar();
51 ORowSetValue
OOp_CharLength::operate(const ORowSetValue
& lhs
) const
56 return lhs
.getString().getLength();
59 ORowSetValue
OOp_Char::operate(const std::vector
<ORowSetValue
>& lhs
) const
62 return ORowSetValue();
65 std::vector
<ORowSetValue
>::const_reverse_iterator aIter
= lhs
.rbegin();
66 std::vector
<ORowSetValue
>::const_reverse_iterator aEnd
= lhs
.rend();
67 for (; aIter
!= aEnd
; ++aIter
)
71 char c
= static_cast<char>(static_cast<sal_Int32
>(*aIter
));
73 sRet
.appendAscii(&c
, 1);
77 return sRet
.makeStringAndClear();
80 ORowSetValue
OOp_Concat::operate(const std::vector
<ORowSetValue
>& lhs
) const
83 return ORowSetValue();
86 std::vector
<ORowSetValue
>::const_reverse_iterator aIter
= lhs
.rbegin();
87 std::vector
<ORowSetValue
>::const_reverse_iterator aEnd
= lhs
.rend();
88 for (; aIter
!= aEnd
; ++aIter
)
91 return ORowSetValue();
93 sRet
.append(aIter
->operator OUString());
96 return sRet
.makeStringAndClear();
99 ORowSetValue
OOp_Locate::operate(const std::vector
<ORowSetValue
>& lhs
) const
101 if (std::any_of(lhs
.begin(), lhs
.end(),
102 [](const ORowSetValue
& rValue
) { return rValue
.isNull(); }))
103 return ORowSetValue();
106 return OUString(OUString::number(lhs
[0].getString().indexOf(lhs
[1].getString()) + 1));
108 else if (lhs
.size() != 3)
109 return ORowSetValue();
111 return lhs
[1].getString().indexOf(lhs
[2].getString(), lhs
[0]) + 1;
114 ORowSetValue
OOp_SubString::operate(const std::vector
<ORowSetValue
>& lhs
) const
116 if (std::any_of(lhs
.begin(), lhs
.end(),
117 [](const ORowSetValue
& rValue
) { return rValue
.isNull(); }))
118 return ORowSetValue();
120 if (lhs
.size() == 2 && static_cast<sal_Int32
>(lhs
[0]) >= sal_Int32(0))
121 return lhs
[1].getString().copy(static_cast<sal_Int32
>(lhs
[0]) - 1);
123 else if (lhs
.size() != 3 || static_cast<sal_Int32
>(lhs
[1]) < sal_Int32(0))
124 return ORowSetValue();
126 return lhs
[2].getString().copy(static_cast<sal_Int32
>(lhs
[1]) - 1, lhs
[0]);
129 ORowSetValue
OOp_LTrim::operate(const ORowSetValue
& lhs
) const
135 OUString sNew
= sRet
.trim();
136 return sRet
.copy(sRet
.indexOf(sNew
));
139 ORowSetValue
OOp_RTrim::operate(const ORowSetValue
& lhs
) const
145 OUString sNew
= sRet
.trim();
146 return sRet
.copy(0, sRet
.lastIndexOf(sNew
[sNew
.getLength() - 1]) + 1);
149 ORowSetValue
OOp_Space::operate(const ORowSetValue
& lhs
) const
156 sal_Int32 nCount
= lhs
;
157 for (sal_Int32 i
= 0; i
< nCount
; ++i
)
159 sRet
.appendAscii(&c
, 1);
161 return sRet
.makeStringAndClear();
164 ORowSetValue
OOp_Replace::operate(const std::vector
<ORowSetValue
>& lhs
) const
167 return ORowSetValue();
169 OUString sStr
= lhs
[2];
170 OUString sFrom
= lhs
[1];
171 OUString sTo
= lhs
[0];
172 sal_Int32 nIndexOf
= sStr
.indexOf(sFrom
);
173 while (nIndexOf
!= -1)
175 sStr
= sStr
.replaceAt(nIndexOf
, sFrom
.getLength(), sTo
);
176 nIndexOf
= sStr
.indexOf(sFrom
, nIndexOf
+ sTo
.getLength());
182 ORowSetValue
OOp_Repeat::operate(const ORowSetValue
& lhs
, const ORowSetValue
& rhs
) const
184 if (lhs
.isNull() || rhs
.isNull())
188 sal_Int32 nCount
= rhs
;
189 for (sal_Int32 i
= 0; i
< nCount
; ++i
)
191 sRet
.append(lhs
.operator OUString());
193 return sRet
.makeStringAndClear();
196 ORowSetValue
OOp_Insert::operate(const std::vector
<ORowSetValue
>& lhs
) const
199 return ORowSetValue();
201 OUString sStr
= lhs
[3];
203 sal_Int32 nStart
= static_cast<sal_Int32
>(lhs
[2]);
206 return sStr
.replaceAt(nStart
- 1, static_cast<sal_Int32
>(lhs
[1]), lhs
[0]);
209 ORowSetValue
OOp_Left::operate(const ORowSetValue
& lhs
, const ORowSetValue
& rhs
) const
211 if (lhs
.isNull() || rhs
.isNull())
215 sal_Int32 nCount
= rhs
;
217 return ORowSetValue();
218 return sRet
.copy(0, nCount
);
221 ORowSetValue
OOp_Right::operate(const ORowSetValue
& lhs
, const ORowSetValue
& rhs
) const
223 if (lhs
.isNull() || rhs
.isNull())
226 sal_Int32 nCount
= rhs
;
228 if (nCount
< 0 || nCount
>= sRet
.getLength())
229 return ORowSetValue();
231 return sRet
.copy(sRet
.getLength() - nCount
, nCount
);
234 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */