LibreOffice Module sw (master)  1
WW8Sttbf.cxx
Go to the documentation of this file.
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 #include <sal/config.h>
21 
22 #include <algorithm>
23 #include <iostream>
24 #include "WW8Sttbf.hxx"
25 #include <osl/endian.h>
26 #include <o3tl/make_shared.hxx>
27 #include <tools/stream.hxx>
28 #include <sal/log.hxx>
29 #include <osl/diagnose.h>
30 
31 #ifdef OSL_BIGENDIAN
32 #include <rtl/ustrbuf.hxx>
33 #endif
34 
35 namespace ww8
36 {
37  WW8Struct::WW8Struct(SvStream& rSt, sal_uInt32 nPos, sal_uInt32 nSize)
38  : mn_offset(0), mn_size(0)
39  {
40  if (checkSeek(rSt, nPos))
41  {
42  std::size_t nRemainingSize = rSt.remainingSize();
43  nSize = std::min<sal_uInt32>(nRemainingSize, nSize);
44  m_pData = o3tl::make_shared_array<sal_uInt8>(nSize);
45  mn_size = rSt.ReadBytes(m_pData.get(), nSize);
46  }
47  OSL_ENSURE(mn_size == nSize, "short read in WW8Struct::WW8Struct");
48  }
49 
50  WW8Struct::WW8Struct(WW8Struct const * pStruct, sal_uInt32 nPos, sal_uInt32 nSize)
51  : m_pData(pStruct->m_pData), mn_offset(pStruct->mn_offset + nPos)
52  , mn_size(nSize)
53  {
54  }
55 
57  {
58  }
59 
60  sal_uInt8 WW8Struct::getU8(sal_uInt32 nOffset)
61  {
62  sal_uInt8 nResult = 0;
63 
64  if (nOffset < mn_size)
65  {
66  nResult = m_pData.get()[mn_offset + nOffset];
67  }
68 
69  return nResult;
70  }
71 
72  OUString WW8Struct::getUString(sal_uInt32 nOffset,
73  sal_uInt32 nCount)
74  {
75  OUString aResult;
76 
77  if (nCount > 0)
78  {
79  //clip to available
80  sal_uInt32 nStartOff = mn_offset + nOffset;
81  if (nStartOff >= mn_size)
82  return aResult;
83  sal_uInt32 nAvailable = (mn_size - nStartOff)/sizeof(sal_Unicode);
84  if (nCount > nAvailable)
85  nCount = nAvailable;
86 #if defined OSL_LITENDIAN
87  aResult = OUString(reinterpret_cast<const sal_Unicode *>(
88  m_pData.get() + nStartOff), nCount);
89 #else
90  OUStringBuffer aBuf;
91  for (sal_uInt32 i = 0; i < nCount; ++i)
92  aBuf.append(static_cast<sal_Unicode>(getU16(nStartOff+i*2)));
93  aResult = aBuf.makeStringAndClear();
94 #endif
95  }
96 
97  SAL_INFO( "sw.ww8.level2", "<WW8Struct-getUString offset=\"" << nOffset
98  << "\" count=\"" << nCount << "\">" << aResult << "</WW8Struct-getUString>" );
99 
100  return aResult;
101 
102  }
103 }
104 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
OUString getUString(sal_uInt32 nOffset, sal_uInt32 nCount)
Definition: WW8Sttbf.cxx:72
std::shared_ptr< sal_uInt8 > m_pData
Definition: WW8Sttbf.hxx:36
aBuf
WW8Struct(SvStream &rSt, sal_uInt32 nPos, sal_uInt32 nSize)
Definition: WW8Sttbf.cxx:37
sal_uInt16 sal_Unicode
FmFilterData * m_pData
sal_uInt64 remainingSize()
bool checkSeek(SvStream &rSt, sal_uInt64 nOffset)
int i
std::size_t ReadBytes(void *pData, std::size_t nSize)
unsigned char sal_uInt8
#define SAL_INFO(area, stream)
sal_uInt16 getU16(sal_uInt32 nOffset)
Definition: WW8Sttbf.hxx:47
sal_uInt32 mn_offset
Definition: WW8Sttbf.hxx:37
sal_uInt8 getU8(sal_uInt32 nOffset)
Definition: WW8Sttbf.cxx:60
virtual ~WW8Struct() override
Definition: WW8Sttbf.cxx:56
sal_uInt32 mn_size
Definition: WW8Sttbf.hxx:38