LCOV - code coverage report
Current view: top level - connectivity/source/drivers/file - FStringFunctions.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 0 126 0.0 %
Date: 2015-06-13 12:38:46 Functions: 0 16 0.0 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.11