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>
30 const char sExpressionPrefix
[] = "rpt:";
31 const char sFieldPrefix
[] = "field:";
38 ReportFormula::ReportFormula( const OUString
& _rFormula
)
41 m_sCompleteFormula
= _rFormula
;
43 // is it an ordinary expression?
44 if ( m_sCompleteFormula
.startsWith( sExpressionPrefix
, &m_sUndecoratedContent
) )
50 /// does it refer to a field?
51 if ( m_sCompleteFormula
.startsWith( sFieldPrefix
) )
53 sal_Int32 nPrefixLen
= strlen(sFieldPrefix
);
54 if ( ( m_sCompleteFormula
.getLength() >= nPrefixLen
+ 2 )
55 && ( m_sCompleteFormula
[ nPrefixLen
] == '[' )
56 && ( m_sCompleteFormula
[ m_sCompleteFormula
.getLength() - 1 ] == ']' )
60 m_sUndecoratedContent
= m_sCompleteFormula
.copy( nPrefixLen
+ 1, m_sCompleteFormula
.getLength() - nPrefixLen
- 2 );
67 ReportFormula::ReportFormula( const BindType _eType
, const OUString
& _rFieldOrExpression
)
74 if ( _rFieldOrExpression
.startsWith( sExpressionPrefix
) )
75 m_sCompleteFormula
= _rFieldOrExpression
;
77 m_sCompleteFormula
= sExpressionPrefix
+ _rFieldOrExpression
;
83 m_sCompleteFormula
= sFieldPrefix
+ OUString::Concat(u
"[") + _rFieldOrExpression
+ "]";
87 OSL_FAIL( "ReportFormula::ReportFormula: illegal bind type!" );
91 m_sUndecoratedContent
= _rFieldOrExpression
;
94 ReportFormula::~ReportFormula()
98 OUString
ReportFormula::getBracketedFieldOrExpression() const
100 bool bIsField
= ( getType() == Field
);
101 OUStringBuffer aFieldContent
;
103 aFieldContent
.append( "[" );
104 aFieldContent
.append( getUndecoratedContent() );
106 aFieldContent
.append( "]" );
108 return aFieldContent
.makeStringAndClear();
111 bool ReportFormula::isValid() const { return getType() != Invalid
; }
113 OUString
ReportFormula::getEqualUndecoratedContent() const
115 return "=" + getUndecoratedContent();
122 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */