Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #include "reportformula.hxx"
30 : :
31 : : #include <rtl/ustrbuf.hxx>
32 : :
33 : : //........................................................................
34 : : namespace rptui
35 : : {
36 : : //........................................................................
37 : :
38 : : /** === begin UNO using === **/
39 : : using ::com::sun::star::uno::Any;
40 : : /** === end UNO using === **/
41 : :
42 : : namespace
43 : : {
44 : : //----------------------------------------------------------------
45 : 0 : const ::rtl::OUString& lcl_getExpressionPrefix( sal_Int32* _pTakeLengthOrNull = NULL )
46 : : {
47 [ # # ][ # # ]: 0 : static ::rtl::OUString s_sPrefix( RTL_CONSTASCII_USTRINGPARAM( "rpt:" ) );
[ # # ][ # # ]
48 [ # # ]: 0 : if ( _pTakeLengthOrNull )
49 : 0 : *_pTakeLengthOrNull = s_sPrefix.getLength();
50 : 0 : return s_sPrefix;
51 : : }
52 : :
53 : : //----------------------------------------------------------------
54 : 0 : const ::rtl::OUString& lcl_getFieldPrefix( sal_Int32* _pTakeLengthOrNull = NULL )
55 : : {
56 [ # # ][ # # ]: 0 : static ::rtl::OUString s_sPrefix( RTL_CONSTASCII_USTRINGPARAM( "field:" ) );
[ # # ][ # # ]
57 [ # # ]: 0 : if ( _pTakeLengthOrNull )
58 : 0 : *_pTakeLengthOrNull = s_sPrefix.getLength();
59 : 0 : return s_sPrefix;
60 : : }
61 : : }
62 : :
63 : : //====================================================================
64 : : //= ReportFormula
65 : : //====================================================================
66 : : //--------------------------------------------------------------------
67 : 0 : ReportFormula::ReportFormula( const ::rtl::OUString& _rFormula )
68 : 0 : :m_eType( Invalid )
69 : : {
70 [ # # ]: 0 : impl_construct( _rFormula );
71 : 0 : }
72 : :
73 : : //--------------------------------------------------------------------
74 : 0 : ReportFormula::ReportFormula( const BindType _eType, const ::rtl::OUString& _rFieldOrExpression )
75 : 0 : :m_eType( _eType )
76 : : {
77 [ # # # ]: 0 : switch ( m_eType )
78 : : {
79 : : case Expression:
80 : : {
81 [ # # ][ # # ]: 0 : if ( _rFieldOrExpression.indexOf( lcl_getExpressionPrefix() ) == 0 )
82 : 0 : m_sCompleteFormula = _rFieldOrExpression;
83 : : else
84 [ # # ]: 0 : m_sCompleteFormula = lcl_getExpressionPrefix() + _rFieldOrExpression;
85 : : }
86 : 0 : break;
87 : :
88 : : case Field:
89 : : {
90 : 0 : ::rtl::OUStringBuffer aBuffer;
91 [ # # ][ # # ]: 0 : aBuffer.append( lcl_getFieldPrefix() );
92 [ # # ]: 0 : aBuffer.appendAscii( "[" );
93 [ # # ]: 0 : aBuffer.append( _rFieldOrExpression );
94 [ # # ]: 0 : aBuffer.appendAscii( "]" );
95 [ # # ]: 0 : m_sCompleteFormula = aBuffer.makeStringAndClear();
96 : : }
97 : 0 : break;
98 : : default:
99 : : OSL_FAIL( "ReportFormula::ReportFormula: illegal bind type!" );
100 : 0 : return;
101 : : }
102 : :
103 : 0 : m_sUndecoratedContent = _rFieldOrExpression;
104 : : }
105 : : //--------------------------------------------------------------------
106 : 0 : ReportFormula::~ReportFormula()
107 : : {
108 : 0 : }
109 : : //--------------------------------------------------------------------
110 : 0 : void ReportFormula::impl_construct( const ::rtl::OUString& _rFormula )
111 : : {
112 : 0 : m_sCompleteFormula = _rFormula;
113 : :
114 : 0 : sal_Int32 nPrefixLen( -1 );
115 : : // is it an ordinary expression?
116 [ # # ][ # # ]: 0 : if ( m_sCompleteFormula.indexOf( lcl_getExpressionPrefix( &nPrefixLen ) ) == 0 )
117 : : {
118 : 0 : m_eType = Expression;
119 : 0 : m_sUndecoratedContent = m_sCompleteFormula.copy( nPrefixLen );
120 : : return;
121 : : }
122 : :
123 : : /// does it refer to a field?
124 [ # # ][ # # ]: 0 : if ( m_sCompleteFormula.indexOf( lcl_getFieldPrefix( &nPrefixLen ) ) == 0 )
125 : : {
126 [ # # # # : 0 : if ( ( m_sCompleteFormula.getLength() >= nPrefixLen + 2 )
# # ][ # # ]
127 : 0 : && ( m_sCompleteFormula[ nPrefixLen ] == '[' )
128 : 0 : && ( m_sCompleteFormula[ m_sCompleteFormula.getLength() - 1 ] == ']' )
129 : : )
130 : : {
131 : 0 : m_eType = Field;
132 : 0 : m_sUndecoratedContent = m_sCompleteFormula.copy( nPrefixLen + 1, m_sCompleteFormula.getLength() - nPrefixLen - 2 );
133 : : return;
134 : : }
135 : : }
136 : :
137 : 0 : m_eType = Invalid;
138 : : }
139 : :
140 : : //--------------------------------------------------------------------
141 : 0 : ::rtl::OUString ReportFormula::getBracketedFieldOrExpression() const
142 : : {
143 : 0 : bool bIsField = ( getType() == Field );
144 : 0 : ::rtl::OUStringBuffer aFieldContent;
145 [ # # ]: 0 : if ( bIsField )
146 [ # # ]: 0 : aFieldContent.appendAscii( "[" );
147 [ # # ][ # # ]: 0 : aFieldContent.append( getUndecoratedContent() );
148 [ # # ]: 0 : if ( bIsField )
149 [ # # ]: 0 : aFieldContent.appendAscii( "]" );
150 : :
151 [ # # ]: 0 : return aFieldContent.makeStringAndClear();
152 : : }
153 : : //--------------------------------------------------------------------
154 : 0 : const ::rtl::OUString& ReportFormula::getUndecoratedContent() const
155 : : {
156 : 0 : return m_sUndecoratedContent;
157 : : }
158 : 0 : const ::rtl::OUString& ReportFormula::getCompleteFormula() const { return m_sCompleteFormula; }
159 : 0 : bool ReportFormula::isValid() const { return getType() != Invalid; }
160 : 0 : ReportFormula& ReportFormula::operator=(class ReportFormula const & _rHd)
161 : : {
162 [ # # ]: 0 : if ( this == &_rHd )
163 : 0 : return *this;
164 : 0 : m_eType = _rHd.m_eType;
165 : 0 : m_sCompleteFormula = _rHd.m_sCompleteFormula;
166 : 0 : m_sUndecoratedContent = _rHd.m_sUndecoratedContent;
167 : 0 : return *this;
168 : : }
169 : : //--------------------------------------------------------------------
170 : 0 : ::rtl::OUString ReportFormula::getEqualUndecoratedContent() const
171 : : {
172 : 0 : ::rtl::OUStringBuffer aBuffer;
173 [ # # ]: 0 : aBuffer.appendAscii( "=" );
174 [ # # ][ # # ]: 0 : aBuffer.append( getUndecoratedContent() );
175 [ # # ]: 0 : return aBuffer.makeStringAndClear();
176 : : }
177 : :
178 : : //........................................................................
179 : : } // namespace rptui
180 : : //........................................................................
181 : :
182 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|