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
){
48 ((RscStringInst
*)rInst
.pData
)->bDflt
= sal_False
;
50 pTmp
= ((RscStringInst
*)rInst
.pData
)->pStr
;
52 rtl_freeMemory( pTmp
);
57 sal_uInt32 nLen
= strlen( pStr
) +1;
58 pTmp
= (char *)rtl_allocateMemory( nLen
);
59 memcpy( pTmp
, pStr
, nLen
);
62 ((RscStringInst
*)rInst
.pData
)->pStr
= pTmp
;
68 ERRTYPE
RscString::GetString( const RSCINST
& rInst
, char ** ppStr
){
69 *ppStr
= ((RscStringInst
*)rInst
.pData
)->pStr
;
73 ERRTYPE
RscString::GetRef( const RSCINST
& rInst
, RscId
* pRscId
){
74 *pRscId
= ((RscStringInst
*)rInst
.pData
)->aRefId
;
78 ERRTYPE
RscString::SetRef( const RSCINST
& rInst
, const RscId
& rRefId
){
80 ((RscStringInst
*)rInst
.pData
)->aRefId
= rRefId
;
81 ((RscStringInst
*)rInst
.pData
)->bDflt
= sal_False
;
84 return( ERR_REFNOTALLOWED
);
89 RSCINST
RscString::Create( RSCINST
* pInst
, const RSCINST
& rDflt
,
96 aInst
.pData
= (CLASS_DATA
)
97 rtl_allocateMemory( sizeof( RscStringInst
) );
101 if( !bOwnClass
&& rDflt
.IsInst() )
102 bOwnClass
= rDflt
.pClass
->InHierarchy( this );
104 ((RscStringInst
*)aInst
.pData
)->aRefId
.Create();
105 ((RscStringInst
*)aInst
.pData
)->pStr
= NULL
;
106 ((RscStringInst
*)aInst
.pData
)->bDflt
= sal_True
;
109 ((RscStringInst
*)aInst
.pData
)->aRefId
=
110 ((RscStringInst
*)rDflt
.pData
)->aRefId
;
111 SetString( aInst
, ((RscStringInst
*)rDflt
.pData
)->pStr
);
112 ((RscStringInst
*)aInst
.pData
)->bDflt
=
113 ((RscStringInst
*)rDflt
.pData
)->bDflt
;
119 void RscString::Destroy( const RSCINST
& rInst
){
120 if( ((RscStringInst
*)rInst
.pData
)->pStr
)
121 rtl_freeMemory( ((RscStringInst
*)rInst
.pData
)->pStr
);
122 ((RscStringInst
*)rInst
.pData
)->aRefId
.Destroy();
125 sal_Bool
RscString::IsValueDefault( const RSCINST
& rInst
, CLASS_DATA pDef
){
126 RscStringInst
* pData
= (RscStringInst
*)rInst
.pData
;
127 RscStringInst
* pDefData
= (RscStringInst
*)pDef
;
130 if( pData
->aRefId
.IsId() || pDefData
->aRefId
.IsId() )
132 if( pData
->aRefId
.aExp
.IsNumber()
133 && pDefData
->aRefId
.aExp
.IsNumber() )
135 // Sind die Referenzidentifier gleich
136 if( pData
->aRefId
.GetNumber() == pDefData
->aRefId
.GetNumber() )
143 sal_Bool bStrEmpty
= sal_False
;
144 sal_Bool bDefStrEmpty
= sal_False
;
147 bStrEmpty
= ('\0' == *pData
->pStr
);
150 bStrEmpty
= sal_True
;
152 if( pDefData
->pStr
){
153 bDefStrEmpty
= ('\0' == *pDefData
->pStr
);
156 bDefStrEmpty
= sal_True
;
158 if( !bStrEmpty
|| !bDefStrEmpty
){
168 void RscString::WriteSrc( const RSCINST
& rInst
, FILE * fOutput
,
169 RscTypCont
*, sal_uInt32
, const char * )
171 if ( ((RscStringInst
*)rInst
.pData
)->aRefId
.IsId() )
173 fprintf( fOutput
, "%s",
174 ((RscStringInst
*)rInst
.pData
)->aRefId
.GetName().getStr() );
178 RscStringInst
* pStrI
= ((RscStringInst
*)rInst
.pData
);
180 //char * pChangeTab = RscChar::GetChangeTab();
182 sal_uInt32 nPos
, nSlashPos
;
185 fputc( '\"', fOutput
);
186 nSlashPos
= nPos
= 0;
187 while( pStrI
->pStr
[ n
]
188 && (nPos
< 72 || nPos
- nSlashPos
<= 3) )
189 { // nach \ mindesten 3 Zeichen wegeb \xa7
190 fputc( pStrI
->pStr
[ n
], fOutput
);
191 if( pStrI
->pStr
[ n
] == '\\' )
197 fputc( '\"', fOutput
);
198 if( pStrI
->pStr
[ n
] ) //nocht nicht zu ende
199 fputc( '\n', fOutput
);
200 } while( pStrI
->pStr
[ n
] );
203 fprintf( fOutput
, "\"\"" );
207 ERRTYPE
RscString::WriteRc( const RSCINST
& rInst
, RscWriteRc
& rMem
,
208 RscTypCont
* pTC
, sal_uInt32 nDeep
, sal_Bool bExtra
)
211 ObjNode
* pObjNode
= NULL
;
214 if( ((RscStringInst
*)rInst
.pData
)->aRefId
.IsId() ){
215 RscId
aId( ((RscStringInst
*)rInst
.pData
)->aRefId
);
218 aTmpI
.pClass
= pRefClass
;
220 while( aError
.IsOk() && aId
.IsId() ){
221 //Erhoehen und abfragen um Endlosrekusion zu vermeiden
223 if( nDeep
> nRefDeep
)
224 aError
= ERR_REFTODEEP
;
227 pObjNode
= pRefClass
->GetObjNode( aId
);
230 aTmpI
.pData
= pObjNode
->GetRscObj();
231 aError
= pRefClass
->GetRef( aTmpI
, &aId
);
237 OStringBuffer
aMsg(pHS
->getString(
238 pRefClass
->GetId()));
239 aMsg
.append(' ').append(aId
.GetName());
240 aError
= WRN_STR_REFNOTFOUND
;
241 pTC
->pEH
->Error( aError
, rInst
.pClass
,
242 RscId(), aMsg
.getStr() );
256 aRefI
= RSCINST( pRefClass
, pObjNode
->GetRscObj() );
257 aError
= aRefI
.pClass
->WriteRc( aRefI
, rMem
, pTC
, nDeep
, bExtra
);
261 if( ((RscStringInst
*)rInst
.pData
)->pStr
&& pTC
)
263 char * pStr
= RscChar::MakeUTF8( ((RscStringInst
*)rInst
.pData
)->pStr
,
264 pTC
->GetSourceCharSet() );
265 rMem
.PutUTF8( pStr
);
266 rtl_freeMemory( pStr
);
269 rMem
.PutUTF8( ((RscStringInst
*)rInst
.pData
)->pStr
);
275 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */