xref: /AOO42X/main/sw/source/filter/ww8/WW8Sttbf.cxx (revision b1c5455db1639c48e26c568e4fa7ee78ca5d60ee)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #include <iostream>
25 #include <dbgoutsw.hxx>
26 #include "WW8Sttbf.hxx"
27 #include <cstdio>
28 
29 namespace ww8
30 {
WW8Struct(SvStream & rSt,sal_uInt32 nPos,sal_uInt32 nSize)31     WW8Struct::WW8Struct(SvStream& rSt, sal_uInt32 nPos, sal_uInt32 nSize)
32     : mn_offset(0), mn_size(nSize)
33     {
34         rSt.Seek(nPos);
35 
36         mp_data.reset(new sal_uInt8[nSize]);
37         rSt.Read(mp_data.get(), nSize);
38     }
39 
WW8Struct(WW8Struct * pStruct,sal_uInt32 nPos,sal_uInt32 nSize)40     WW8Struct::WW8Struct(WW8Struct * pStruct, sal_uInt32 nPos, sal_uInt32 nSize)
41     : mp_data(pStruct->mp_data), mn_offset(pStruct->mn_offset + nPos),
42     mn_size(nSize)
43     {
44     }
45 
~WW8Struct()46     WW8Struct::~WW8Struct()
47     {
48     }
49 
getU8(sal_uInt32 nOffset)50     sal_uInt8 WW8Struct::getU8(sal_uInt32 nOffset)
51     {
52         sal_uInt8 nResult = 0;
53 
54         if (nOffset < mn_size)
55         {
56             nResult = mp_data[mn_offset + nOffset];
57         }
58 
59         return nResult;
60     }
61 
getUString(sal_uInt32 nOffset,sal_uInt32 nCount)62     ::rtl::OUString WW8Struct::getUString(sal_uInt32 nOffset,
63                                           sal_uInt32 nCount)
64     {
65         ::rtl::OUString aResult;
66 
67         if (nCount > 0)
68         {
69             rtl_uString * pNew = 0;
70             rtl_uString_newFromStr_WithLength
71             (&pNew, reinterpret_cast<const sal_Unicode *>(&mp_data[mn_offset + nOffset]),
72              nCount);
73 
74             aResult = rtl::OUString(pNew);
75         }
76 
77 #ifdef DEBUG
78         char sBuffer[256];
79         snprintf(sBuffer, sizeof(sBuffer), "offset=\"%" SAL_PRIuUINT32 "\" count=\"%" SAL_PRIuUINT32 "\"",
80                  nOffset, nCount);
81         ::std::clog << "<WW8Struct-getUString" << sBuffer << ">"
82                     << dbg_out(aResult) << "</WW8Struct-getUString>"
83                     << ::std::endl;
84 #endif
85 
86         return aResult;
87 
88     }
89 
getString(sal_uInt32 nOffset,sal_uInt32 nCount)90     ::rtl::OUString WW8Struct::getString(sal_uInt32 nOffset,
91                                          sal_uInt32 nCount)
92     {
93         ::rtl::OUString aResult;
94 
95         if (nCount > 0)
96         {
97             ::rtl::OString aOStr(reinterpret_cast<const sal_Char *>(&mp_data[mn_offset + nOffset]),
98                                  nCount);
99             ::rtl::OUString aOUStr(rtl::OStringToOUString(aOStr, RTL_TEXTENCODING_ASCII_US));
100             aResult = rtl::OUString(aOUStr);
101         }
102 
103 #ifdef DEBUG
104         char sBuffer[256];
105         snprintf(sBuffer, sizeof(sBuffer), "offset=\"%" SAL_PRIuUINT32 "\" count=\"%" SAL_PRIuUINT32 "\"",
106                  nOffset, nCount);
107         ::std::clog << "<WW8Struct-getString " << sBuffer << ">"
108                     << dbg_out(aResult) << "</WW8Struct-getUString>"
109                     << ::std::endl;
110 #endif
111 
112         return aResult;
113     }
114 }
115