android: Update app-specific/MIME type icons
[LibreOffice.git] / sw / source / filter / ww8 / WW8Sttbf.cxx
blob3143faece7ddca4dd188a9d8972613315b946566
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 .
20 #include <sal/config.h>
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>
33 namespace ww8
35 WW8Struct::WW8Struct(SvStream& rSt, sal_uInt32 nPos, sal_uInt32 nSize)
36 : mn_offset(0), mn_size(0)
38 if (checkSeek(rSt, nPos))
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);
45 OSL_ENSURE(mn_size == nSize, "short read in WW8Struct::WW8Struct");
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)
54 WW8Struct::~WW8Struct()
58 sal_uInt8 WW8Struct::getU8(sal_uInt32 nOffset)
60 sal_uInt8 nResult = 0;
62 if (nOffset < mn_size)
64 nResult = m_pData.get()[mn_offset + nOffset];
67 return nResult;
70 OUString WW8Struct::getUString(sal_uInt32 nOffset,
71 sal_Int32 nCount)
73 OUString aResult;
75 if (nCount > 0)
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();
90 SAL_INFO( "sw.ww8.level2", "<WW8Struct-getUString offset=\"" << nOffset
91 << "\" count=\"" << nCount << "\">" << aResult << "</WW8Struct-getUString>" );
93 return aResult;
97 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */