LCOV - code coverage report
Current view: top level - libreoffice/reportdesign/source/core/misc - reportformula.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 70 0.0 %
Date: 2012-12-27 Functions: 0 12 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             : #include "reportformula.hxx"
      21             : 
      22             : #include <rtl/ustrbuf.hxx>
      23             : 
      24             : //........................................................................
      25             : namespace rptui
      26             : {
      27             : //........................................................................
      28             : 
      29             :     /** === begin UNO using === **/
      30             :     using ::com::sun::star::uno::Any;
      31             :     /** === end UNO using === **/
      32             : 
      33             :     namespace
      34             :     {
      35             :         //----------------------------------------------------------------
      36           0 :         const ::rtl::OUString&  lcl_getExpressionPrefix( sal_Int32* _pTakeLengthOrNull = NULL )
      37             :         {
      38           0 :             static ::rtl::OUString s_sPrefix( RTL_CONSTASCII_USTRINGPARAM( "rpt:" ) );
      39           0 :             if ( _pTakeLengthOrNull )
      40           0 :                 *_pTakeLengthOrNull = s_sPrefix.getLength();
      41           0 :             return s_sPrefix;
      42             :         }
      43             : 
      44             :         //----------------------------------------------------------------
      45           0 :         const ::rtl::OUString&  lcl_getFieldPrefix( sal_Int32* _pTakeLengthOrNull = NULL )
      46             :         {
      47           0 :             static ::rtl::OUString s_sPrefix( RTL_CONSTASCII_USTRINGPARAM( "field:" ) );
      48           0 :             if ( _pTakeLengthOrNull )
      49           0 :                 *_pTakeLengthOrNull = s_sPrefix.getLength();
      50           0 :             return s_sPrefix;
      51             :         }
      52             :     }
      53             : 
      54             :     //====================================================================
      55             :     //= ReportFormula
      56             :     //====================================================================
      57             :     //--------------------------------------------------------------------
      58           0 :     ReportFormula::ReportFormula( const ::rtl::OUString& _rFormula )
      59           0 :         :m_eType( Invalid )
      60             :     {
      61           0 :         impl_construct( _rFormula );
      62           0 :     }
      63             : 
      64             :     //--------------------------------------------------------------------
      65           0 :     ReportFormula::ReportFormula( const BindType _eType, const ::rtl::OUString& _rFieldOrExpression )
      66           0 :         :m_eType( _eType )
      67             :     {
      68           0 :         switch ( m_eType )
      69             :         {
      70             :         case Expression:
      71             :         {
      72           0 :             if ( _rFieldOrExpression.indexOf( lcl_getExpressionPrefix() ) == 0 )
      73           0 :                 m_sCompleteFormula = _rFieldOrExpression;
      74             :             else
      75           0 :                 m_sCompleteFormula = lcl_getExpressionPrefix() + _rFieldOrExpression;
      76             :         }
      77           0 :         break;
      78             : 
      79             :         case Field:
      80             :         {
      81           0 :             ::rtl::OUStringBuffer aBuffer;
      82           0 :             aBuffer.append( lcl_getFieldPrefix() );
      83           0 :             aBuffer.appendAscii( "[" );
      84           0 :             aBuffer.append( _rFieldOrExpression );
      85           0 :             aBuffer.appendAscii( "]" );
      86           0 :             m_sCompleteFormula = aBuffer.makeStringAndClear();
      87             :         }
      88           0 :         break;
      89             :         default:
      90             :             OSL_FAIL( "ReportFormula::ReportFormula: illegal bind type!" );
      91           0 :             return;
      92             :         }
      93             : 
      94           0 :         m_sUndecoratedContent = _rFieldOrExpression;
      95             :     }
      96             :     //--------------------------------------------------------------------
      97           0 :     ReportFormula::~ReportFormula()
      98             :     {
      99           0 :     }
     100             :     //--------------------------------------------------------------------
     101           0 :     void ReportFormula::impl_construct( const ::rtl::OUString& _rFormula )
     102             :     {
     103           0 :         m_sCompleteFormula = _rFormula;
     104             : 
     105           0 :         sal_Int32 nPrefixLen( -1 );
     106             :         // is it an ordinary expression?
     107           0 :         if ( m_sCompleteFormula.indexOf( lcl_getExpressionPrefix( &nPrefixLen ) ) == 0 )
     108             :         {
     109           0 :             m_eType = Expression;
     110           0 :             m_sUndecoratedContent = m_sCompleteFormula.copy( nPrefixLen );
     111             :             return;
     112             :         }
     113             : 
     114             :         /// does it refer to a field?
     115           0 :         if ( m_sCompleteFormula.indexOf( lcl_getFieldPrefix( &nPrefixLen ) ) == 0 )
     116             :         {
     117           0 :             if  (   ( m_sCompleteFormula.getLength() >= nPrefixLen + 2 )
     118           0 :                 &&  ( m_sCompleteFormula[ nPrefixLen ] == '[' )
     119           0 :                 &&  ( m_sCompleteFormula[ m_sCompleteFormula.getLength() - 1 ] == ']' )
     120             :                 )
     121             :             {
     122           0 :                 m_eType = Field;
     123           0 :                 m_sUndecoratedContent = m_sCompleteFormula.copy( nPrefixLen + 1, m_sCompleteFormula.getLength() - nPrefixLen - 2 );
     124             :                 return;
     125             :             }
     126             :         }
     127             : 
     128           0 :         m_eType = Invalid;
     129             :     }
     130             : 
     131             :     //--------------------------------------------------------------------
     132           0 :     ::rtl::OUString ReportFormula::getBracketedFieldOrExpression() const
     133             :     {
     134           0 :         bool bIsField = ( getType() == Field );
     135           0 :         ::rtl::OUStringBuffer aFieldContent;
     136           0 :         if ( bIsField )
     137           0 :             aFieldContent.appendAscii( "[" );
     138           0 :         aFieldContent.append( getUndecoratedContent() );
     139           0 :         if ( bIsField )
     140           0 :             aFieldContent.appendAscii( "]" );
     141             : 
     142           0 :         return aFieldContent.makeStringAndClear();
     143             :     }
     144             :     //--------------------------------------------------------------------
     145           0 :     const ::rtl::OUString& ReportFormula::getUndecoratedContent() const
     146             :     {
     147           0 :         return m_sUndecoratedContent;
     148             :     }
     149           0 :     const ::rtl::OUString&  ReportFormula::getCompleteFormula() const { return m_sCompleteFormula; }
     150           0 :     bool                    ReportFormula::isValid() const { return getType() != Invalid; }
     151           0 :     ReportFormula& ReportFormula::operator=(class ReportFormula const & _rHd)
     152             :     {
     153           0 :         if ( this == &_rHd )
     154           0 :             return *this;
     155           0 :         m_eType                 = _rHd.m_eType;
     156           0 :         m_sCompleteFormula      = _rHd.m_sCompleteFormula;
     157           0 :         m_sUndecoratedContent   = _rHd.m_sUndecoratedContent;
     158           0 :         return *this;
     159             :     }
     160             :     //--------------------------------------------------------------------
     161           0 :     ::rtl::OUString ReportFormula::getEqualUndecoratedContent() const
     162             :     {
     163           0 :         ::rtl::OUStringBuffer aBuffer;
     164           0 :         aBuffer.appendAscii( "=" );
     165           0 :         aBuffer.append( getUndecoratedContent() );
     166           0 :         return aBuffer.makeStringAndClear();
     167             :     }
     168             : 
     169             : //........................................................................
     170             : } // namespace rptui
     171             : //........................................................................
     172             : 
     173             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10