1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 .
21 #include <dbgoutsw.hxx>
22 #include "WW8Sttbf.hxx"
23 #include "ww8scan.hxx"
25 #include <osl/endian.h>
26 #include <rtl/ustrbuf.hxx>
28 #if OSL_DEBUG_LEVEL > 1
34 WW8Struct::WW8Struct(SvStream
& rSt
, sal_uInt32 nPos
, sal_uInt32 nSize
)
35 : mn_offset(0), mn_size(0)
37 if (checkSeek(rSt
, nPos
))
39 mp_data
.reset(new sal_uInt8
[nSize
]);
40 mn_size
= rSt
.Read(mp_data
.get(), nSize
);
42 OSL_ENSURE(mn_size
== nSize
, "short read in WW8Struct::WW8Struct");
45 WW8Struct::WW8Struct(WW8Struct
* pStruct
, sal_uInt32 nPos
, sal_uInt32 nSize
)
46 : mp_data(pStruct
->mp_data
), mn_offset(pStruct
->mn_offset
+ nPos
)
51 WW8Struct::~WW8Struct()
55 sal_uInt8
WW8Struct::getU8(sal_uInt32 nOffset
)
57 sal_uInt8 nResult
= 0;
59 if (nOffset
< mn_size
)
61 nResult
= mp_data
[mn_offset
+ nOffset
];
67 OUString
WW8Struct::getUString(sal_uInt32 nOffset
,
75 sal_uInt32 nStartOff
= mn_offset
+ nOffset
;
76 if (nStartOff
>= mn_size
)
78 sal_uInt32 nAvailable
= (mn_size
- nStartOff
)/sizeof(sal_Unicode
);
79 if (nCount
> nAvailable
)
81 #if defined OSL_LITENDIAN
82 aResult
= OUString(reinterpret_cast<const sal_Unicode
*>(
83 mp_data
.get() + nStartOff
), nCount
);
86 for (sal_uInt32 i
= 0; i
< nCount
; ++i
)
87 aBuf
.append(static_cast<sal_Unicode
>(getU16(nStartOff
+i
*2)));
88 aResult
= aBuf
.makeStringAndClear();
92 SAL_INFO( "sw.ww8.level2", "<WW8Struct-getUString" << " offset=\"" << nOffset
93 << "\" count=\"" << nCount
<< "\"" << ">" << aResult
<< "</WW8Struct-getUString>" );
99 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */