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 "reportformula.hxx"
22 #include <rtl/ustrbuf.hxx>
24 //........................................................................
27 //........................................................................
29 using ::com::sun::star::uno::Any
;
33 //----------------------------------------------------------------
34 const OUString
& lcl_getExpressionPrefix( sal_Int32
* _pTakeLengthOrNull
= NULL
)
36 static OUString
s_sPrefix( "rpt:" );
37 if ( _pTakeLengthOrNull
)
38 *_pTakeLengthOrNull
= s_sPrefix
.getLength();
42 //----------------------------------------------------------------
43 const OUString
& lcl_getFieldPrefix( sal_Int32
* _pTakeLengthOrNull
= NULL
)
45 static OUString
s_sPrefix( "field:" );
46 if ( _pTakeLengthOrNull
)
47 *_pTakeLengthOrNull
= s_sPrefix
.getLength();
52 //====================================================================
54 //====================================================================
55 //--------------------------------------------------------------------
56 ReportFormula::ReportFormula( const OUString
& _rFormula
)
59 impl_construct( _rFormula
);
62 //--------------------------------------------------------------------
63 ReportFormula::ReportFormula( const BindType _eType
, const OUString
& _rFieldOrExpression
)
70 if ( _rFieldOrExpression
.indexOf( lcl_getExpressionPrefix() ) == 0 )
71 m_sCompleteFormula
= _rFieldOrExpression
;
73 m_sCompleteFormula
= lcl_getExpressionPrefix() + _rFieldOrExpression
;
79 OUStringBuffer aBuffer
;
80 aBuffer
.append( lcl_getFieldPrefix() );
81 aBuffer
.appendAscii( "[" );
82 aBuffer
.append( _rFieldOrExpression
);
83 aBuffer
.appendAscii( "]" );
84 m_sCompleteFormula
= aBuffer
.makeStringAndClear();
88 OSL_FAIL( "ReportFormula::ReportFormula: illegal bind type!" );
92 m_sUndecoratedContent
= _rFieldOrExpression
;
94 //--------------------------------------------------------------------
95 ReportFormula::~ReportFormula()
98 //--------------------------------------------------------------------
99 void ReportFormula::impl_construct( const OUString
& _rFormula
)
101 m_sCompleteFormula
= _rFormula
;
103 sal_Int32
nPrefixLen( -1 );
104 // is it an ordinary expression?
105 if ( m_sCompleteFormula
.indexOf( lcl_getExpressionPrefix( &nPrefixLen
) ) == 0 )
107 m_eType
= Expression
;
108 m_sUndecoratedContent
= m_sCompleteFormula
.copy( nPrefixLen
);
112 /// does it refer to a field?
113 if ( m_sCompleteFormula
.indexOf( lcl_getFieldPrefix( &nPrefixLen
) ) == 0 )
115 if ( ( m_sCompleteFormula
.getLength() >= nPrefixLen
+ 2 )
116 && ( m_sCompleteFormula
[ nPrefixLen
] == '[' )
117 && ( m_sCompleteFormula
[ m_sCompleteFormula
.getLength() - 1 ] == ']' )
121 m_sUndecoratedContent
= m_sCompleteFormula
.copy( nPrefixLen
+ 1, m_sCompleteFormula
.getLength() - nPrefixLen
- 2 );
129 //--------------------------------------------------------------------
130 OUString
ReportFormula::getBracketedFieldOrExpression() const
132 bool bIsField
= ( getType() == Field
);
133 OUStringBuffer aFieldContent
;
135 aFieldContent
.appendAscii( "[" );
136 aFieldContent
.append( getUndecoratedContent() );
138 aFieldContent
.appendAscii( "]" );
140 return aFieldContent
.makeStringAndClear();
142 //--------------------------------------------------------------------
143 const OUString
& ReportFormula::getUndecoratedContent() const
145 return m_sUndecoratedContent
;
147 const OUString
& ReportFormula::getCompleteFormula() const { return m_sCompleteFormula
; }
148 bool ReportFormula::isValid() const { return getType() != Invalid
; }
149 ReportFormula
& ReportFormula::operator=(class ReportFormula
const & _rHd
)
153 m_eType
= _rHd
.m_eType
;
154 m_sCompleteFormula
= _rHd
.m_sCompleteFormula
;
155 m_sUndecoratedContent
= _rHd
.m_sUndecoratedContent
;
158 //--------------------------------------------------------------------
159 OUString
ReportFormula::getEqualUndecoratedContent() const
161 OUStringBuffer aBuffer
;
162 aBuffer
.appendAscii( "=" );
163 aBuffer
.append( getUndecoratedContent() );
164 return aBuffer
.makeStringAndClear();
167 //........................................................................
169 //........................................................................
171 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */