Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*
3 : : * This file is part of the LibreOffice project.
4 : : *
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/.
8 : : *
9 : : * This file incorporates work covered by the following license notice:
10 : : *
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 .
18 : : */
19 : :
20 : : // TODO: Read->RefreshBuffer-> React to changes from nBufActualLen
21 : :
22 : : #include <cstddef>
23 : :
24 : : #include <string.h>
25 : : #include <stdio.h>
26 : : #include <ctype.h> // isspace
27 : : #include <stdlib.h> // strtol, _crotl
28 : :
29 : : #include "boost/static_assert.hpp"
30 : :
31 : : #include <tools/solar.h>
32 : : #include <osl/endian.h>
33 : :
34 : : #include <comphelper/string.hxx>
35 : :
36 : : #define SWAPNIBBLES(c) \
37 : : unsigned char nSwapTmp=c; \
38 : : nSwapTmp <<= 4; \
39 : : c >>= 4; \
40 : : c |= nSwapTmp;
41 : :
42 : : #include <tools/debug.hxx>
43 : : #include <tools/stream.hxx>
44 : : #include <osl/thread.h>
45 : : #include <algorithm>
46 : :
47 : : DBG_NAME( Stream )
48 : :
49 : : // !!! Do not inline if already the operators <<,>> are inline
50 : 5511 : inline static void SwapUShort( sal_uInt16& r )
51 : 5511 : { r = OSL_SWAPWORD(r); }
52 : 8508 : inline static void SwapShort( short& r )
53 : 8508 : { r = OSL_SWAPWORD(r); }
54 : : inline static void SwapLong( long& r )
55 : : { r = OSL_SWAPDWORD(r); }
56 : 97271 : inline static void SwapULong( sal_uInt32& r )
57 : 97271 : { r = OSL_SWAPDWORD(r); }
58 : 37421 : inline static void SwapLongInt( sal_Int32& r )
59 : 37421 : { r = OSL_SWAPDWORD(r); }
60 : : inline static void SwapLongUInt( unsigned int& r )
61 : : { r = OSL_SWAPDWORD(r); }
62 : :
63 : 0 : inline static void SwapUInt64( sal_uInt64& r )
64 : : {
65 : : union
66 : : {
67 : : sal_uInt64 n;
68 : : sal_uInt32 c[2];
69 : : } s;
70 : :
71 : 0 : s.n = r;
72 : 0 : s.c[0] ^= s.c[1]; // swap the 32 bit words
73 : 0 : s.c[1] ^= s.c[0];
74 : 0 : s.c[0] ^= s.c[1];
75 : : // swap the bytes in the words
76 : 0 : s.c[0] = OSL_SWAPDWORD(s.c[0]);
77 : 0 : s.c[1] = OSL_SWAPDWORD(s.c[1]);
78 : 0 : r = s.n;
79 : 0 : }
80 : 0 : inline static void SwapInt64( sal_Int64& r )
81 : : {
82 : : union
83 : : {
84 : : sal_Int64 n;
85 : : sal_Int32 c[2];
86 : : } s;
87 : :
88 : 0 : s.n = r;
89 : 0 : s.c[0] ^= s.c[1]; // swap the 32 bit words
90 : 0 : s.c[1] ^= s.c[0];
91 : 0 : s.c[0] ^= s.c[1];
92 : : // swap the bytes in the words
93 : 0 : s.c[0] = OSL_SWAPDWORD(s.c[0]);
94 : 0 : s.c[1] = OSL_SWAPDWORD(s.c[1]);
95 : 0 : r = s.n;
96 : 0 : }
97 : :
98 : : #ifdef UNX
99 : 0 : inline static void SwapFloat( float& r )
100 : : {
101 : : union
102 : : {
103 : : float f;
104 : : sal_uInt32 c;
105 : : } s;
106 : :
107 : 0 : s.f = r;
108 : 0 : s.c = OSL_SWAPDWORD( s.c );
109 : 0 : r = s.f;
110 : 0 : }
111 : :
112 : 0 : inline static void SwapDouble( double& r )
113 : : {
114 : : if( sizeof(double) != 8 )
115 : : {
116 : : DBG_ASSERT( sal_False, "Can only swap 8-Byte-doubles\n" );
117 : : }
118 : : else
119 : : {
120 : : union
121 : : {
122 : : double d;
123 : : sal_uInt32 c[2];
124 : : } s;
125 : :
126 : 0 : s.d = r;
127 : 0 : s.c[0] ^= s.c[1]; // swap 32-bit values in situ
128 : 0 : s.c[1] ^= s.c[0];
129 : 0 : s.c[0] ^= s.c[1];
130 : 0 : s.c[0] = OSL_SWAPDWORD(s.c[0]); // swap dword itself in situ
131 : 0 : s.c[1] = OSL_SWAPDWORD(s.c[1]);
132 : 0 : r = s.d;
133 : : }
134 : 0 : }
135 : : #endif
136 : :
137 : : //SDO
138 : :
139 : : #define READNUMBER_WITHOUT_SWAP(datatype,value) \
140 : : {\
141 : : int tmp = eIOMode; \
142 : : if( (tmp == STREAM_IO_READ) && sizeof(datatype)<=nBufFree) \
143 : : {\
144 : : for (std::size_t i = 0; i < sizeof(datatype); i++)\
145 : : ((char *)&value)[i] = pBufPos[i];\
146 : : nBufActualPos += sizeof(datatype);\
147 : : pBufPos += sizeof(datatype);\
148 : : nBufFree -= sizeof(datatype);\
149 : : }\
150 : : else\
151 : : Read( (char*)&value, sizeof(datatype) );\
152 : : }
153 : :
154 : : #define WRITENUMBER_WITHOUT_SWAP(datatype,value) \
155 : : {\
156 : : int tmp = eIOMode; \
157 : : if( (tmp==STREAM_IO_WRITE) && sizeof(datatype) <= nBufFree)\
158 : : {\
159 : : for (std::size_t i = 0; i < sizeof(datatype); i++)\
160 : : pBufPos[i] = ((char *)&value)[i];\
161 : : nBufFree -= sizeof(datatype);\
162 : : nBufActualPos += sizeof(datatype);\
163 : : if( nBufActualPos > nBufActualLen )\
164 : : nBufActualLen = nBufActualPos;\
165 : : pBufPos += sizeof(datatype);\
166 : : bIsDirty = sal_True;\
167 : : }\
168 : : else\
169 : : Write( (char*)&value, sizeof(datatype) );\
170 : : }
171 : :
172 : : // class SvLockBytes
173 : :
174 : 22166 : void SvLockBytes::close()
175 : : {
176 [ - + ]: 22166 : if (m_bOwner)
177 [ # # ]: 0 : delete m_pStream;
178 : 22166 : m_pStream = 0;
179 : 22166 : }
180 : :
181 [ # # ]: 0 : TYPEINIT0(SvLockBytes);
182 : :
183 : : // virtual
184 : 2 : ErrCode SvLockBytes::ReadAt(sal_Size nPos, void * pBuffer, sal_Size nCount,
185 : : sal_Size * pRead) const
186 : : {
187 [ - + ]: 2 : if (!m_pStream)
188 : : {
189 : : OSL_FAIL("SvLockBytes::ReadAt(): Bad stream");
190 : 0 : return ERRCODE_NONE;
191 : : }
192 : :
193 : 2 : m_pStream->Seek(nPos);
194 : 2 : sal_Size nTheRead = m_pStream->Read(pBuffer, nCount);
195 [ + - ]: 2 : if (pRead)
196 : 2 : *pRead = nTheRead;
197 : 2 : return m_pStream->GetErrorCode();
198 : : }
199 : :
200 : : // virtual
201 : 0 : ErrCode SvLockBytes::WriteAt(sal_Size nPos, const void * pBuffer, sal_Size nCount,
202 : : sal_Size * pWritten)
203 : : {
204 [ # # ]: 0 : if (!m_pStream)
205 : : {
206 : : OSL_FAIL("SvLockBytes::WriteAt(): Bad stream");
207 : 0 : return ERRCODE_NONE;
208 : : }
209 : :
210 : 0 : m_pStream->Seek(nPos);
211 : 0 : sal_Size nTheWritten = m_pStream->Write(pBuffer, nCount);
212 [ # # ]: 0 : if (pWritten)
213 : 0 : *pWritten = nTheWritten;
214 : 0 : return m_pStream->GetErrorCode();
215 : : }
216 : :
217 : : // virtual
218 : 0 : ErrCode SvLockBytes::Flush() const
219 : : {
220 [ # # ]: 0 : if (!m_pStream)
221 : : {
222 : : OSL_FAIL("SvLockBytes::Flush(): Bad stream");
223 : 0 : return ERRCODE_NONE;
224 : : }
225 : :
226 : 0 : m_pStream->Flush();
227 : 0 : return m_pStream->GetErrorCode();
228 : : }
229 : :
230 : : // virtual
231 : 0 : ErrCode SvLockBytes::SetSize(sal_Size nSize)
232 : : {
233 [ # # ]: 0 : if (!m_pStream)
234 : : {
235 : : OSL_FAIL("SvLockBytes::SetSize(): Bad stream");
236 : 0 : return ERRCODE_NONE;
237 : : }
238 : :
239 : 0 : m_pStream->SetStreamSize(nSize);
240 : 0 : return m_pStream->GetErrorCode();
241 : : }
242 : :
243 : 0 : ErrCode SvLockBytes::Stat(SvLockBytesStat * pStat, SvLockBytesStatFlag) const
244 : : {
245 [ # # ]: 0 : if (!m_pStream)
246 : : {
247 : : OSL_FAIL("SvLockBytes::Stat(): Bad stream");
248 : 0 : return ERRCODE_NONE;
249 : : }
250 : :
251 [ # # ]: 0 : if (pStat)
252 : : {
253 : 0 : sal_Size nPos = m_pStream->Tell();
254 : 0 : pStat->nSize = m_pStream->Seek(STREAM_SEEK_TO_END);
255 : 0 : m_pStream->Seek(nPos);
256 : : }
257 : 0 : return ERRCODE_NONE;
258 : : }
259 : :
260 : : // class SvOpenLockBytes
261 : :
262 [ # # ][ # # ]: 0 : TYPEINIT1(SvOpenLockBytes, SvLockBytes);
263 : :
264 : : // class SvAsyncLockBytes
265 : :
266 [ # # ][ # # ]: 0 : TYPEINIT1(SvAsyncLockBytes, SvOpenLockBytes);
267 : :
268 : : // virtual
269 : 0 : ErrCode SvAsyncLockBytes::ReadAt(sal_Size nPos, void * pBuffer, sal_Size nCount,
270 : : sal_Size * pRead) const
271 : : {
272 [ # # ]: 0 : if (m_bTerminated)
273 : 0 : return SvOpenLockBytes::ReadAt(nPos, pBuffer, nCount, pRead);
274 : : else
275 : : {
276 [ # # ][ # # ]: 0 : sal_Size nTheCount = std::min(nPos < m_nSize ? m_nSize - nPos : 0, nCount);
277 : : ErrCode nError = SvOpenLockBytes::ReadAt(nPos, pBuffer, nTheCount,
278 : 0 : pRead);
279 : 0 : return !nCount || nTheCount == nCount || nError ? nError :
280 [ # # ][ # # ]: 0 : ERRCODE_IO_PENDING;
[ # # ]
281 : : }
282 : : }
283 : :
284 : : // virtual
285 : 0 : ErrCode SvAsyncLockBytes::WriteAt(sal_Size nPos, const void * pBuffer,
286 : : sal_Size nCount, sal_Size * pWritten)
287 : : {
288 [ # # ]: 0 : if (m_bTerminated)
289 : 0 : return SvOpenLockBytes::WriteAt(nPos, pBuffer, nCount, pWritten);
290 : : else
291 : : {
292 [ # # ][ # # ]: 0 : sal_Size nTheCount = std::min(nPos < m_nSize ? m_nSize - nPos : 0, nCount);
293 : : ErrCode nError = SvOpenLockBytes::WriteAt(nPos, pBuffer, nTheCount,
294 : 0 : pWritten);
295 : 0 : return !nCount || nTheCount == nCount || nError ? nError :
296 [ # # ][ # # ]: 0 : ERRCODE_IO_PENDING;
[ # # ]
297 : : }
298 : : }
299 : :
300 : : // virtual
301 : 0 : ErrCode SvAsyncLockBytes::FillAppend(const void * pBuffer, sal_Size nCount,
302 : : sal_Size * pWritten)
303 : : {
304 : : sal_Size nTheWritten;
305 : : ErrCode nError = SvOpenLockBytes::WriteAt(m_nSize, pBuffer, nCount,
306 [ # # ]: 0 : &nTheWritten);
307 [ # # ]: 0 : if (!nError)
308 : 0 : m_nSize += nTheWritten;
309 [ # # ]: 0 : if (pWritten)
310 : 0 : *pWritten = nTheWritten;
311 : 0 : return nError;
312 : : }
313 : :
314 : : // virtual
315 : 0 : sal_Size SvAsyncLockBytes::Seek(sal_Size nPos)
316 : : {
317 [ # # ]: 0 : if (nPos != STREAM_SEEK_TO_END)
318 : 0 : m_nSize = nPos;
319 : 0 : return m_nSize;
320 : : }
321 : :
322 : : // class SvStream
323 : :
324 : 58743 : sal_Size SvStream::GetData( void* pData, sal_Size nSize )
325 : : {
326 [ + - ]: 58743 : if( !GetError() )
327 : : {
328 : : DBG_ASSERT( xLockBytes.Is(), "pure virtual function" );
329 : : sal_Size nRet;
330 [ + - ]: 58743 : nError = xLockBytes->ReadAt( nActPos, pData, nSize, &nRet );
331 : 58743 : nActPos += nRet;
332 : 58743 : return nRet;
333 : : }
334 : 58743 : else return 0;
335 : : }
336 : :
337 : 7076 : sal_Size SvStream::PutData( const void* pData, sal_Size nSize )
338 : : {
339 [ + - ]: 7076 : if( !GetError() )
340 : : {
341 : : DBG_ASSERT( xLockBytes.Is(), "pure virtual function" );
342 : : sal_Size nRet;
343 [ + - ]: 7076 : nError = xLockBytes->WriteAt( nActPos, pData, nSize, &nRet );
344 : 7076 : nActPos += nRet;
345 : 7076 : return nRet;
346 : : }
347 : 7076 : else return 0;
348 : : }
349 : :
350 : 144594 : sal_Size SvStream::SeekPos( sal_Size nPos )
351 : : {
352 [ + + ][ + + ]: 144594 : if( !GetError() && nPos == STREAM_SEEK_TO_END )
[ + + ]
353 : : {
354 : : DBG_ASSERT( xLockBytes.Is(), "pure virtual function" );
355 : 27014 : SvLockBytesStat aStat;
356 [ + - ]: 27014 : xLockBytes->Stat( &aStat, SVSTATFLAG_DEFAULT );
357 : 27014 : nActPos = aStat.nSize;
358 : : }
359 : : else
360 : 117580 : nActPos = nPos;
361 : 144594 : return nActPos;
362 : : }
363 : :
364 : 23323 : void SvStream::FlushData()
365 : : {
366 [ + + ]: 23323 : if( !GetError() )
367 : : {
368 : : DBG_ASSERT( xLockBytes.Is(), "pure virtual function" );
369 : 21112 : nError = xLockBytes->Flush();
370 : : }
371 : 23323 : }
372 : :
373 : 1872 : void SvStream::SetSize( sal_Size nSize )
374 : : {
375 : : DBG_ASSERT( xLockBytes.Is(), "pure virtual function" );
376 : 1872 : nError = xLockBytes->SetSize( nSize );
377 : 1872 : }
378 : :
379 : 95068 : void SvStream::ImpInit()
380 : : {
381 : 95068 : nActPos = 0;
382 : 95068 : nCompressMode = COMPRESSMODE_NONE;
383 : 95068 : eStreamCharSet = osl_getThreadTextEncoding();
384 : 95068 : nCryptMask = 0;
385 : 95068 : bIsEof = sal_False;
386 : : #if defined UNX
387 : 95068 : eLineDelimiter = LINEEND_LF; // UNIX-Format
388 : : #else
389 : : eLineDelimiter = LINEEND_CRLF; // DOS-Format
390 : : #endif
391 : :
392 : 95068 : SetNumberFormatInt( NUMBERFORMAT_INT_LITTLEENDIAN );
393 : :
394 : 95068 : nBufFilePos = 0;
395 : 95068 : nBufActualPos = 0;
396 : 95068 : bIsDirty = sal_False;
397 : 95068 : bIsConsistent = sal_True;
398 : 95068 : bIsWritable = sal_True;
399 : :
400 : 95068 : pRWBuf = 0;
401 : 95068 : pBufPos = 0;
402 : 95068 : nBufSize = 0;
403 : 95068 : nBufActualLen = 0;
404 : 95068 : eIOMode = STREAM_IO_DONTKNOW;
405 : 95068 : nBufFree = 0;
406 : :
407 : 95068 : eStreamMode = 0;
408 : :
409 : 95068 : nVersion = 0;
410 : :
411 : 95068 : ClearError();
412 : 95068 : }
413 : :
414 : 22369 : SvStream::SvStream( SvLockBytes* pLockBytesP )
415 : : {
416 : : DBG_CTOR( Stream, NULL );
417 : :
418 [ + - ]: 22369 : ImpInit();
419 [ + - ]: 22369 : xLockBytes = pLockBytesP;
420 : : const SvStream* pStrm;
421 [ + - ]: 22369 : if( pLockBytesP ) {
422 [ + - ]: 22369 : pStrm = pLockBytesP->GetStream();
423 [ - + ]: 22369 : if( pStrm ) {
424 [ # # ]: 0 : SetError( pStrm->GetErrorCode() );
425 : : }
426 : : }
427 [ + - ]: 22369 : SetBufferSize( 256 );
428 : 22369 : }
429 : :
430 : 72699 : SvStream::SvStream()
431 : : {
432 : : DBG_CTOR( Stream, NULL );
433 : :
434 [ + - ]: 72699 : ImpInit();
435 : 72699 : }
436 : :
437 : 94179 : SvStream::~SvStream()
438 : : {
439 : : DBG_DTOR( Stream, NULL );
440 : :
441 [ + + ]: 94179 : if ( xLockBytes.Is() )
442 [ + - ]: 22164 : Flush();
443 : :
444 [ + + ]: 94179 : if( pRWBuf )
445 [ + - ]: 66657 : delete[] pRWBuf;
446 [ - + ]: 116343 : }
447 : :
448 : 0 : sal_uInt16 SvStream::IsA() const
449 : : {
450 : 0 : return (sal_uInt16)ID_STREAM;
451 : : }
452 : :
453 : 126137 : void SvStream::ClearError()
454 : : {
455 : 126137 : bIsEof = sal_False;
456 : 126137 : nError = SVSTREAM_OK;
457 : 126137 : }
458 : :
459 : 5011377 : void SvStream::SetError( sal_uInt32 nErrorCode )
460 : : {
461 [ + + ]: 5011377 : if ( nError == SVSTREAM_OK )
462 : 5011117 : nError = nErrorCode;
463 : 5011377 : }
464 : :
465 : 185175 : void SvStream::SetNumberFormatInt( sal_uInt16 nNewFormat )
466 : : {
467 : 185175 : nNumberFormatInt = nNewFormat;
468 : 185175 : bSwap = sal_False;
469 : : #ifdef OSL_BIGENDIAN
470 : : if( nNumberFormatInt == NUMBERFORMAT_INT_LITTLEENDIAN )
471 : : bSwap = sal_True;
472 : : #else
473 [ + + ]: 185175 : if( nNumberFormatInt == NUMBERFORMAT_INT_BIGENDIAN )
474 : 9596 : bSwap = sal_True;
475 : : #endif
476 : 185175 : }
477 : :
478 : 110823 : void SvStream::SetBufferSize( sal_uInt16 nBufferSize )
479 : : {
480 : 110823 : sal_Size nActualFilePos = Tell();
481 : 110823 : sal_Bool bDontSeek = (sal_Bool)(pRWBuf == 0);
482 : :
483 [ + - ][ + - ]: 110823 : if( bIsDirty && bIsConsistent && bIsWritable ) // due to Windows NT: Access denied
[ + + ]
484 : 18 : Flush();
485 : :
486 [ + + ]: 110823 : if( nBufSize )
487 : : {
488 [ + - ]: 25706 : delete[] pRWBuf;
489 : 25706 : nBufFilePos += nBufActualPos;
490 : : }
491 : :
492 : 110823 : pRWBuf = 0;
493 : 110823 : nBufActualLen = 0;
494 : 110823 : nBufActualPos = 0;
495 : 110823 : nBufSize = nBufferSize;
496 [ + + ]: 110823 : if( nBufSize )
497 : 93252 : pRWBuf = new sal_uInt8[ nBufSize ];
498 : 110823 : bIsConsistent = sal_True;
499 : 110823 : pBufPos = pRWBuf;
500 : 110823 : eIOMode = STREAM_IO_DONTKNOW;
501 [ + + ]: 110823 : if( !bDontSeek )
502 : 25706 : SeekPos( nActualFilePos );
503 : 110823 : }
504 : :
505 : 12363 : void SvStream::ClearBuffer()
506 : : {
507 : 12363 : nBufActualLen = 0;
508 : 12363 : nBufActualPos = 0;
509 : 12363 : nBufFilePos = 0;
510 : 12363 : pBufPos = pRWBuf;
511 : 12363 : bIsDirty = sal_False;
512 : 12363 : bIsConsistent = sal_True;
513 : 12363 : eIOMode = STREAM_IO_DONTKNOW;
514 : :
515 : 12363 : bIsEof = sal_False;
516 : 12363 : }
517 : :
518 : 18969 : void SvStream::ResetError()
519 : : {
520 : 18969 : ClearError();
521 : 18969 : }
522 : :
523 : 570 : sal_Bool SvStream::ReadByteStringLine( rtl::OUString& rStr, rtl_TextEncoding eSrcCharSet,
524 : : sal_Int32 nMaxBytesToRead )
525 : : {
526 : 570 : rtl::OString aStr;
527 [ + - ]: 570 : sal_Bool bRet = ReadLine( aStr, nMaxBytesToRead);
528 [ + - ]: 570 : rStr = rtl::OStringToOUString(aStr, eSrcCharSet);
529 : 570 : return bRet;
530 : : }
531 : :
532 : 0 : sal_Bool SvStream::ReadByteStringLine( String& rStr, rtl_TextEncoding eSrcCharSet )
533 : : {
534 : 0 : rtl::OString aStr;
535 [ # # ]: 0 : sal_Bool bRet = ReadLine(aStr);
536 [ # # ][ # # ]: 0 : rStr = rtl::OStringToOUString(aStr, eSrcCharSet);
537 : 0 : return bRet;
538 : : }
539 : :
540 : 676366 : sal_Bool SvStream::ReadLine( rtl::OString& rStr, sal_Int32 nMaxBytesToRead )
541 : : {
542 : : sal_Char buf[256+1];
543 : 676366 : sal_Bool bEnd = sal_False;
544 : 676366 : sal_Size nOldFilePos = Tell();
545 : 676366 : sal_Char c = 0;
546 : 676366 : sal_Size nTotalLen = 0;
547 : :
548 : 676366 : rtl::OStringBuffer aBuf(4096);
549 [ + + ][ + - ]: 1352052 : while( !bEnd && !GetError() ) // Don't test for EOF as we
[ + + ]
550 : : // are reading block-wise!
551 : : {
552 [ + - ]: 676450 : sal_uInt16 nLen = (sal_uInt16)Read( buf, sizeof(buf)-1 );
553 [ + + ]: 676450 : if ( !nLen )
554 : : {
555 [ + + ]: 764 : if ( aBuf.getLength() == 0 )
556 : : {
557 : : // Exit on first block-read error
558 : 755 : bIsEof = sal_True;
559 : 755 : rStr = rtl::OString();
560 : 755 : return sal_False;
561 : : }
562 : : else
563 : 9 : break;
564 : : }
565 : :
566 : : sal_uInt16 j, n;
567 [ + + ]: 16347249 : for( j = n = 0; j < nLen ; ++j )
568 : : {
569 : 16347165 : c = buf[j];
570 [ + + ][ + + ]: 16347165 : if ( c == '\n' || c == '\r' )
571 : : {
572 : 675602 : bEnd = sal_True;
573 : 675602 : break;
574 : : }
575 [ - + ]: 15671563 : if ( n < j )
576 : 0 : buf[n] = c;
577 : 15671563 : ++n;
578 : : }
579 : 675686 : nTotalLen += j;
580 [ - + ]: 675686 : if (nTotalLen > static_cast<sal_Size>(nMaxBytesToRead))
581 : : {
582 : 0 : n -= nTotalLen - nMaxBytesToRead;
583 : 0 : nTotalLen = nMaxBytesToRead;
584 : 0 : bEnd = sal_True;
585 : : }
586 [ + + ]: 675686 : if ( n )
587 [ + - ]: 616219 : aBuf.append(buf, n);
588 : : }
589 : :
590 [ + + ][ + - ]: 675611 : if ( !bEnd && !GetError() && aBuf.getLength() )
[ + - ][ + + ]
591 : 9 : bEnd = sal_True;
592 : :
593 : 675611 : nOldFilePos += nTotalLen;
594 [ + + ]: 675611 : if( Tell() > nOldFilePos )
595 : 675602 : nOldFilePos++;
596 [ + - ]: 675611 : Seek( nOldFilePos ); // Seek pointer due to BlockRead above
597 : :
598 [ + - ][ + + ]: 675611 : if ( bEnd && (c=='\r' || c=='\n') ) // Special treatment for DOS files
[ + + ]
599 : : {
600 : : char cTemp;
601 [ + - ]: 675602 : sal_Size nLen = Read((char*)&cTemp , sizeof(cTemp) );
602 [ + + ]: 675602 : if ( nLen ) {
603 [ + + ][ + - ]: 674950 : if( cTemp == c || (cTemp != '\n' && cTemp != '\r') )
[ + - ]
604 [ + - ]: 675602 : Seek( nOldFilePos );
605 : : }
606 : : }
607 : :
608 [ + - ]: 675611 : if ( bEnd )
609 : 675611 : bIsEof = sal_False;
610 : 675611 : rStr = aBuf.makeStringAndClear();
611 : 676366 : return bEnd;
612 : : }
613 : :
614 : 0 : sal_Bool SvStream::ReadUniStringLine( rtl::OUString& rStr, sal_Int32 nMaxCodepointsToRead )
615 : : {
616 : : sal_Unicode buf[256+1];
617 : 0 : sal_Bool bEnd = sal_False;
618 : 0 : sal_Size nOldFilePos = Tell();
619 : 0 : sal_Unicode c = 0;
620 : 0 : sal_Size nTotalLen = 0;
621 : :
622 : : DBG_ASSERT( sizeof(sal_Unicode) == sizeof(sal_uInt16), "ReadUniStringLine: swapping sizeof(sal_Unicode) not implemented" );
623 : :
624 : 0 : rtl::OUStringBuffer aBuf(4096);
625 [ # # ][ # # ]: 0 : while( !bEnd && !GetError() ) // Don't test for EOF as we
[ # # ]
626 : : // are reading block-wise!
627 : : {
628 [ # # ]: 0 : sal_uInt16 nLen = (sal_uInt16)Read( (char*)buf, sizeof(buf)-sizeof(sal_Unicode) );
629 : 0 : nLen /= sizeof(sal_Unicode);
630 [ # # ]: 0 : if ( !nLen )
631 : : {
632 [ # # ]: 0 : if ( aBuf.getLength() == 0 )
633 : : {
634 : : // exit on first BlockRead error
635 : 0 : bIsEof = sal_True;
636 : 0 : rStr = rtl::OUString();
637 : 0 : return sal_False;
638 : : }
639 : : else
640 : 0 : break;
641 : : }
642 : :
643 : : sal_uInt16 j, n;
644 [ # # ]: 0 : for( j = n = 0; j < nLen ; ++j )
645 : : {
646 [ # # ]: 0 : if ( bSwap )
647 : 0 : SwapUShort( buf[n] );
648 : 0 : c = buf[j];
649 [ # # ][ # # ]: 0 : if ( c == '\n' || c == '\r' )
650 : : {
651 : 0 : bEnd = sal_True;
652 : 0 : break;
653 : : }
654 : : // erAck 26.02.01: Old behavior was no special treatment of '\0'
655 : : // character here, but a following rStr+=c did ignore it. Is this
656 : : // really intended? Or should a '\0' better terminate a line?
657 : : // The nOldFilePos stuff wasn't correct then anyways.
658 [ # # ]: 0 : if ( c )
659 : : {
660 [ # # ]: 0 : if ( n < j )
661 : 0 : buf[n] = c;
662 : 0 : ++n;
663 : : }
664 : : }
665 : 0 : nTotalLen += j;
666 [ # # ]: 0 : if (nTotalLen > static_cast<sal_Size>(nMaxCodepointsToRead))
667 : : {
668 : 0 : n -= nTotalLen - nMaxCodepointsToRead;
669 : 0 : nTotalLen = nMaxCodepointsToRead;
670 : 0 : bEnd = sal_True;
671 : : }
672 [ # # ]: 0 : if ( n )
673 [ # # ]: 0 : aBuf.append( buf, n );
674 : : }
675 : :
676 [ # # ][ # # ]: 0 : if ( !bEnd && !GetError() && aBuf.getLength() )
[ # # ][ # # ]
677 : 0 : bEnd = sal_True;
678 : :
679 : 0 : nOldFilePos += nTotalLen * sizeof(sal_Unicode);
680 [ # # ]: 0 : if( Tell() > nOldFilePos )
681 : 0 : nOldFilePos += sizeof(sal_Unicode);
682 [ # # ]: 0 : Seek( nOldFilePos ); // seek due to BlockRead above
683 : :
684 [ # # ][ # # ]: 0 : if ( bEnd && (c=='\r' || c=='\n') ) // special treatment for DOS files
[ # # ]
685 : : {
686 : : sal_Unicode cTemp;
687 [ # # ]: 0 : Read( (char*)&cTemp, sizeof(cTemp) );
688 [ # # ]: 0 : if ( bSwap )
689 : 0 : SwapUShort( cTemp );
690 [ # # ][ # # ]: 0 : if( cTemp == c || (cTemp != '\n' && cTemp != '\r') )
[ # # ]
691 [ # # ]: 0 : Seek( nOldFilePos );
692 : : }
693 : :
694 [ # # ]: 0 : if ( bEnd )
695 : 0 : bIsEof = sal_False;
696 [ # # ]: 0 : rStr = aBuf.makeStringAndClear();
697 : 0 : return bEnd;
698 : : }
699 : :
700 : 570 : sal_Bool SvStream::ReadUniOrByteStringLine( rtl::OUString& rStr, rtl_TextEncoding eSrcCharSet,
701 : : sal_Int32 nMaxCodepointsToRead )
702 : : {
703 [ - + ]: 570 : if ( eSrcCharSet == RTL_TEXTENCODING_UNICODE )
704 : 0 : return ReadUniStringLine( rStr, nMaxCodepointsToRead );
705 : : else
706 : 570 : return ReadByteStringLine( rStr, eSrcCharSet, nMaxCodepointsToRead );
707 : : }
708 : :
709 : 6 : rtl::OString read_zeroTerminated_uInt8s_ToOString(SvStream& rStream)
710 : : {
711 : 6 : rtl::OStringBuffer aOutput(256);
712 : :
713 : : sal_Char buf[ 256 + 1 ];
714 : 6 : sal_Bool bEnd = sal_False;
715 : 6 : sal_Size nFilePos = rStream.Tell();
716 : :
717 [ + + ][ + - ]: 12 : while( !bEnd && !rStream.GetError() )
[ + + ]
718 : : {
719 [ + - ]: 6 : sal_Size nLen = rStream.Read(buf, sizeof(buf)-1);
720 [ - + ]: 6 : if (!nLen)
721 : 0 : break;
722 : :
723 : 6 : sal_Size nReallyRead = nLen;
724 : 6 : const sal_Char* pPtr = buf;
725 [ + + ][ + + ]: 33 : while (nLen && *pPtr)
[ + + ]
726 : 27 : ++pPtr, --nLen;
727 : :
728 : : bEnd = ( nReallyRead < sizeof(buf)-1 ) // read less than attempted to read
729 : : || ( ( nLen > 0 ) // OR it is inside the block we read
730 : : && ( 0 == *pPtr ) // AND found a string terminator
731 [ - + ][ # # ]: 6 : );
[ # # ]
732 : :
733 [ + - ]: 6 : aOutput.append(buf, pPtr - buf);
734 : : }
735 : :
736 : 6 : nFilePos += aOutput.getLength();
737 [ + + ]: 6 : if (rStream.Tell() > nFilePos)
738 [ + - ]: 3 : rStream.Seek(nFilePos+1); // seek due to FileRead above
739 : 6 : return aOutput.makeStringAndClear();
740 : : }
741 : :
742 : 0 : rtl::OUString read_zeroTerminated_uInt8s_ToOUString(SvStream& rStream, rtl_TextEncoding eEnc)
743 : : {
744 : : return rtl::OStringToOUString(
745 [ # # ]: 0 : read_zeroTerminated_uInt8s_ToOString(rStream), eEnc);
746 : : }
747 : :
748 : : /** Attempt to write a prefixed sequence of nUnits 16bit units from an OUString,
749 : : returned value is number of bytes written */
750 : 119940 : sal_Size write_uInt16s_FromOUString(SvStream& rStrm, const rtl::OUString& rStr,
751 : : sal_Size nUnits)
752 : : {
753 : : DBG_ASSERT( sizeof(sal_Unicode) == sizeof(sal_uInt16), "write_uInt16s_FromOUString: swapping sizeof(sal_Unicode) not implemented" );
754 : : sal_Size nWritten;
755 [ + - ]: 119940 : if (!rStrm.IsEndianSwap())
756 : 119940 : nWritten = rStrm.Write( (char*)rStr.getStr(), nUnits * sizeof(sal_Unicode) );
757 : : else
758 : : {
759 : 0 : sal_Size nLen = nUnits;
760 : : sal_Unicode aBuf[384];
761 [ # # ][ # # ]: 0 : sal_Unicode* const pTmp = ( nLen > 384 ? new sal_Unicode[nLen] : aBuf);
762 : 0 : memcpy( pTmp, rStr.getStr(), nLen * sizeof(sal_Unicode) );
763 : 0 : sal_Unicode* p = pTmp;
764 : 0 : const sal_Unicode* const pStop = pTmp + nLen;
765 [ # # ]: 0 : while ( p < pStop )
766 : : {
767 : 0 : SwapUShort( *p );
768 : 0 : p++;
769 : : }
770 [ # # ]: 0 : nWritten = rStrm.Write( (char*)pTmp, nLen * sizeof(sal_Unicode) );
771 [ # # ]: 0 : if ( pTmp != aBuf )
772 [ # # ]: 0 : delete [] pTmp;
773 : : }
774 : 119940 : return nWritten;
775 : : }
776 : :
777 : 10891 : sal_Bool SvStream::WriteUnicodeOrByteText( const String& rStr, rtl_TextEncoding eDestCharSet )
778 : : {
779 [ + + ]: 10891 : if ( eDestCharSet == RTL_TEXTENCODING_UNICODE )
780 : : {
781 [ + - ]: 10885 : write_uInt16s_FromOUString(*this, rStr, rStr.Len());
782 : 10885 : return nError == SVSTREAM_OK;
783 : : }
784 : : else
785 : : {
786 [ + - ][ + - ]: 6 : rtl::OString aStr(rtl::OUStringToOString(rStr, eDestCharSet));
787 [ + - ]: 6 : write_uInt8s_FromOString(*this, aStr, aStr.getLength());
788 : 10891 : return nError == SVSTREAM_OK;
789 : : }
790 : : }
791 : :
792 : 0 : sal_Bool SvStream::WriteByteStringLine( const String& rStr, rtl_TextEncoding eDestCharSet )
793 : : {
794 [ # # ][ # # ]: 0 : return WriteLine(rtl::OUStringToOString(rStr, eDestCharSet));
795 : : }
796 : :
797 : 262117 : sal_Bool SvStream::WriteLine(const rtl::OString& rStr)
798 : : {
799 : 262117 : Write(rStr.getStr(), rStr.getLength());
800 : 262117 : endl(*this);
801 : 262117 : return nError == SVSTREAM_OK;
802 : : }
803 : :
804 : 0 : sal_Bool SvStream::WriteUniOrByteChar( sal_Unicode ch, rtl_TextEncoding eDestCharSet )
805 : : {
806 [ # # ]: 0 : if ( eDestCharSet == RTL_TEXTENCODING_UNICODE )
807 : 0 : *this << ch;
808 : : else
809 : : {
810 [ # # ]: 0 : rtl::OString aStr(&ch, 1, eDestCharSet);
811 [ # # ]: 0 : Write(aStr.getStr(), aStr.getLength());
812 : : }
813 : 0 : return nError == SVSTREAM_OK;
814 : : }
815 : :
816 : 0 : sal_Bool SvStream::StartWritingUnicodeText()
817 : : {
818 : 0 : SetEndianSwap( sal_False ); // write native format
819 : : // BOM, Byte Order Mark, U+FEFF, see
820 : : // http://www.unicode.org/faq/utf_bom.html#BOM
821 : : // Upon read: 0xfeff(-257) => no swap; 0xfffe(-2) => swap
822 : 0 : *this << sal_uInt16( 0xfeff );
823 : 0 : return nError == SVSTREAM_OK;
824 : : }
825 : :
826 : 6 : sal_Bool SvStream::StartReadingUnicodeText( rtl_TextEncoding eReadBomCharSet )
827 : : {
828 [ + - ]: 6 : if (!( eReadBomCharSet == RTL_TEXTENCODING_DONTKNOW ||
829 : : eReadBomCharSet == RTL_TEXTENCODING_UNICODE ||
830 [ + - ][ + - ]: 6 : eReadBomCharSet == RTL_TEXTENCODING_UTF8))
831 : 6 : return sal_True; // nothing to read
832 : :
833 : 0 : bool bTryUtf8 = false;
834 : : sal_uInt16 nFlag;
835 : 0 : sal_sSize nBack = sizeof(nFlag);
836 [ # # ]: 0 : *this >> nFlag;
837 [ # # # # : 0 : switch ( nFlag )
# ]
838 : : {
839 : : case 0xfeff :
840 : : // native UTF-16
841 [ # # ][ # # ]: 0 : if ( eReadBomCharSet == RTL_TEXTENCODING_DONTKNOW ||
842 : : eReadBomCharSet == RTL_TEXTENCODING_UNICODE)
843 : 0 : nBack = 0;
844 : 0 : break;
845 : : case 0xfffe :
846 : : // swapped UTF-16
847 [ # # ][ # # ]: 0 : if ( eReadBomCharSet == RTL_TEXTENCODING_DONTKNOW ||
848 : : eReadBomCharSet == RTL_TEXTENCODING_UNICODE)
849 : : {
850 [ # # ]: 0 : SetEndianSwap( !bSwap );
851 : 0 : nBack = 0;
852 : : }
853 : 0 : break;
854 : : case 0xefbb :
855 [ # # ][ # # ]: 0 : if (nNumberFormatInt == NUMBERFORMAT_INT_BIGENDIAN &&
[ # # ]
856 : : (eReadBomCharSet == RTL_TEXTENCODING_DONTKNOW ||
857 : : eReadBomCharSet == RTL_TEXTENCODING_UTF8))
858 : 0 : bTryUtf8 = true;
859 : 0 : break;
860 : : case 0xbbef :
861 [ # # ][ # # ]: 0 : if (nNumberFormatInt == NUMBERFORMAT_INT_LITTLEENDIAN &&
[ # # ]
862 : : (eReadBomCharSet == RTL_TEXTENCODING_DONTKNOW ||
863 : : eReadBomCharSet == RTL_TEXTENCODING_UTF8))
864 : 0 : bTryUtf8 = true;
865 : 0 : break;
866 : : default:
867 : : ; // nothing
868 : : }
869 [ # # ]: 0 : if (bTryUtf8)
870 : : {
871 : : sal_uChar nChar;
872 : 0 : nBack += sizeof(nChar);
873 [ # # ]: 0 : *this >> nChar;
874 [ # # ]: 0 : if (nChar == 0xbf)
875 : 0 : nBack = 0; // it is UTF-8
876 : : }
877 [ # # ]: 0 : if (nBack)
878 [ # # ]: 0 : SeekRel( -nBack ); // no BOM, pure data
879 : 6 : return nError == SVSTREAM_OK;
880 : : }
881 : :
882 : 1218575 : sal_Size SvStream::SeekRel( sal_sSize nPos )
883 : : {
884 : 1218575 : sal_Size nActualPos = Tell();
885 : :
886 [ + + ]: 1218575 : if ( nPos >= 0 )
887 : : {
888 [ + - ]: 1123104 : if ( SAL_MAX_SIZE - nActualPos > (sal_Size)nPos )
889 : 1123104 : nActualPos += nPos;
890 : : }
891 : : else
892 : : {
893 : 95471 : sal_Size nAbsPos = (sal_Size)-nPos;
894 [ + - ]: 95471 : if ( nActualPos >= nAbsPos )
895 : 95471 : nActualPos -= nAbsPos;
896 : : }
897 : :
898 : 1218575 : pBufPos = pRWBuf + nActualPos;
899 : 1218575 : return Seek( nActualPos );
900 : : }
901 : :
902 : 3707115 : SvStream& SvStream::operator>>(sal_uInt16& r)
903 : : {
904 : 3707115 : sal_uInt16 n = 0;
905 [ + + ][ + + ]: 10549803 : READNUMBER_WITHOUT_SWAP(sal_uInt16, n)
[ + + ][ + - ]
906 [ + + ]: 3707115 : if (good())
907 : : {
908 [ + + ]: 3702568 : if (bSwap)
909 : 5511 : SwapUShort(n);
910 : 3702568 : r = n;
911 : : }
912 : 3707115 : return *this;
913 : : }
914 : :
915 : 1279912 : SvStream& SvStream::operator>>(sal_uInt32& r)
916 : : {
917 : 1279912 : sal_uInt32 n = 0;
918 [ + + ][ + + ]: 6079828 : READNUMBER_WITHOUT_SWAP(sal_uInt32, n)
[ + + ][ + - ]
919 [ + + ]: 1279912 : if (good())
920 : : {
921 [ + + ]: 1279586 : if (bSwap)
922 : 95973 : SwapULong(n);
923 : 1279586 : r = n;
924 : : }
925 : 1279912 : return *this;
926 : : }
927 : :
928 : 0 : SvStream& SvStream::operator>>(sal_uInt64& r)
929 : : {
930 : 0 : sal_uInt64 n = 0;
931 [ # # ][ # # ]: 0 : READNUMBER_WITHOUT_SWAP(sal_uInt64, n)
[ # # ][ # # ]
932 [ # # ]: 0 : if (good())
933 : : {
934 [ # # ]: 0 : if (bSwap)
935 : 0 : SwapUInt64(n);
936 : 0 : r = n;
937 : : }
938 : 0 : return *this;
939 : : }
940 : :
941 : 139255 : SvStream& SvStream::operator>>(sal_Int16& r)
942 : : {
943 : 139255 : sal_Int16 n = 0;
944 [ + + ][ + + ]: 352107 : READNUMBER_WITHOUT_SWAP(sal_Int16, n)
[ + + ][ + - ]
945 [ + + ]: 139255 : if (good())
946 : : {
947 [ + + ]: 115322 : if (bSwap)
948 : 8508 : SwapShort(n);
949 : 115322 : r = n;
950 : : }
951 : 139255 : return *this;
952 : : }
953 : :
954 : 860722 : SvStream& SvStream::operator>>(sal_Int32& r)
955 : : {
956 : 860722 : sal_Int32 n = 0;
957 [ + + ][ + + ]: 3939662 : READNUMBER_WITHOUT_SWAP(sal_Int32, n)
[ + + ][ + - ]
958 [ + + ]: 860722 : if (good())
959 : : {
960 [ + + ]: 830243 : if (bSwap)
961 : 37421 : SwapLongInt(n);
962 : 830243 : r = n;
963 : : }
964 : 860722 : return *this;
965 : : }
966 : :
967 : 0 : SvStream& SvStream::operator>>(sal_Int64& r)
968 : : {
969 : 0 : sal_Int64 n = 0;
970 [ # # ][ # # ]: 0 : READNUMBER_WITHOUT_SWAP(sal_Int64, n)
[ # # ][ # # ]
971 [ # # ]: 0 : if (good())
972 : : {
973 [ # # ]: 0 : if (bSwap)
974 : 0 : SwapInt64(n);
975 : 0 : r = n;
976 : : }
977 : 0 : return *this;
978 : : }
979 : :
980 : 1527 : SvStream& SvStream::operator>>( signed char& r )
981 : : {
982 [ + + ][ - + ]: 1527 : if( (eIOMode == STREAM_IO_READ || !bIsConsistent) &&
[ + + ]
983 : : sizeof(signed char) <= nBufFree )
984 : : {
985 : 1331 : r = *pBufPos;
986 : 1331 : nBufActualPos += sizeof(signed char);
987 : 1331 : pBufPos += sizeof(signed char);
988 : 1331 : nBufFree -= sizeof(signed char);
989 : : }
990 : : else
991 : 196 : Read( (char*)&r, sizeof(signed char) );
992 : 1527 : return *this;
993 : : }
994 : :
995 : : // Special treatment for Chars due to PutBack
996 : :
997 : 3412799 : SvStream& SvStream::operator>>( char& r )
998 : : {
999 [ + + ][ - + ]: 3412799 : if( (eIOMode == STREAM_IO_READ || !bIsConsistent) &&
[ + + ]
1000 : : sizeof(char) <= nBufFree )
1001 : : {
1002 : 3305224 : r = *pBufPos;
1003 : 3305224 : nBufActualPos += sizeof(char);
1004 : 3305224 : pBufPos += sizeof(char);
1005 : 3305224 : nBufFree -= sizeof(char);
1006 : : }
1007 : : else
1008 : 107575 : Read( (char*)&r, sizeof(char) );
1009 : 3412799 : return *this;
1010 : : }
1011 : :
1012 : 1913031 : SvStream& SvStream::operator>>( unsigned char& r )
1013 : : {
1014 [ + + ][ - + ]: 1913031 : if( (eIOMode == STREAM_IO_READ || !bIsConsistent) &&
[ + + ]
1015 : : sizeof(char) <= nBufFree )
1016 : : {
1017 : 1541837 : r = *pBufPos;
1018 : 1541837 : nBufActualPos += sizeof(char);
1019 : 1541837 : pBufPos += sizeof(char);
1020 : 1541837 : nBufFree -= sizeof(char);
1021 : : }
1022 : : else
1023 : 371194 : Read( (char*)&r, sizeof(char) );
1024 : 1913031 : return *this;
1025 : : }
1026 : :
1027 : 660 : SvStream& SvStream::operator>>(float& r)
1028 : : {
1029 : 660 : float n = 0;
1030 [ + - ][ + + ]: 2928 : READNUMBER_WITHOUT_SWAP(float, n)
[ + + ][ + - ]
1031 [ + - ]: 660 : if (good())
1032 : : {
1033 : : #if defined UNX
1034 [ - + ]: 660 : if (bSwap)
1035 : 0 : SwapFloat(n);
1036 : : #endif
1037 : 660 : r = n;
1038 : : }
1039 : 660 : return *this;
1040 : : }
1041 : :
1042 : 2916 : SvStream& SvStream::operator>>(double& r)
1043 : : {
1044 : 2916 : double n = 0;
1045 [ + - ][ + - ]: 26244 : READNUMBER_WITHOUT_SWAP(double, n)
[ + + ][ # # ]
1046 [ + - ]: 2916 : if (good())
1047 : : {
1048 : : #if defined UNX
1049 [ - + ]: 2916 : if (bSwap)
1050 : 0 : SwapDouble(n);
1051 : : #endif
1052 : 2916 : r = n;
1053 : : }
1054 : 2916 : return *this;
1055 : : }
1056 : :
1057 : 9 : SvStream& SvStream::operator>> ( SvStream& rStream )
1058 : : {
1059 : 9 : const sal_uInt32 cBufLen = 0x8000;
1060 : 9 : char* pBuf = new char[ cBufLen ];
1061 : :
1062 : : sal_uInt32 nCount;
1063 [ - + ]: 9 : do {
1064 : 9 : nCount = Read( pBuf, cBufLen );
1065 : 9 : rStream.Write( pBuf, nCount );
1066 : : } while( nCount == cBufLen );
1067 : :
1068 [ + - ]: 9 : delete[] pBuf;
1069 : 9 : return *this;
1070 : : }
1071 : :
1072 : 4834552 : SvStream& SvStream::operator<< ( sal_uInt16 v )
1073 : : {
1074 [ - + ]: 4834552 : if( bSwap )
1075 : 0 : SwapUShort(v);
1076 [ + + ][ + + ]: 11105244 : WRITENUMBER_WITHOUT_SWAP(sal_uInt16,v)
[ + + ][ + - ]
1077 : 4834552 : return *this;
1078 : : }
1079 : :
1080 : 1828304 : SvStream& SvStream::operator<< ( sal_uInt32 v )
1081 : : {
1082 [ + + ]: 1828304 : if( bSwap )
1083 : 1298 : SwapULong(v);
1084 [ + + ][ + + ]: 3472340 : WRITENUMBER_WITHOUT_SWAP(sal_uInt32,v)
[ + + ][ + - ]
1085 : 1828304 : return *this;
1086 : : }
1087 : :
1088 : 563 : SvStream& SvStream::operator<< ( sal_uInt64 v )
1089 : : {
1090 [ - + ]: 563 : if( bSwap )
1091 : 0 : SwapUInt64(v);
1092 [ + - ][ + + ]: 5035 : WRITENUMBER_WITHOUT_SWAP(sal_uInt64,v)
[ + + ][ + - ]
1093 : 563 : return *this;
1094 : : }
1095 : :
1096 : 149469 : SvStream& SvStream::operator<< ( sal_Int16 v )
1097 : : {
1098 [ - + ]: 149469 : if( bSwap )
1099 : 0 : SwapShort(v);
1100 [ + + ][ + + ]: 438401 : WRITENUMBER_WITHOUT_SWAP(sal_Int16,v)
[ + + ][ + - ]
1101 : 149469 : return *this;
1102 : : }
1103 : :
1104 : 830221 : SvStream& SvStream::operator<< ( sal_Int32 v )
1105 : : {
1106 [ - + ]: 830221 : if( bSwap )
1107 : 0 : SwapLongInt(v);
1108 [ + + ][ + + ]: 3608281 : WRITENUMBER_WITHOUT_SWAP(sal_Int32,v)
[ + + ][ + - ]
1109 : 830221 : return *this;
1110 : : }
1111 : :
1112 : 0 : SvStream& SvStream::operator<< ( sal_Int64 v )
1113 : : {
1114 [ # # ]: 0 : if( bSwap )
1115 : 0 : SwapInt64(v);
1116 [ # # ][ # # ]: 0 : WRITENUMBER_WITHOUT_SWAP(sal_Int64,v)
[ # # ][ # # ]
1117 : 0 : return *this;
1118 : : }
1119 : :
1120 : 2828 : SvStream& SvStream::operator<< ( signed char v )
1121 : : {
1122 : : //SDO
1123 : 2828 : int tmp = eIOMode;
1124 [ + - ][ + - ]: 2828 : if(tmp == STREAM_IO_WRITE && sizeof(signed char) <= nBufFree )
1125 : : {
1126 : 2828 : *pBufPos = v;
1127 : 2828 : pBufPos++; // sizeof(char);
1128 : 2828 : nBufActualPos++;
1129 [ + - ]: 2828 : if( nBufActualPos > nBufActualLen ) // Append ?
1130 : 2828 : nBufActualLen = nBufActualPos;
1131 : 2828 : nBufFree--; // = sizeof(char);
1132 : 2828 : bIsDirty = sal_True;
1133 : : }
1134 : : else
1135 : 0 : Write( (char*)&v, sizeof(signed char) );
1136 : 2828 : return *this;
1137 : : }
1138 : :
1139 : : // Special treatment for Chars due to PutBack
1140 : :
1141 : 873651 : SvStream& SvStream::operator<< ( char v )
1142 : : {
1143 : : //SDO
1144 : 873651 : int tmp = eIOMode;
1145 [ + + ][ + + ]: 873651 : if(tmp == STREAM_IO_WRITE && sizeof(char) <= nBufFree )
1146 : : {
1147 : 855018 : *pBufPos = v;
1148 : 855018 : pBufPos++; // sizeof(char);
1149 : 855018 : nBufActualPos++;
1150 [ + + ]: 855018 : if( nBufActualPos > nBufActualLen ) // Append ?
1151 : 825454 : nBufActualLen = nBufActualPos;
1152 : 855018 : nBufFree--; // = sizeof(char);
1153 : 855018 : bIsDirty = sal_True;
1154 : : }
1155 : : else
1156 : 18633 : Write( (char*)&v, sizeof(char) );
1157 : 873651 : return *this;
1158 : : }
1159 : :
1160 : 1234680 : SvStream& SvStream::operator<< ( unsigned char v )
1161 : : {
1162 : : //SDO
1163 : 1234680 : int tmp = eIOMode;
1164 [ + + ][ + + ]: 1234680 : if(tmp == STREAM_IO_WRITE && sizeof(char) <= nBufFree )
1165 : : {
1166 : 736822 : *(unsigned char*)pBufPos = v;
1167 : 736822 : pBufPos++; // = sizeof(char);
1168 : 736822 : nBufActualPos++; // = sizeof(char);
1169 [ + - ]: 736822 : if( nBufActualPos > nBufActualLen ) // Append ?
1170 : 736822 : nBufActualLen = nBufActualPos;
1171 : 736822 : nBufFree--;
1172 : 736822 : bIsDirty = sal_True;
1173 : : }
1174 : : else
1175 : 497858 : Write( (char*)&v, sizeof(char) );
1176 : 1234680 : return *this;
1177 : : }
1178 : :
1179 : 54 : SvStream& SvStream::operator<< ( float v )
1180 : : {
1181 : : #ifdef UNX
1182 [ - + ]: 54 : if( bSwap )
1183 : 0 : SwapFloat(v);
1184 : : #endif
1185 [ + - ][ + - ]: 270 : WRITENUMBER_WITHOUT_SWAP(float,v)
[ + + ][ + - ]
1186 : 54 : return *this;
1187 : : }
1188 : :
1189 : 22586 : SvStream& SvStream::operator<< ( const double& r )
1190 : : {
1191 : : #if defined UNX
1192 [ - + ]: 22586 : if( bSwap )
1193 : : {
1194 : 0 : double nHelp = r;
1195 : 0 : SwapDouble(nHelp);
1196 [ # # ][ # # ]: 0 : WRITENUMBER_WITHOUT_SWAP(double,nHelp)
[ # # ][ # # ]
[ # # ]
1197 : 0 : return *this;
1198 : : }
1199 : : else
1200 : : #endif
1201 [ + + ][ + + ]: 155834 : WRITENUMBER_WITHOUT_SWAP(double,r)
[ + + ][ + - ]
1202 : :
1203 : 22586 : return *this;
1204 : : }
1205 : :
1206 : 774224 : SvStream& SvStream::operator<< ( const char* pBuf )
1207 : : {
1208 : 774224 : Write( pBuf, strlen( pBuf ) );
1209 : 774224 : return *this;
1210 : : }
1211 : :
1212 : 0 : SvStream& SvStream::operator<< ( const unsigned char* pBuf )
1213 : : {
1214 : 0 : Write( (char*)pBuf, strlen( (char*)pBuf ) );
1215 : 0 : return *this;
1216 : : }
1217 : :
1218 : 110 : SvStream& SvStream::operator<< ( SvStream& rStream )
1219 : : {
1220 : 110 : const sal_uInt32 cBufLen = 0x8000;
1221 : 110 : char* pBuf = new char[ cBufLen ];
1222 : : sal_uInt32 nCount;
1223 [ + + ]: 598 : do {
1224 : 598 : nCount = rStream.Read( pBuf, cBufLen );
1225 : 598 : Write( pBuf, nCount );
1226 : : } while( nCount == cBufLen );
1227 : :
1228 [ + - ]: 110 : delete[] pBuf;
1229 : 110 : return *this;
1230 : : }
1231 : :
1232 : 206713 : rtl::OUString SvStream::ReadUniOrByteString( rtl_TextEncoding eSrcCharSet )
1233 : : {
1234 : : // read UTF-16 string directly from stream ?
1235 [ + + ]: 206713 : if (eSrcCharSet == RTL_TEXTENCODING_UNICODE)
1236 : 25459 : return read_lenPrefixed_uInt16s_ToOUString<sal_uInt32>(*this);
1237 : 206713 : return read_lenPrefixed_uInt8s_ToOUString<sal_uInt16>(*this, eSrcCharSet);
1238 : : }
1239 : :
1240 : 246577 : SvStream& SvStream::WriteUniOrByteString( const rtl::OUString& rStr, rtl_TextEncoding eDestCharSet )
1241 : : {
1242 : : // write UTF-16 string directly into stream ?
1243 [ + + ]: 246577 : if (eDestCharSet == RTL_TEXTENCODING_UNICODE)
1244 : 32850 : write_lenPrefixed_uInt16s_FromOUString<sal_uInt32>(*this, rStr);
1245 : : else
1246 : 213727 : write_lenPrefixed_uInt8s_FromOUString<sal_uInt16>(*this, rStr, eDestCharSet);
1247 : 246577 : return *this;
1248 : : }
1249 : :
1250 : 4867747 : sal_Size SvStream::Read( void* pData, sal_Size nCount )
1251 : : {
1252 : 4867747 : sal_Size nSaveCount = nCount;
1253 [ - + ]: 4867747 : if( !bIsConsistent )
1254 : 0 : RefreshBuffer();
1255 : :
1256 [ + + ]: 4867747 : if( !pRWBuf )
1257 : : {
1258 : 2438549 : nCount = GetData( (char*)pData,nCount);
1259 [ - + ]: 2438549 : if( nCryptMask )
1260 : 0 : EncryptBuffer(pData, nCount);
1261 : 2438549 : nBufFilePos += nCount;
1262 : : }
1263 : : else
1264 : : {
1265 : : // check if block is completely within buffer
1266 : 2429198 : eIOMode = STREAM_IO_READ;
1267 [ + + ]: 2429198 : if( nCount <= (sal_Size)(nBufActualLen - nBufActualPos ) )
1268 : : {
1269 : : // => yes
1270 : 2018352 : memcpy(pData, pBufPos, (size_t) nCount);
1271 : 2018352 : nBufActualPos = nBufActualPos + (sal_uInt16)nCount;
1272 : 2018352 : pBufPos += nCount;
1273 : 2018352 : nBufFree = nBufFree - (sal_uInt16)nCount;
1274 : : }
1275 : : else
1276 : : {
1277 [ + + ]: 410846 : if( bIsDirty ) // Does stream require a flush?
1278 : : {
1279 : 85 : SeekPos( nBufFilePos );
1280 [ - + ]: 85 : if( nCryptMask )
1281 : 0 : CryptAndWriteBuffer(pRWBuf, nBufActualLen);
1282 : : else
1283 : 85 : PutData( pRWBuf, nBufActualLen );
1284 : 85 : bIsDirty = sal_False;
1285 : : }
1286 : :
1287 : : // Does data block fit into buffer?
1288 [ + + ]: 410846 : if( nCount > nBufSize )
1289 : : {
1290 : : // => No! Thus read directly
1291 : : // into target area without using the buffer
1292 : :
1293 : 30768 : eIOMode = STREAM_IO_DONTKNOW;
1294 : :
1295 : 30768 : SeekPos( nBufFilePos + nBufActualPos );
1296 : 30768 : nBufActualLen = 0;
1297 : 30768 : pBufPos = pRWBuf;
1298 : 30768 : nCount = GetData( (char*)pData, nCount );
1299 [ - + ]: 30768 : if( nCryptMask )
1300 : 0 : EncryptBuffer(pData, nCount);
1301 : 30768 : nBufFilePos += nCount;
1302 : 30768 : nBufFilePos += nBufActualPos;
1303 : 30768 : nBufActualPos = 0;
1304 : : }
1305 : : else
1306 : : {
1307 : : // => Yes. Fill buffer first, then copy to target area
1308 : :
1309 : 380078 : nBufFilePos += nBufActualPos;
1310 : 380078 : SeekPos( nBufFilePos );
1311 : :
1312 : : // TODO: Typecast before GetData, sal_uInt16 nCountTmp
1313 : 380078 : sal_Size nCountTmp = GetData( pRWBuf, nBufSize );
1314 [ - + ]: 380078 : if( nCryptMask )
1315 : 0 : EncryptBuffer(pRWBuf, nCountTmp);
1316 : 380078 : nBufActualLen = (sal_uInt16)nCountTmp;
1317 [ + + ]: 380078 : if( nCount > nCountTmp )
1318 : : {
1319 : 243771 : nCount = nCountTmp; // trim count back, EOF see below
1320 : : }
1321 : 380078 : memcpy( pData, pRWBuf, (size_t)nCount );
1322 : 380078 : nBufActualPos = (sal_uInt16)nCount;
1323 : 380078 : pBufPos = pRWBuf + nCount;
1324 : : }
1325 : : }
1326 : : }
1327 : 4867747 : bIsEof = sal_False;
1328 : 4867747 : nBufFree = nBufActualLen - nBufActualPos;
1329 [ + + ][ + - ]: 4867747 : if( nCount != nSaveCount && nError != ERRCODE_IO_PENDING )
1330 : 321296 : bIsEof = sal_True;
1331 [ + + ][ - + ]: 4867747 : if( nCount == nSaveCount && nError == ERRCODE_IO_PENDING )
1332 : 0 : nError = ERRCODE_NONE;
1333 : 4867747 : return nCount;
1334 : : }
1335 : :
1336 : 6196409 : sal_Size SvStream::Write( const void* pData, sal_Size nCount )
1337 : : {
1338 [ + + ]: 6196409 : if( !nCount )
1339 : 102281 : return 0;
1340 [ - + ]: 6094128 : if( !bIsWritable )
1341 : : {
1342 : 0 : SetError( ERRCODE_IO_CANTWRITE );
1343 : 0 : return 0;
1344 : : }
1345 [ - + ]: 6094128 : if( !bIsConsistent )
1346 : 0 : RefreshBuffer(); // Remove changes in buffer through PutBack
1347 : :
1348 [ + + ]: 6094128 : if( !pRWBuf )
1349 : : {
1350 [ - + ]: 806493 : if( nCryptMask )
1351 : 0 : nCount = CryptAndWriteBuffer( pData, nCount );
1352 : : else
1353 : 806493 : nCount = PutData( (char*)pData, nCount );
1354 : 806493 : nBufFilePos += nCount;
1355 : 806493 : return nCount;
1356 : : }
1357 : :
1358 : 5287635 : eIOMode = STREAM_IO_WRITE;
1359 [ + + ]: 5287635 : if( nCount <= (sal_Size)(nBufSize - nBufActualPos) )
1360 : : {
1361 : 5154534 : memcpy( pBufPos, pData, (size_t)nCount );
1362 : 5154534 : nBufActualPos = nBufActualPos + (sal_uInt16)nCount;
1363 : : // Update length if buffer was updated
1364 [ + + ]: 5154534 : if( nBufActualPos > nBufActualLen )
1365 : 5071476 : nBufActualLen = nBufActualPos;
1366 : :
1367 : 5154534 : pBufPos += nCount;
1368 : 5154534 : bIsDirty = sal_True;
1369 : : }
1370 : : else
1371 : : {
1372 : : // Does stream require flushing?
1373 [ + + ]: 133101 : if( bIsDirty )
1374 : : {
1375 : 121880 : SeekPos( nBufFilePos );
1376 [ - + ]: 121880 : if( nCryptMask )
1377 : 0 : CryptAndWriteBuffer( pRWBuf, (sal_Size)nBufActualLen );
1378 : : else
1379 : 121880 : PutData( pRWBuf, nBufActualLen );
1380 : 121880 : bIsDirty = sal_False;
1381 : : }
1382 : :
1383 : : // Does data block fit into buffer?
1384 [ + + ]: 133101 : if( nCount > nBufSize )
1385 : : {
1386 : 27129 : eIOMode = STREAM_IO_DONTKNOW;
1387 : 27129 : nBufFilePos += nBufActualPos;
1388 : 27129 : nBufActualLen = 0;
1389 : 27129 : nBufActualPos = 0;
1390 : 27129 : pBufPos = pRWBuf;
1391 : 27129 : SeekPos( nBufFilePos );
1392 [ - + ]: 27129 : if( nCryptMask )
1393 : 0 : nCount = CryptAndWriteBuffer( pData, nCount );
1394 : : else
1395 : 27129 : nCount = PutData( (char*)pData, nCount );
1396 : 27129 : nBufFilePos += nCount;
1397 : : }
1398 : : else
1399 : : {
1400 : : // Copy block to buffer
1401 : 105972 : memcpy( pRWBuf, pData, (size_t)nCount );
1402 : :
1403 : : // Mind the order!
1404 : 105972 : nBufFilePos += nBufActualPos;
1405 : 105972 : nBufActualPos = (sal_uInt16)nCount;
1406 : 105972 : pBufPos = pRWBuf + nCount;
1407 : 105972 : nBufActualLen = (sal_uInt16)nCount;
1408 : 105972 : bIsDirty = sal_True;
1409 : : }
1410 : : }
1411 : 5287635 : nBufFree = nBufSize - nBufActualPos;
1412 : 6196409 : return nCount;
1413 : : }
1414 : :
1415 : 7550580 : sal_Size SvStream::Seek( sal_Size nFilePos )
1416 : : {
1417 : 7550580 : eIOMode = STREAM_IO_DONTKNOW;
1418 : :
1419 : 7550580 : bIsEof = sal_False;
1420 [ + + ]: 7550580 : if( !pRWBuf )
1421 : : {
1422 : 2095881 : nBufFilePos = SeekPos( nFilePos );
1423 : : DBG_ASSERT(Tell()==nBufFilePos,"Out Of Sync!");
1424 : 2095881 : return nBufFilePos;
1425 : : }
1426 : :
1427 : : // Is seek position within buffer?
1428 [ + + ][ + + ]: 5454699 : if( nFilePos >= nBufFilePos && nFilePos <= (nBufFilePos + nBufActualLen))
1429 : : {
1430 : 1998784 : nBufActualPos = (sal_uInt16)(nFilePos - nBufFilePos);
1431 : 1998784 : pBufPos = pRWBuf + nBufActualPos;
1432 : : // Update nBufFree to avoid crash upon PutBack
1433 : 1998784 : nBufFree = nBufActualLen - nBufActualPos;
1434 : : }
1435 : : else
1436 : : {
1437 [ + + ][ + - ]: 3455915 : if( bIsDirty && bIsConsistent)
1438 : : {
1439 : 2930617 : SeekPos( nBufFilePos );
1440 [ - + ]: 2930617 : if( nCryptMask )
1441 : 0 : CryptAndWriteBuffer( pRWBuf, nBufActualLen );
1442 : : else
1443 : 2930617 : PutData( pRWBuf, nBufActualLen );
1444 : 2930617 : bIsDirty = sal_False;
1445 : : }
1446 : 3455915 : nBufActualLen = 0;
1447 : 3455915 : nBufActualPos = 0;
1448 : 3455915 : pBufPos = pRWBuf;
1449 : 3455915 : nBufFilePos = SeekPos( nFilePos );
1450 : : }
1451 : : #ifdef OV_DEBUG
1452 : : {
1453 : : sal_Size nDebugTemp = nBufFilePos + nBufActualPos;
1454 : : DBG_ASSERT(Tell()==nDebugTemp,"Sync?");
1455 : : }
1456 : : #endif
1457 : 7550580 : return nBufFilePos + nBufActualPos;
1458 : : }
1459 : :
1460 : : //STREAM_SEEK_TO_END in the some of the Seek backends is special cased to be
1461 : : //efficient, in others e.g. SotStorageStream it's really horribly slow, and in
1462 : : //those this should be overridden
1463 : 0 : sal_Size SvStream::remainingSize()
1464 : : {
1465 : 0 : sal_Size nCurr = Tell();
1466 : 0 : sal_Size nEnd = Seek(STREAM_SEEK_TO_END);
1467 : 0 : sal_Size nMaxAvailable = nEnd-nCurr;
1468 : 0 : Seek(nCurr);
1469 : 0 : return nMaxAvailable;
1470 : : }
1471 : :
1472 : 275552 : void SvStream::Flush()
1473 : : {
1474 [ + + ][ + - ]: 275552 : if( bIsDirty && bIsConsistent )
1475 : : {
1476 : 14394 : SeekPos( nBufFilePos );
1477 [ - + ]: 14394 : if( nCryptMask )
1478 : 0 : CryptAndWriteBuffer( pRWBuf, (sal_Size)nBufActualLen );
1479 : : else
1480 [ + + ]: 14394 : if( PutData( pRWBuf, nBufActualLen ) != nBufActualLen )
1481 : 9 : SetError( SVSTREAM_WRITE_ERROR );
1482 : 14394 : bIsDirty = sal_False;
1483 : : }
1484 [ + + ]: 275552 : if( bIsWritable )
1485 : 258456 : FlushData();
1486 : 275552 : }
1487 : :
1488 : 40 : void SvStream::RefreshBuffer()
1489 : : {
1490 [ - + ][ # # ]: 40 : if( bIsDirty && bIsConsistent )
1491 : : {
1492 : 0 : SeekPos( nBufFilePos );
1493 [ # # ]: 0 : if( nCryptMask )
1494 : 0 : CryptAndWriteBuffer( pRWBuf, (sal_Size)nBufActualLen );
1495 : : else
1496 : 0 : PutData( pRWBuf, nBufActualLen );
1497 : 0 : bIsDirty = sal_False;
1498 : : }
1499 : 40 : SeekPos( nBufFilePos );
1500 : 40 : nBufActualLen = (sal_uInt16)GetData( pRWBuf, nBufSize );
1501 [ - + ][ + - ]: 40 : if( nBufActualLen && nError == ERRCODE_IO_PENDING )
1502 : 0 : nError = ERRCODE_NONE;
1503 [ - + ]: 40 : if( nCryptMask )
1504 : 0 : EncryptBuffer(pRWBuf, (sal_Size)nBufActualLen);
1505 : 40 : bIsConsistent = sal_True;
1506 : 40 : eIOMode = STREAM_IO_DONTKNOW;
1507 : 40 : }
1508 : :
1509 : 0 : SvStream& SvStream::WriteNumber(sal_Int32 nInt32)
1510 : : {
1511 : : char buffer[12];
1512 : 0 : sal_Size nLen = sprintf(buffer, "%" SAL_PRIdINT32, nInt32);
1513 [ # # ]: 0 : Write(buffer, nLen);
1514 : 0 : return *this;
1515 : : }
1516 : :
1517 : 0 : SvStream& SvStream::WriteNumber(sal_uInt32 nUInt32)
1518 : : {
1519 : : char buffer[11];
1520 : 0 : sal_Size nLen = sprintf(buffer, "%" SAL_PRIuUINT32, nUInt32);
1521 [ # # ]: 0 : Write(buffer, nLen);
1522 : 0 : return *this;
1523 : : }
1524 : :
1525 : : #define CRYPT_BUFSIZE 1024
1526 : :
1527 : : /// Encrypt and write
1528 : 0 : sal_Size SvStream::CryptAndWriteBuffer( const void* pStart, sal_Size nLen)
1529 : : {
1530 : : unsigned char pTemp[CRYPT_BUFSIZE];
1531 : 0 : unsigned char* pDataPtr = (unsigned char*)pStart;
1532 : 0 : sal_Size nCount = 0;
1533 : : sal_Size nBufCount;
1534 : 0 : unsigned char nMask = nCryptMask;
1535 [ # # ]: 0 : do
1536 : : {
1537 [ # # ]: 0 : if( nLen >= CRYPT_BUFSIZE )
1538 : 0 : nBufCount = CRYPT_BUFSIZE;
1539 : : else
1540 : 0 : nBufCount = nLen;
1541 : 0 : nLen -= nBufCount;
1542 : 0 : memcpy( pTemp, pDataPtr, (sal_uInt16)nBufCount );
1543 : : // **** Verschluesseln *****
1544 [ # # ]: 0 : for ( sal_uInt16 n=0; n < CRYPT_BUFSIZE; n++ )
1545 : : {
1546 : 0 : unsigned char aCh = pTemp[n];
1547 : 0 : aCh ^= nMask;
1548 : 0 : SWAPNIBBLES(aCh)
1549 : 0 : pTemp[n] = aCh;
1550 : : }
1551 : : // *************************
1552 [ # # ]: 0 : nCount += PutData( (char*)pTemp, nBufCount );
1553 : 0 : pDataPtr += nBufCount;
1554 : : }
1555 : : while ( nLen );
1556 : 0 : return nCount;
1557 : : }
1558 : :
1559 : 0 : sal_Bool SvStream::EncryptBuffer(void* pStart, sal_Size nLen)
1560 : : {
1561 : 0 : unsigned char* pTemp = (unsigned char*)pStart;
1562 : 0 : unsigned char nMask = nCryptMask;
1563 : :
1564 [ # # ]: 0 : for ( sal_Size n=0; n < nLen; n++, pTemp++ )
1565 : : {
1566 : 0 : unsigned char aCh = *pTemp;
1567 : 0 : SWAPNIBBLES(aCh)
1568 : 0 : aCh ^= nMask;
1569 : 0 : *pTemp = aCh;
1570 : : }
1571 : 0 : return sal_True;
1572 : : }
1573 : :
1574 : 15 : unsigned char implGetCryptMask(const sal_Char* pStr, sal_Int32 nLen, long nVersion)
1575 : : {
1576 : 15 : unsigned char nCryptMask = 0;
1577 : :
1578 [ + - ]: 15 : if (!nLen)
1579 : 15 : return nCryptMask;
1580 : :
1581 [ # # ]: 0 : if( nVersion <= SOFFICE_FILEFORMAT_31 )
1582 : : {
1583 [ # # ]: 0 : while( nLen )
1584 : : {
1585 : 0 : nCryptMask ^= *pStr;
1586 : 0 : pStr++;
1587 : 0 : nLen--;
1588 : : }
1589 : : }
1590 : : else // BugFix #25888#
1591 : : {
1592 [ # # ]: 0 : for( sal_uInt16 i = 0; i < nLen; i++ ) {
1593 : 0 : nCryptMask ^= pStr[i];
1594 [ # # ]: 0 : if( nCryptMask & 0x80 ) {
1595 : 0 : nCryptMask <<= 1;
1596 : 0 : nCryptMask++;
1597 : : }
1598 : : else
1599 : 0 : nCryptMask <<= 1;
1600 : : }
1601 : : }
1602 : :
1603 [ # # ]: 0 : if( !nCryptMask )
1604 : 0 : nCryptMask = 67;
1605 : :
1606 : 15 : return nCryptMask;
1607 : : }
1608 : :
1609 : 15 : void SvStream::SetCryptMaskKey(const rtl::OString& rCryptMaskKey)
1610 : : {
1611 : 15 : m_aCryptMaskKey = rCryptMaskKey;
1612 : : nCryptMask = implGetCryptMask(m_aCryptMaskKey.getStr(),
1613 : 15 : m_aCryptMaskKey.getLength(), GetVersion());
1614 : 15 : }
1615 : :
1616 : 576 : void SvStream::SyncSvStream( sal_Size nNewStreamPos )
1617 : : {
1618 : 576 : ClearBuffer();
1619 : 576 : SvStream::nBufFilePos = nNewStreamPos;
1620 : 576 : }
1621 : :
1622 : 576 : void SvStream::SyncSysStream()
1623 : : {
1624 : 576 : Flush();
1625 : 576 : SeekPos( Tell() );
1626 : 576 : }
1627 : :
1628 : 1968 : sal_Bool SvStream::SetStreamSize( sal_Size nSize )
1629 : : {
1630 : : #ifdef DBG_UTIL
1631 : : sal_Size nFPos = Tell();
1632 : : #endif
1633 : 1968 : sal_uInt16 nBuf = nBufSize;
1634 : 1968 : SetBufferSize( 0 );
1635 : 1968 : SetSize( nSize );
1636 : 1968 : SetBufferSize( nBuf );
1637 : : DBG_ASSERT(Tell()==nFPos,"SetStreamSize failed");
1638 : 1968 : return (sal_Bool)(nError == 0);
1639 : : }
1640 : :
1641 : 456689 : SvStream& endl( SvStream& rStr )
1642 : : {
1643 : 456689 : LineEnd eDelim = rStr.GetLineDelimiter();
1644 [ - + ]: 456689 : if ( eDelim == LINEEND_CR )
1645 : 0 : rStr << _CR;
1646 [ + - ]: 456689 : else if( eDelim == LINEEND_LF )
1647 : 456689 : rStr << _LF;
1648 : : else
1649 : 0 : rStr << _CR << _LF;
1650 : 456689 : return rStr;
1651 : : }
1652 : :
1653 : 0 : SvStream& endlu( SvStream& rStrm )
1654 : : {
1655 [ # # # ]: 0 : switch ( rStrm.GetLineDelimiter() )
1656 : : {
1657 : : case LINEEND_CR :
1658 : 0 : rStrm << sal_Unicode(_CR);
1659 : 0 : break;
1660 : : case LINEEND_LF :
1661 : 0 : rStrm << sal_Unicode(_LF);
1662 : 0 : break;
1663 : : default:
1664 : 0 : rStrm << sal_Unicode(_CR) << sal_Unicode(_LF);
1665 : : }
1666 : 0 : return rStrm;
1667 : : }
1668 : :
1669 : 0 : SvStream& endlub( SvStream& rStrm )
1670 : : {
1671 [ # # ]: 0 : if ( rStrm.GetStreamCharSet() == RTL_TEXTENCODING_UNICODE )
1672 : 0 : return endlu( rStrm );
1673 : : else
1674 : 0 : return endl( rStrm );
1675 : : }
1676 : :
1677 : 14232 : SvMemoryStream::SvMemoryStream( void* pBuffer, sal_Size bufSize,
1678 : 14232 : StreamMode eMode )
1679 : : {
1680 [ + + ]: 14232 : if( eMode & STREAM_WRITE )
1681 : 1617 : bIsWritable = sal_True;
1682 : : else
1683 : 12615 : bIsWritable = sal_False;
1684 : 14232 : nEndOfData = bufSize;
1685 : 14232 : bOwnsData = sal_False;
1686 : 14232 : pBuf = (sal_uInt8 *) pBuffer;
1687 : 14232 : nResize = 0L;
1688 : 14232 : nSize = bufSize;
1689 : 14232 : nPos = 0L;
1690 [ + - ]: 14232 : SetBufferSize( 0 );
1691 : 14232 : }
1692 : :
1693 : 39804 : SvMemoryStream::SvMemoryStream( sal_Size nInitSize, sal_Size nResizeOffset )
1694 : : {
1695 : 39804 : bIsWritable = sal_True;
1696 : 39804 : bOwnsData = sal_True;
1697 : 39804 : nEndOfData = 0L;
1698 : 39804 : nResize = nResizeOffset;
1699 : 39804 : nPos = 0;
1700 : 39804 : pBuf = 0;
1701 [ - + ][ + + ]: 39804 : if( nResize != 0 && nResize < 16 )
1702 : 0 : nResize = 16;
1703 [ + + ][ + - ]: 39804 : if( nInitSize && !AllocateMemory( nInitSize ) )
[ - + ][ - + ]
1704 : : {
1705 [ # # ]: 0 : SetError( SVSTREAM_OUTOFMEMORY );
1706 : 0 : nSize = 0;
1707 : : }
1708 : : else
1709 : 39804 : nSize = nInitSize;
1710 [ + - ]: 39804 : SetBufferSize( 64 );
1711 : 39804 : }
1712 : :
1713 : 54027 : SvMemoryStream::~SvMemoryStream()
1714 : : {
1715 [ + + ]: 54027 : if( pBuf )
1716 : : {
1717 [ + + ]: 51583 : if( bOwnsData )
1718 [ + - ]: 37271 : FreeMemory();
1719 : : else
1720 [ + - ]: 14312 : Flush();
1721 : : }
1722 [ - + ]: 71961 : }
1723 : :
1724 : 0 : sal_uInt16 SvMemoryStream::IsA() const
1725 : : {
1726 : 0 : return (sal_uInt16)ID_MEMORYSTREAM;
1727 : : }
1728 : :
1729 : 205 : void* SvMemoryStream::SetBuffer( void* pNewBuf, sal_Size nCount,
1730 : : sal_Bool bOwnsDat, sal_Size nEOF )
1731 : : {
1732 : : void* pResult;
1733 : 205 : SetBufferSize( 0 ); // Buffering in der Basisklasse initialisieren
1734 : 205 : Seek( 0 );
1735 [ + - ]: 205 : if( bOwnsData )
1736 : : {
1737 : 205 : pResult = 0;
1738 [ + - ]: 205 : if( pNewBuf != pBuf )
1739 : 205 : FreeMemory();
1740 : : }
1741 : : else
1742 : 0 : pResult = pBuf;
1743 : :
1744 : 205 : pBuf = (sal_uInt8 *) pNewBuf;
1745 : 205 : nPos = 0;
1746 : 205 : nSize = nCount;
1747 : 205 : nResize = 0;
1748 : 205 : bOwnsData = bOwnsDat;
1749 : :
1750 [ - + ]: 205 : if( nEOF > nCount )
1751 : 0 : nEOF = nCount;
1752 : 205 : nEndOfData = nEOF;
1753 : :
1754 : 205 : ResetError();
1755 : :
1756 : : DBG_ASSERT( nEndOfData<STREAM_SEEK_TO_END,"Invalid EOF");
1757 : 205 : return pResult;
1758 : : }
1759 : :
1760 : 238933 : sal_Size SvMemoryStream::GetData( void* pData, sal_Size nCount )
1761 : : {
1762 : 238933 : sal_Size nMaxCount = nEndOfData-nPos;
1763 [ + + ]: 238933 : if( nCount > nMaxCount )
1764 : 20487 : nCount = nMaxCount;
1765 : 238933 : memcpy( pData, pBuf+nPos, (size_t)nCount );
1766 : 238933 : nPos += nCount;
1767 : 238933 : return nCount;
1768 : : }
1769 : :
1770 : 3155758 : sal_Size SvMemoryStream::PutData( const void* pData, sal_Size nCount )
1771 : : {
1772 [ - + ]: 3155758 : if( GetError() )
1773 : 0 : return 0L;
1774 : :
1775 : 3155758 : sal_Size nMaxCount = nSize-nPos;
1776 : :
1777 : : // check for overflow
1778 [ + + ]: 3155758 : if( nCount > nMaxCount )
1779 : : {
1780 [ - + ]: 6367 : if( nResize == 0 )
1781 : : {
1782 : : // copy as much as possible
1783 : 0 : nCount = nMaxCount;
1784 : 0 : SetError( SVSTREAM_OUTOFMEMORY );
1785 : : }
1786 : : else
1787 : : {
1788 : : long nNewResize;
1789 [ + - ][ + + ]: 6367 : if( nSize && nSize > nResize )
1790 : 5297 : nNewResize = nSize;
1791 : : else
1792 : 1070 : nNewResize = nResize;
1793 : :
1794 [ + + ]: 6367 : if( (nCount-nMaxCount) < nResize )
1795 : : {
1796 : : // lacking memory is smaller than nResize,
1797 : : // resize accordingly
1798 [ - + ]: 3918 : if( !ReAllocateMemory( nNewResize) )
1799 : : {
1800 : 0 : nCount = 0;
1801 : 0 : SetError( SVSTREAM_WRITE_ERROR );
1802 : : }
1803 : : }
1804 : : else
1805 : : {
1806 : : // lacking memory is larger than nResize,
1807 : : // resize by (nCoount-nMaxCount) + resize offset
1808 [ - + ]: 2449 : if( !ReAllocateMemory( nCount-nMaxCount+nNewResize ) )
1809 : : {
1810 : 0 : nCount = 0;
1811 : 0 : SetError( SVSTREAM_WRITE_ERROR );
1812 : : }
1813 : : }
1814 : : }
1815 : : }
1816 : : DBG_ASSERT(pBuf,"Possibly Reallocate failed");
1817 : 3155758 : memcpy( pBuf+nPos, pData, (size_t)nCount);
1818 : :
1819 : 3155758 : nPos += nCount;
1820 [ + + ]: 3155758 : if( nPos > nEndOfData )
1821 : 1650062 : nEndOfData = nPos;
1822 : 3155758 : return nCount;
1823 : : }
1824 : :
1825 : 6496511 : sal_Size SvMemoryStream::SeekPos( sal_Size nNewPos )
1826 : : {
1827 : : // nEndOfData: First position in stream not allowed to read from
1828 : : // nSize: Size of allocated buffer
1829 : :
1830 [ + + ]: 6496511 : if( nNewPos < nEndOfData )
1831 : 3261678 : nPos = nNewPos;
1832 [ + + ]: 3234833 : else if( nNewPos == STREAM_SEEK_TO_END )
1833 : 40847 : nPos = nEndOfData;
1834 : : else
1835 : : {
1836 [ + + ]: 3193986 : if( nNewPos >= nSize ) // Does buffer need extension?
1837 : : {
1838 [ + + ]: 1291 : if( nResize ) // Is extension possible?
1839 : : {
1840 : 912 : long nDiff = (long)(nNewPos - nSize + 1);
1841 : 912 : nDiff += (long)nResize;
1842 : 912 : ReAllocateMemory( nDiff );
1843 : 912 : nPos = nNewPos;
1844 : 912 : nEndOfData = nNewPos;
1845 : : }
1846 : : else // Extension not possible, set pos to end of data
1847 : : {
1848 : : // SetError( SVSTREAM_OUTOFMEMORY );
1849 : 379 : nPos = nEndOfData;
1850 : : }
1851 : : }
1852 : : else // Expand buffer size
1853 : : {
1854 : 3192695 : nPos = nNewPos;
1855 : 3192695 : nEndOfData = nNewPos;
1856 : : }
1857 : : }
1858 : 6496511 : return nPos;
1859 : : }
1860 : :
1861 : 222258 : void SvMemoryStream::FlushData()
1862 : : {
1863 : 222258 : }
1864 : :
1865 : 232 : void SvMemoryStream::ResetError()
1866 : : {
1867 : 232 : SvStream::ClearError();
1868 : 232 : }
1869 : :
1870 : 37378 : sal_Bool SvMemoryStream::AllocateMemory( sal_Size nNewSize )
1871 : : {
1872 : 37378 : pBuf = new sal_uInt8[nNewSize];
1873 : 37378 : return( pBuf != 0 );
1874 : : }
1875 : :
1876 : : // (using Bozo algorithm)
1877 : 7279 : sal_Bool SvMemoryStream::ReAllocateMemory( long nDiff )
1878 : : {
1879 : 7279 : sal_Bool bRetVal = sal_False;
1880 : 7279 : long nTemp = (long)nSize;
1881 : 7279 : nTemp += nDiff;
1882 : 7279 : sal_Size nNewSize = (sal_Size)nTemp;
1883 : :
1884 [ + - ]: 7279 : if( nNewSize )
1885 : : {
1886 : 7279 : sal_uInt8* pNewBuf = new sal_uInt8[nNewSize];
1887 : :
1888 [ + - ]: 7279 : if( pNewBuf )
1889 : : {
1890 : 7279 : bRetVal = sal_True; // Success!
1891 [ - + ]: 7279 : if( nNewSize < nSize ) // Are we shrinking?
1892 : : {
1893 : 0 : memcpy( pNewBuf, pBuf, (size_t)nNewSize );
1894 [ # # ]: 0 : if( nPos > nNewSize )
1895 : 0 : nPos = 0L;
1896 [ # # ]: 0 : if( nEndOfData >= nNewSize )
1897 : 0 : nEndOfData = nNewSize-1L;
1898 : : }
1899 : : else
1900 : : {
1901 : 7279 : memcpy( pNewBuf, pBuf, (size_t)nSize );
1902 : : }
1903 : :
1904 : 7279 : FreeMemory();
1905 : :
1906 : 7279 : pBuf = pNewBuf;
1907 : 7279 : nSize = nNewSize;
1908 : : }
1909 : : }
1910 : : else
1911 : : {
1912 : 0 : bRetVal = sal_True;
1913 : 0 : FreeMemory();
1914 : 0 : pBuf = 0;
1915 : 0 : nSize = 0;
1916 : 0 : nEndOfData = 0;
1917 : 0 : nPos = 0;
1918 : : }
1919 : :
1920 : 7279 : return bRetVal;
1921 : : }
1922 : :
1923 : 44755 : void SvMemoryStream::FreeMemory()
1924 : : {
1925 [ + - ]: 44755 : delete[] pBuf;
1926 : 44755 : }
1927 : :
1928 : 18 : void* SvMemoryStream::SwitchBuffer( sal_Size nInitSize, sal_Size nResizeOffset)
1929 : : {
1930 : 18 : Flush();
1931 [ - + ]: 18 : if( !bOwnsData )
1932 : 0 : return 0;
1933 : 18 : Seek( STREAM_SEEK_TO_BEGIN );
1934 : :
1935 : 18 : void* pRetVal = pBuf;
1936 : 18 : pBuf = 0;
1937 : 18 : nEndOfData = 0L;
1938 : 18 : nResize = nResizeOffset;
1939 : 18 : nPos = 0;
1940 : :
1941 [ - + ][ + - ]: 18 : if( nResize != 0 && nResize < 16 )
1942 : 0 : nResize = 16;
1943 : :
1944 : 18 : ResetError();
1945 : :
1946 [ - + ][ - + ]: 18 : if( nInitSize && !AllocateMemory(nInitSize) )
[ + - ]
1947 : : {
1948 : 0 : SetError( SVSTREAM_OUTOFMEMORY );
1949 : 0 : nSize = 0;
1950 : : }
1951 : : else
1952 : 18 : nSize = nInitSize;
1953 : :
1954 : 18 : SetBufferSize( 64 );
1955 : 18 : return pRetVal;
1956 : : }
1957 : :
1958 : 0 : void SvMemoryStream::SetSize( sal_Size nNewSize )
1959 : : {
1960 : 0 : long nDiff = (long)nNewSize - (long)nSize;
1961 : 0 : ReAllocateMemory( nDiff );
1962 : 0 : }
1963 : :
1964 [ # # ]: 0 : TYPEINIT0 ( SvDataCopyStream )
1965 : :
1966 : 0 : void SvDataCopyStream::Assign( const SvDataCopyStream& )
1967 : : {
1968 : 0 : }
1969 : :
1970 : : //Create a OString of nLen bytes from rStream
1971 : 291451 : rtl::OString read_uInt8s_ToOString(SvStream& rStrm, sal_Size nLen)
1972 : : {
1973 : : using comphelper::string::rtl_string_alloc;
1974 : :
1975 : 291451 : rtl_String *pStr = NULL;
1976 [ + + ]: 291451 : if (nLen)
1977 : : {
1978 [ + - ]: 171288 : nLen = std::min(nLen, static_cast<sal_Size>(SAL_MAX_INT32));
1979 : : //alloc a (ref-count 1) rtl_String of the desired length.
1980 : : //rtl_String's buffer is uninitialized, except for null termination
1981 : 171288 : pStr = rtl_string_alloc(sal::static_int_cast<sal_Int32>(nLen));
1982 : 171288 : sal_Size nWasRead = rStrm.Read(pStr->buffer, nLen);
1983 [ + + ]: 171288 : if (nWasRead != nLen)
1984 : : {
1985 : : //on (typically unlikely) short read set length to what we could
1986 : : //read, and null terminate. Excess buffer capacity remains of
1987 : : //course, could create a (true) replacement OString if it matters.
1988 : 12 : pStr->length = sal::static_int_cast<sal_Int32>(nWasRead);
1989 : 12 : pStr->buffer[pStr->length] = 0;
1990 : : }
1991 : : }
1992 : :
1993 : : //take ownership of buffer and return, otherwise return empty string
1994 [ + + ]: 291451 : return pStr ? rtl::OString(pStr, SAL_NO_ACQUIRE) : rtl::OString();
1995 : : }
1996 : :
1997 : : //Create a OUString of nLen sal_Unicodes from rStream
1998 : 99968 : rtl::OUString read_uInt16s_ToOUString(SvStream& rStrm, sal_Size nLen)
1999 : : {
2000 : : using comphelper::string::rtl_uString_alloc;
2001 : :
2002 : 99968 : rtl_uString *pStr = NULL;
2003 [ + + ]: 99968 : if (nLen)
2004 : : {
2005 [ + - ]: 97388 : nLen = std::min(nLen, static_cast<sal_Size>(SAL_MAX_INT32));
2006 : : //alloc a (ref-count 1) rtl_uString of the desired length.
2007 : : //rtl_String's buffer is uninitialized, except for null termination
2008 : 97388 : pStr = rtl_uString_alloc(sal::static_int_cast<sal_Int32>(nLen));
2009 : 97388 : sal_Size nWasRead = rStrm.Read(pStr->buffer, nLen*2)/2;
2010 [ + + ]: 97388 : if (nWasRead != nLen)
2011 : : {
2012 : : //on (typically unlikely) short read set length to what we could
2013 : : //read, and null terminate. Excess buffer capacity remains of
2014 : : //course, could create a (true) replacement OUString if it matters.
2015 : 12 : pStr->length = sal::static_int_cast<sal_Int32>(nWasRead);
2016 : 12 : pStr->buffer[pStr->length] = 0;
2017 : : }
2018 [ - + ]: 97388 : if (rStrm.IsEndianSwap())
2019 : : {
2020 [ # # ]: 0 : for (sal_Int32 i = 0; i < pStr->length; ++i)
2021 : 0 : pStr->buffer[i] = OSL_SWAPWORD(pStr->buffer[i]);
2022 : : }
2023 : : }
2024 : :
2025 : : //take ownership of buffer and return, otherwise return empty string
2026 [ + + ]: 99968 : return pStr ? rtl::OUString(pStr, SAL_NO_ACQUIRE) : rtl::OUString();
2027 : : }
2028 : :
2029 : : namespace
2030 : : {
2031 : 82158 : template <typename T, typename O> T tmpl_convertLineEnd(const T &rIn, LineEnd eLineEnd)
2032 : : {
2033 : : // Determine linebreaks and compute length
2034 : 82158 : bool bConvert = false; // Needs conversion
2035 : 82158 : sal_Int32 nStrLen = rIn.getLength();
2036 [ - + ][ - + ]: 82158 : sal_Int32 nLineEndLen = (eLineEnd == LINEEND_CRLF) ? 2 : 1;
2037 : 82158 : sal_Int32 nLen = 0; // Target length
2038 : 82158 : sal_Int32 i = 0; // Source counter
2039 : :
2040 [ + + ][ + + ]: 472779 : while (i < nStrLen)
2041 : : {
2042 : : // \r or \n causes linebreak
2043 [ + + ][ + + ]: 390621 : if ( (rIn[i] == _CR) || (rIn[i] == _LF) )
[ + + ][ + - ]
[ - + ][ - + ]
2044 : : {
2045 : 2965 : nLen = nLen + nLineEndLen;
2046 : :
2047 : : // If set already, skip expensive test
2048 [ + + ][ # # ]: 2965 : if ( !bConvert )
2049 : : {
2050 : : // Muessen wir Konvertieren
2051 [ - + ][ # # ]: 2778 : if ( ((eLineEnd != LINEEND_LF) && (rIn[i] == _LF)) ||
[ - + ][ # # ]
[ + - ][ + + ]
[ + - ][ - + ]
[ # # ][ # # ]
[ + + ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
2052 : : ((eLineEnd == LINEEND_CRLF) && (rIn[i+1] != _LF)) ||
2053 : : ((eLineEnd == LINEEND_LF) &&
2054 : : ((rIn[i] == _CR) || (rIn[i+1] == _CR))) ||
2055 : : ((eLineEnd == LINEEND_CR) &&
2056 : : ((rIn[i] == _LF) || (rIn[i+1] == _LF))) )
2057 : 1041 : bConvert = true;
2058 : : }
2059 : :
2060 : : // skip char if \r\n oder \n\r
2061 [ + - ][ + + ]: 2965 : if ( ((rIn[i+1] == _CR) || (rIn[i+1] == _LF)) &&
[ - + ][ - + ]
[ # # ][ # # ]
[ # # ][ # # ]
2062 : : (rIn[i] != rIn[i+1]) )
2063 : 0 : ++i;
2064 : : }
2065 : : else
2066 : 387656 : ++nLen;
2067 : 390621 : ++i;
2068 : : }
2069 : :
2070 [ + + ][ + - ]: 82158 : if (!bConvert)
2071 : 81117 : return rIn;
2072 : :
2073 : : // convert linebreaks, insert string
2074 : 1041 : O aNewData(nLen);
2075 : 1041 : i = 0;
2076 [ + + ][ # # ]: 2730 : while (i < nStrLen)
2077 : : {
2078 : : // \r or \n causes linebreak
2079 [ + + ][ - + ]: 1689 : if ( (rIn[i] == _CR) || (rIn[i] == _LF) )
[ + + ][ # # ]
[ # # ][ # # ]
2080 : : {
2081 [ - + ][ # # ]: 1228 : if ( eLineEnd == LINEEND_CRLF )
2082 : : {
2083 [ # # ][ # # ]: 0 : aNewData.append(_CR);
2084 [ # # ][ # # ]: 0 : aNewData.append(_LF);
2085 : : }
2086 : : else
2087 : : {
2088 [ - + ][ # # ]: 1228 : if ( eLineEnd == LINEEND_CR )
2089 [ # # ][ # # ]: 0 : aNewData.append(_CR);
2090 : : else
2091 [ + - ][ # # ]: 1228 : aNewData.append(_LF);
2092 : : }
2093 : :
2094 [ + - ][ - + ]: 1228 : if ( ((rIn[i+1] == _CR) || (rIn[i+1] == _LF)) &&
[ # # ][ - + ]
[ # # ][ # # ]
[ # # ][ # # ]
2095 : : (rIn[i] != rIn[i+1]) )
2096 : 0 : ++i;
2097 : : }
2098 : : else
2099 : : {
2100 [ + - ][ # # ]: 461 : aNewData.append(rIn[i]);
2101 : : }
2102 : :
2103 : 1689 : ++i;
2104 : : }
2105 : :
2106 [ + - ]: 82158 : return aNewData.makeStringAndClear();
2107 : : }
2108 : : }
2109 : :
2110 : 184 : rtl::OString convertLineEnd(const rtl::OString &rIn, LineEnd eLineEnd)
2111 : : {
2112 : 184 : return tmpl_convertLineEnd<rtl::OString, rtl::OStringBuffer>(rIn, eLineEnd);
2113 : : }
2114 : :
2115 : 81974 : rtl::OUString convertLineEnd(const rtl::OUString &rIn, LineEnd eLineEnd)
2116 : : {
2117 : 81974 : return tmpl_convertLineEnd<rtl::OUString, rtl::OUStringBuffer>(rIn, eLineEnd);
2118 : : }
2119 : :
2120 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|