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 .
23 #include <bastype.hxx>
25 #include <globals.hxx>
27 #include <database.hxx>
28 #include <osl/diagnose.h>
30 static bool ReadRangeSvIdl( SvStringHashEntry
* pName
, SvTokenStream
& rInStm
,
31 sal_uLong nMin
, sal_uLong nMax
, sal_uLong
* pValue
)
33 sal_uInt32 nTokPos
= rInStm
.Tell();
34 SvToken
* pTok
= rInStm
.GetToken_Next();
35 if( pTok
->Is( pName
) )
38 if( rInStm
.Read( '=' ) )
40 pTok
= rInStm
.GetToken_Next();
41 if( pTok
->IsInteger() )
43 sal_uLong n
= pTok
->GetNumber();
44 if ( n
>= nMin
&& n
<= nMax
)
56 rInStm
.Seek( nTokPos
);
60 SvStream
& WriteSvBOOL(SvStream
& rStm
, const SvBOOL
& rb
)
62 sal_uInt8 n
= int(rb
.nVal
);
68 SvStream
& operator >> (SvStream
& rStm
, SvBOOL
& rb
)
72 rb
.nVal
= (n
& 0x01) != 0;
73 rb
.bSet
= (n
& 0x02) != 0;
76 rStm
.SetError( SVSTREAM_FILEFORMAT_ERROR
);
77 OSL_FAIL( "format error" );
82 SvStream
& WriteSvVersion(SvStream
& rStm
, const SvVersion
& r
)
84 if( (r
.GetMajorVersion() || r
.GetMinorVersion())
85 && r
.GetMajorVersion() <= 0x0F && r
.GetMinorVersion() <= 0x0F )
86 { // compress version number in 1 byte
87 // format first 4 bit for major, then 4 bit for minor
88 // 0.0 gets not compressed
90 int n
= r
.GetMajorVersion() << 4;
91 n
|= r
.GetMinorVersion();
97 rStm
.WriteUInt16( r
.GetMajorVersion() );
98 rStm
.WriteUInt16( r
.GetMinorVersion() );
103 SvStream
& operator >> (SvStream
& rStm
, SvVersion
& r
)
109 rStm
.ReadUInt16( r
.nMajorVersion
);
110 rStm
.ReadUInt16( r
.nMinorVersion
);
114 r
.nMajorVersion
= (n
>> 4) & 0x0F;
115 r
.nMinorVersion
= n
& 0x0F;
121 bool SvBOOL::ReadSvIdl( SvStringHashEntry
* pName
, SvTokenStream
& rInStm
)
123 sal_uInt32 nTokPos
= rInStm
.Tell();
124 SvToken
* pTok
= rInStm
.GetToken_Next();
126 if( pTok
->Is( pName
) )
129 bool bBraket
= rInStm
.Read( '(' );
130 if( bBraket
|| rInStm
.Read( '=' ) )
132 pTok
= rInStm
.GetToken();
135 *this = pTok
->GetBool();
137 rInStm
.GetToken_Next();
140 bOk
= rInStm
.Read( ')' );
143 *this = true; //default action set to TRUE
147 rInStm
.Seek( nTokPos
);
151 bool SvIdentifier::ReadSvIdl( SvStringHashEntry
* pName
, SvTokenStream
& rInStm
)
153 sal_uInt32 nTokPos
= rInStm
.Tell();
154 SvToken
* pTok
= rInStm
.GetToken_Next();
156 if( pTok
->Is( pName
) )
159 bool bBraket
= rInStm
.Read( '(' );
160 if( bBraket
|| rInStm
.Read( '=' ) )
162 pTok
= rInStm
.GetToken();
163 if( pTok
->IsIdentifier() )
165 setString(pTok
->GetString());
166 rInStm
.GetToken_Next();
169 bOk
= rInStm
.Read( ')' );
174 rInStm
.Seek( nTokPos
);
178 bool SvNumberIdentifier::ReadSvIdl( SvIdlDataBase
& rBase
,
179 SvStringHashEntry
* pName
,
180 SvTokenStream
& rInStm
)
182 if( SvIdentifier::ReadSvIdl( pName
, rInStm
) )
185 if( rBase
.FindId( getString(), &n
) )
192 OStringBuffer
aStr("no value for identifier <");
193 aStr
.append(getString()).append("> ");
194 rBase
.SetError( aStr
.makeStringAndClear(), rInStm
.GetToken() );
195 rBase
.WriteError( rInStm
);
201 bool SvNumberIdentifier::ReadSvIdl( SvIdlDataBase
& rBase
,
202 SvTokenStream
& rInStm
)
204 sal_uInt32 nTokPos
= rInStm
.Tell();
205 SvToken
* pTok
= rInStm
.GetToken_Next();
207 if( pTok
->IsIdentifier() )
210 if( rBase
.FindId( pTok
->GetString(), &n
) )
212 setString(pTok
->GetString());
218 OStringBuffer
aStr("no value for identifier <");
219 aStr
.append(getString()).append("> ");
220 rBase
.SetError( aStr
.makeStringAndClear(), rInStm
.GetToken() );
221 rBase
.WriteError( rInStm
);
224 rInStm
.Seek( nTokPos
);
228 bool SvString::ReadSvIdl( SvStringHashEntry
* pName
, SvTokenStream
& rInStm
)
230 sal_uInt32 nTokPos
= rInStm
.Tell();
231 SvToken
* pTok
= rInStm
.GetToken_Next();
233 if( pTok
->Is( pName
) )
236 bool bBraket
= rInStm
.Read( '(' );
237 if( bBraket
|| rInStm
.Read( '=' ) )
239 pTok
= rInStm
.GetToken();
240 if( pTok
->IsString() )
242 setString(pTok
->GetString());
243 rInStm
.GetToken_Next();
246 bOk
= rInStm
.Read( ')' );
251 rInStm
.Seek( nTokPos
);
255 SvStream
& WriteSvString(SvStream
& rStm
, const SvString
& r
)
257 write_uInt16_lenPrefixed_uInt8s_FromOString(rStm
, r
.getString());
261 SvStream
& operator >> (SvStream
& rStm
, SvString
& r
)
263 r
.setString(read_uInt16_lenPrefixed_uInt8s_ToOString(rStm
));
268 bool SvHelpText::ReadSvIdl( SvIdlDataBase
&, SvTokenStream
& rInStm
)
270 return SvString::ReadSvIdl( SvHash_HelpText(), rInStm
);
273 bool SvUUId::ReadSvIdl( SvIdlDataBase
&, SvTokenStream
& rInStm
)
275 sal_uInt32 nTokPos
= rInStm
.Tell();
276 SvToken
* pTok
= rInStm
.GetToken_Next();
278 if( pTok
->Is( SvHash_uuid() ) )
281 bool bBraket
= rInStm
.Read( '(' );
282 if( bBraket
|| rInStm
.Read( '=' ) )
284 pTok
= rInStm
.GetToken();
285 if( pTok
->IsString() )
287 pTok
= rInStm
.GetToken_Next();
288 bOk
= MakeId(OStringToOUString(pTok
->GetString(), RTL_TEXTENCODING_ASCII_US
));
291 bOk
= rInStm
.Read( ')' );
296 rInStm
.Seek( nTokPos
);
300 bool SvVersion::ReadSvIdl( SvTokenStream
& rInStm
)
304 sal_uInt32 nTokPos
= rInStm
.Tell();
305 if( ReadRangeSvIdl( SvHash_Version(), rInStm
, 0 , 0xFFFF, &n
) )
307 nMajorVersion
= (sal_uInt16
)n
;
308 if( rInStm
.Read( '.' ) )
310 SvToken
* pTok
= rInStm
.GetToken_Next();
311 if( pTok
->IsInteger() && pTok
->GetNumber() <= 0xFFFF )
313 nMinorVersion
= (sal_uInt16
)pTok
->GetNumber();
320 rInStm
.Seek( nTokPos
);
324 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */