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 .
28 #include <rtl/textcvt.h>
29 #include <rtl/textenc.h>
31 RscString::RscString( Atom nId
, sal_uInt32 nTypeId
)
32 : RscTop( nId
, nTypeId
)
34 nSize
= ALIGNED_SIZE( sizeof( RscStringInst
) );
38 RSCCLASS_TYPE
RscString::GetClassType() const
40 return RSCCLASS_STRING
;
43 ERRTYPE
RscString::SetString( const RSCINST
& rInst
, const char * pStr
)
50 reinterpret_cast<RscStringInst
*>(rInst
.pData
)->bDflt
= false;
52 pTmp
= reinterpret_cast<RscStringInst
*>(rInst
.pData
)->pStr
;
55 rtl_freeMemory( pTmp
);
61 sal_uInt32 nLen
= strlen( pStr
) +1;
62 pTmp
= static_cast<char *>(rtl_allocateMemory( nLen
));
63 memcpy( pTmp
, pStr
, nLen
);
66 reinterpret_cast<RscStringInst
*>(rInst
.pData
)->pStr
= pTmp
;
72 ERRTYPE
RscString::GetString( const RSCINST
& rInst
, char ** ppStr
)
74 *ppStr
= reinterpret_cast<RscStringInst
*>(rInst
.pData
)->pStr
;
78 ERRTYPE
RscString::GetRef( const RSCINST
& rInst
, RscId
* pRscId
)
80 *pRscId
= reinterpret_cast<RscStringInst
*>(rInst
.pData
)->aRefId
;
84 ERRTYPE
RscString::SetRef( const RSCINST
& rInst
, const RscId
& rRefId
)
88 reinterpret_cast<RscStringInst
*>(rInst
.pData
)->aRefId
= rRefId
;
89 reinterpret_cast<RscStringInst
*>(rInst
.pData
)->bDflt
= false;
92 return ERR_REFNOTALLOWED
;
97 RSCINST
RscString::Create( RSCINST
* pInst
, const RSCINST
& rDflt
,
105 aInst
.pData
= static_cast<CLASS_DATA
>(
106 rtl_allocateMemory( sizeof( RscStringInst
) ));
111 if( !bOwnClass
&& rDflt
.IsInst() )
112 bOwnClass
= rDflt
.pClass
->InHierarchy( this );
114 reinterpret_cast<RscStringInst
*>(aInst
.pData
)->aRefId
.Create();
115 reinterpret_cast<RscStringInst
*>(aInst
.pData
)->pStr
= NULL
;
116 reinterpret_cast<RscStringInst
*>(aInst
.pData
)->bDflt
= true;
120 reinterpret_cast<RscStringInst
*>(aInst
.pData
)->aRefId
=
121 reinterpret_cast<RscStringInst
*>(rDflt
.pData
)->aRefId
;
122 SetString( aInst
, reinterpret_cast<RscStringInst
*>(rDflt
.pData
)->pStr
);
123 reinterpret_cast<RscStringInst
*>(aInst
.pData
)->bDflt
=
124 reinterpret_cast<RscStringInst
*>(rDflt
.pData
)->bDflt
;
130 void RscString::Destroy( const RSCINST
& rInst
)
132 if( reinterpret_cast<RscStringInst
*>(rInst
.pData
)->pStr
)
133 rtl_freeMemory( reinterpret_cast<RscStringInst
*>(rInst
.pData
)->pStr
);
134 reinterpret_cast<RscStringInst
*>(rInst
.pData
)->aRefId
.Destroy();
137 bool RscString::IsValueDefault( const RSCINST
& rInst
, CLASS_DATA pDef
)
139 RscStringInst
* pData
= reinterpret_cast<RscStringInst
*>(rInst
.pData
);
140 RscStringInst
* pDefData
= reinterpret_cast<RscStringInst
*>(pDef
);
144 if( pData
->aRefId
.IsId() || pDefData
->aRefId
.IsId() )
146 if( pData
->aRefId
.aExp
.IsNumber() &&
147 pDefData
->aRefId
.aExp
.IsNumber() )
149 // Sind die Referenzidentifier gleich
150 if( pData
->aRefId
.GetNumber() == pDefData
->aRefId
.GetNumber() )
158 bool bStrEmpty
= false;
159 bool bDefStrEmpty
= false;
163 bStrEmpty
= ('\0' == *pData
->pStr
);
170 bDefStrEmpty
= ('\0' == *pDefData
->pStr
);
175 if( !bStrEmpty
|| !bDefStrEmpty
)
186 void RscString::WriteSrc( const RSCINST
& rInst
, FILE * fOutput
,
187 RscTypCont
*, sal_uInt32
, const char * )
189 if ( reinterpret_cast<RscStringInst
*>(rInst
.pData
)->aRefId
.IsId() )
191 fprintf( fOutput
, "%s",
192 reinterpret_cast<RscStringInst
*>(rInst
.pData
)->aRefId
.GetName().getStr() );
196 RscStringInst
* pStrI
= reinterpret_cast<RscStringInst
*>(rInst
.pData
);
198 //char * pChangeTab = RscChar::GetChangeTab();
200 sal_uInt32 nPos
, nSlashPos
;
204 fputc( '\"', fOutput
);
205 nSlashPos
= nPos
= 0;
207 while( pStrI
->pStr
[ n
] && (nPos
< 72 || nPos
- nSlashPos
<= 3) )
208 { // nach \ mindesten 3 Zeichen wegeb \xa7
209 fputc( pStrI
->pStr
[ n
], fOutput
);
210 if( pStrI
->pStr
[ n
] == '\\' )
216 fputc( '\"', fOutput
);
217 if( pStrI
->pStr
[ n
] ) //nocht nicht zu ende
219 fputc( '\n', fOutput
);
222 while( pStrI
->pStr
[ n
] );
225 fprintf( fOutput
, "\"\"" );
229 ERRTYPE
RscString::WriteRc( const RSCINST
& rInst
, RscWriteRc
& rMem
,
230 RscTypCont
* pTC
, sal_uInt32 nDeep
, bool bExtra
)
233 ObjNode
* pObjNode
= NULL
;
236 if( reinterpret_cast<RscStringInst
*>(rInst
.pData
)->aRefId
.IsId() )
238 RscId
aId( reinterpret_cast<RscStringInst
*>(rInst
.pData
)->aRefId
);
241 aTmpI
.pClass
= pRefClass
;
243 while( aError
.IsOk() && aId
.IsId() )
245 //Erhoehen und abfragen um Endlosrekusion zu vermeiden
247 if( nDeep
> nRefDeep
)
248 aError
= ERR_REFTODEEP
;
251 pObjNode
= pRefClass
->GetObjNode( aId
);
254 aTmpI
.pData
= pObjNode
->GetRscObj();
255 aError
= pRefClass
->GetRef( aTmpI
, &aId
);
261 OStringBuffer
aMsg(pHS
->getString(
262 pRefClass
->GetId()));
263 aMsg
.append(' ').append(aId
.GetName());
264 aError
= WRN_STR_REFNOTFOUND
;
265 pTC
->pEH
->Error( aError
, rInst
.pClass
,
266 RscId(), aMsg
.getStr() );
280 aRefI
= RSCINST( pRefClass
, pObjNode
->GetRscObj() );
281 aError
= aRefI
.pClass
->WriteRc( aRefI
, rMem
, pTC
, nDeep
, bExtra
);
285 if( reinterpret_cast<RscStringInst
*>(rInst
.pData
)->pStr
&& pTC
)
287 char * pStr
= RscChar::MakeUTF8( reinterpret_cast<RscStringInst
*>(rInst
.pData
)->pStr
,
288 pTC
->GetSourceCharSet() );
289 rMem
.PutUTF8( pStr
);
290 rtl_freeMemory( pStr
);
293 rMem
.PutUTF8( reinterpret_cast<RscStringInst
*>(rInst
.pData
)->pStr
);
299 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */