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 static const char sExpressionPrefix
[] = "rpt:";
31 static const char sFieldPrefix
[] = "field:";
38 ReportFormula::ReportFormula( const OUString
& _rFormula
)
41 impl_construct( _rFormula
);
45 ReportFormula::ReportFormula( const BindType _eType
, const OUString
& _rFieldOrExpression
)
52 if ( _rFieldOrExpression
.startsWith( sExpressionPrefix
) )
53 m_sCompleteFormula
= _rFieldOrExpression
;
55 m_sCompleteFormula
= sExpressionPrefix
+ _rFieldOrExpression
;
61 OUStringBuffer aBuffer
;
62 aBuffer
.append( sFieldPrefix
);
63 aBuffer
.append( "[" );
64 aBuffer
.append( _rFieldOrExpression
);
65 aBuffer
.append( "]" );
66 m_sCompleteFormula
= aBuffer
.makeStringAndClear();
70 OSL_FAIL( "ReportFormula::ReportFormula: illegal bind type!" );
74 m_sUndecoratedContent
= _rFieldOrExpression
;
77 ReportFormula::~ReportFormula()
81 void ReportFormula::impl_construct( const OUString
& _rFormula
)
83 m_sCompleteFormula
= _rFormula
;
85 // is it an ordinary expression?
86 if ( m_sCompleteFormula
.startsWith( sExpressionPrefix
, &m_sUndecoratedContent
) )
92 /// does it refer to a field?
93 if ( m_sCompleteFormula
.startsWith( sFieldPrefix
) )
95 sal_Int32 nPrefixLen
= strlen(sFieldPrefix
);
96 if ( ( m_sCompleteFormula
.getLength() >= nPrefixLen
+ 2 )
97 && ( m_sCompleteFormula
[ nPrefixLen
] == '[' )
98 && ( m_sCompleteFormula
[ m_sCompleteFormula
.getLength() - 1 ] == ']' )
102 m_sUndecoratedContent
= m_sCompleteFormula
.copy( nPrefixLen
+ 1, m_sCompleteFormula
.getLength() - nPrefixLen
- 2 );
111 OUString
ReportFormula::getBracketedFieldOrExpression() const
113 bool bIsField
= ( getType() == Field
);
114 OUStringBuffer aFieldContent
;
116 aFieldContent
.append( "[" );
117 aFieldContent
.append( getUndecoratedContent() );
119 aFieldContent
.append( "]" );
121 return aFieldContent
.makeStringAndClear();
124 bool ReportFormula::isValid() const { return getType() != Invalid
; }
126 OUString
ReportFormula::getEqualUndecoratedContent() const
128 OUStringBuffer aBuffer
;
129 aBuffer
.append( "=" );
130 aBuffer
.append( getUndecoratedContent() );
131 return aBuffer
.makeStringAndClear();
138 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */