tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / reportdesign / source / core / misc / reportformula.cxx
blob5b90647374adce4ed82e3c8d4693713f70660207
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 const char sExpressionPrefix[] = "rpt:";
31 const char sFieldPrefix[] = "field:";
35 //= ReportFormula
38 ReportFormula::ReportFormula( const OUString& _rFormula )
39 :m_eType( Invalid )
41 m_sCompleteFormula = _rFormula;
43 // is it an ordinary expression?
44 if ( m_sCompleteFormula.startsWith( sExpressionPrefix, &m_sUndecoratedContent ) )
46 m_eType = Expression;
47 return;
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 ] == ']' )
59 m_eType = Field;
60 m_sUndecoratedContent = m_sCompleteFormula.copy( nPrefixLen + 1, m_sCompleteFormula.getLength() - nPrefixLen - 2 );
61 return;
67 ReportFormula::ReportFormula( const BindType _eType, const OUString& _rFieldOrExpression )
68 :m_eType( _eType )
70 switch ( m_eType )
72 case Expression:
74 if ( _rFieldOrExpression.startsWith( sExpressionPrefix ) )
75 m_sCompleteFormula = _rFieldOrExpression;
76 else
77 m_sCompleteFormula = sExpressionPrefix + _rFieldOrExpression;
79 break;
81 case Field:
83 m_sCompleteFormula = sFieldPrefix + OUString::Concat(u"[") + _rFieldOrExpression + "]";
85 break;
86 default:
87 OSL_FAIL( "ReportFormula::ReportFormula: illegal bind type!" );
88 return;
91 m_sUndecoratedContent = _rFieldOrExpression;
94 ReportFormula::~ReportFormula()
98 OUString ReportFormula::getBracketedFieldOrExpression() const
100 bool bIsField = ( getType() == Field );
101 OUStringBuffer aFieldContent;
102 if ( bIsField )
103 aFieldContent.append( "[" );
104 aFieldContent.append( getUndecoratedContent() );
105 if ( bIsField )
106 aFieldContent.append( "]" );
108 return aFieldContent.makeStringAndClear();
111 bool ReportFormula::isValid() const { return getType() != Invalid; }
113 OUString ReportFormula::getEqualUndecoratedContent() const
115 return "=" + getUndecoratedContent();
119 } // namespace rptui
122 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */