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>
29 using ::com::sun::star::uno::Any
;
34 static const char sExpressionPrefix
[] = "rpt:";
35 static const char sFieldPrefix
[] = "field:";
42 ReportFormula::ReportFormula( const OUString
& _rFormula
)
45 impl_construct( _rFormula
);
49 ReportFormula::ReportFormula( const BindType _eType
, const OUString
& _rFieldOrExpression
)
56 if ( _rFieldOrExpression
.startsWith( sExpressionPrefix
) )
57 m_sCompleteFormula
= _rFieldOrExpression
;
59 m_sCompleteFormula
= sExpressionPrefix
+ _rFieldOrExpression
;
65 OUStringBuffer aBuffer
;
66 aBuffer
.append( sFieldPrefix
);
67 aBuffer
.appendAscii( "[" );
68 aBuffer
.append( _rFieldOrExpression
);
69 aBuffer
.appendAscii( "]" );
70 m_sCompleteFormula
= aBuffer
.makeStringAndClear();
74 OSL_FAIL( "ReportFormula::ReportFormula: illegal bind type!" );
78 m_sUndecoratedContent
= _rFieldOrExpression
;
81 ReportFormula::~ReportFormula()
85 void ReportFormula::impl_construct( const OUString
& _rFormula
)
87 m_sCompleteFormula
= _rFormula
;
89 // is it an ordinary expression?
90 if ( m_sCompleteFormula
.startsWith( sExpressionPrefix
) )
92 sal_Int32 nPrefixLen
= strlen(sExpressionPrefix
);
94 m_sUndecoratedContent
= m_sCompleteFormula
.copy( nPrefixLen
);
98 /// does it refer to a field?
99 if ( m_sCompleteFormula
.startsWith( sFieldPrefix
) )
101 sal_Int32 nPrefixLen
= strlen(sFieldPrefix
);
102 if ( ( m_sCompleteFormula
.getLength() >= nPrefixLen
+ 2 )
103 && ( m_sCompleteFormula
[ nPrefixLen
] == '[' )
104 && ( m_sCompleteFormula
[ m_sCompleteFormula
.getLength() - 1 ] == ']' )
108 m_sUndecoratedContent
= m_sCompleteFormula
.copy( nPrefixLen
+ 1, m_sCompleteFormula
.getLength() - nPrefixLen
- 2 );
117 OUString
ReportFormula::getBracketedFieldOrExpression() const
119 bool bIsField
= ( getType() == Field
);
120 OUStringBuffer aFieldContent
;
122 aFieldContent
.appendAscii( "[" );
123 aFieldContent
.append( getUndecoratedContent() );
125 aFieldContent
.appendAscii( "]" );
127 return aFieldContent
.makeStringAndClear();
130 bool ReportFormula::isValid() const { return getType() != Invalid
; }
131 ReportFormula
& ReportFormula::operator=(class ReportFormula
const & _rHd
)
135 m_eType
= _rHd
.m_eType
;
136 m_sCompleteFormula
= _rHd
.m_sCompleteFormula
;
137 m_sUndecoratedContent
= _rHd
.m_sUndecoratedContent
;
141 OUString
ReportFormula::getEqualUndecoratedContent() const
143 OUStringBuffer aBuffer
;
144 aBuffer
.appendAscii( "=" );
145 aBuffer
.append( getUndecoratedContent() );
146 return aBuffer
.makeStringAndClear();
153 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */