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