bump product version to 6.3.0.0.beta1
[LibreOffice.git] / reportdesign / source / core / misc / reportformula.cxx
blobc5026a545e94e5a124cbe912a859ff2d5ddd92dd
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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>
25 namespace rptui
27 namespace
30 static const char sExpressionPrefix[] = "rpt:";
31 static const char sFieldPrefix[] = "field:";
35 //= ReportFormula
38 ReportFormula::ReportFormula( const OUString& _rFormula )
39 :m_eType( Invalid )
41 impl_construct( _rFormula );
45 ReportFormula::ReportFormula( const BindType _eType, const OUString& _rFieldOrExpression )
46 :m_eType( _eType )
48 switch ( m_eType )
50 case Expression:
52 if ( _rFieldOrExpression.startsWith( sExpressionPrefix ) )
53 m_sCompleteFormula = _rFieldOrExpression;
54 else
55 m_sCompleteFormula = sExpressionPrefix + _rFieldOrExpression;
57 break;
59 case Field:
61 OUStringBuffer aBuffer;
62 aBuffer.append( sFieldPrefix );
63 aBuffer.append( "[" );
64 aBuffer.append( _rFieldOrExpression );
65 aBuffer.append( "]" );
66 m_sCompleteFormula = aBuffer.makeStringAndClear();
68 break;
69 default:
70 OSL_FAIL( "ReportFormula::ReportFormula: illegal bind type!" );
71 return;
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 ) )
88 m_eType = Expression;
89 return;
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 ] == ']' )
101 m_eType = Field;
102 m_sUndecoratedContent = m_sCompleteFormula.copy( nPrefixLen + 1, m_sCompleteFormula.getLength() - nPrefixLen - 2 );
103 return;
107 m_eType = Invalid;
111 OUString ReportFormula::getBracketedFieldOrExpression() const
113 bool bIsField = ( getType() == Field );
114 OUStringBuffer aFieldContent;
115 if ( bIsField )
116 aFieldContent.append( "[" );
117 aFieldContent.append( getUndecoratedContent() );
118 if ( bIsField )
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();
135 } // namespace rptui
138 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */