merge the formfield patch from ooo-build
[ooovba.git] / autodoc / source / parser / cpp / defdescr.cxx
blobae9284aa35a52d7d6b240bb3451097436f615467
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: defdescr.cxx,v $
10 * $Revision: 1.6.18.1 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #include <precomp.h>
32 #include "defdescr.hxx"
35 // NOT FULLY DEFINED SERVICES
36 #include <prprpr.hxx>
41 namespace cpp
47 DefineDescription::DefineDescription( const String & i_sName,
48 const str_vector & i_rDefinition )
49 : sName(i_sName),
50 // aParams,
51 aDefinition(i_rDefinition),
52 eDefineType(type_define)
56 DefineDescription::DefineDescription( const String & i_sName,
57 const str_vector & i_rParams,
58 const str_vector & i_rDefinition )
59 : sName(i_sName),
60 aParams(i_rParams),
61 aDefinition(i_rDefinition),
62 eDefineType(type_macro)
66 DefineDescription::~DefineDescription()
70 void
71 DefineDescription::GetDefineText( csv::StreamStr & o_rText ) const
73 if ( aDefinition.begin() == aDefinition.end() OR eDefineType != type_define )
74 return;
77 bool bSwitch_Stringify = false;
78 bool bSwitch_Concatenate = false;
80 for ( str_vector::const_iterator it = aDefinition.begin();
81 it != aDefinition.end();
82 ++it )
84 if ( HandleOperatorsBeforeTextItem( o_rText,
85 bSwitch_Stringify,
86 bSwitch_Concatenate,
87 *it ) )
89 continue;
92 o_rText << (*it);
94 Do_bStringify_end(o_rText, bSwitch_Stringify);
95 o_rText << " ";
97 o_rText.seekp(-1, csv::cur);
100 void
101 DefineDescription::GetMacroText( csv::StreamStr & o_rText,
102 const StringVector & i_rGivenArguments ) const
104 bool bSwitch_Stringify = false;
105 bool bSwitch_Concatenate = false;
106 intt nActiveParamNr = -1;
108 if ( aDefinition.begin() == aDefinition.end() OR eDefineType != type_macro )
109 return;
111 for ( str_vector::const_iterator it = aDefinition.begin();
112 it != aDefinition.end();
113 ++it )
115 if ( HandleOperatorsBeforeTextItem( o_rText,
116 bSwitch_Stringify,
117 bSwitch_Concatenate,
118 *it ) )
120 continue;
123 for ( str_vector::const_iterator param_it = aParams.begin();
124 param_it != aParams.end() AND nActiveParamNr == -1;
125 ++param_it )
127 if ( strcmp(*it, *param_it) == 0 )
128 nActiveParamNr = param_it - aParams.begin();
130 if ( nActiveParamNr == -1 )
132 o_rText << (*it);
134 else
136 o_rText << i_rGivenArguments[nActiveParamNr];
137 nActiveParamNr = -1;
140 Do_bStringify_end(o_rText, bSwitch_Stringify);
141 o_rText << " ";
143 o_rText.seekp(-1, csv::cur);
148 } // end namespace cpp
154 bool
155 CheckForOperator( bool & o_bStringify,
156 bool & o_bConcatenate,
157 const String & i_sTextItem )
159 if ( strcmp(i_sTextItem, "##") == 0 )
161 o_bConcatenate = true;
162 return true;
164 else if ( strcmp(i_sTextItem, "#") == 0 )
166 o_bStringify = true;
167 return true;
169 return false;
172 void
173 Do_bConcatenate( csv::StreamStr & o_rText,
174 bool & io_bConcatenate )
176 if ( io_bConcatenate )
178 uintt nPos;
179 for ( nPos = o_rText.tellp() - 1;
180 nPos > 0 ? o_rText.c_str()[nPos] == ' ' : false;
181 --nPos ) ;
182 o_rText.seekp(nPos+1);
183 io_bConcatenate = false;
187 void
188 Do_bStringify_begin( csv::StreamStr & o_rText,
189 bool i_bStringify )
191 if ( i_bStringify )
193 o_rText << "\"";
197 void
198 Do_bStringify_end( csv::StreamStr & o_rText,
199 bool & io_bStringify )
201 if ( io_bStringify )
203 o_rText << "\"";
204 io_bStringify = false;
209 bool
210 HandleOperatorsBeforeTextItem( csv::StreamStr & o_rText,
211 bool & io_bStringify,
212 bool & io_bConcatenate,
213 const String & i_sTextItem )
215 if ( CheckForOperator( io_bStringify,
216 io_bConcatenate,
217 i_sTextItem) )
219 return true;
221 Do_bConcatenate(o_rText, io_bConcatenate);
222 Do_bStringify_begin(o_rText, io_bStringify);
224 return false;