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