xref: /aoo4110/main/sw/source/filter/ww8/WW8Sttbf.cxx (revision b1cdbd2c)
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 /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil -*- */
24 
25 #include <iostream>
26 #include <dbgoutsw.hxx>
27 #include "WW8Sttbf.hxx"
28 #include <cstdio>
29 
30 namespace ww8
31 {
WW8Struct(SvStream & rSt,sal_uInt32 nPos,sal_uInt32 nSize)32     WW8Struct::WW8Struct(SvStream& rSt, sal_uInt32 nPos, sal_uInt32 nSize)
33     : mn_offset(0), mn_size(nSize)
34     {
35         rSt.Seek(nPos);
36 
37         mp_data.reset(new sal_uInt8[nSize]);
38         rSt.Read(mp_data.get(), nSize);
39     }
40 
WW8Struct(WW8Struct * pStruct,sal_uInt32 nPos,sal_uInt32 nSize)41     WW8Struct::WW8Struct(WW8Struct * pStruct, sal_uInt32 nPos, sal_uInt32 nSize)
42     : mp_data(pStruct->mp_data), mn_offset(pStruct->mn_offset + nPos),
43     mn_size(nSize)
44     {
45     }
46 
~WW8Struct()47     WW8Struct::~WW8Struct()
48     {
49     }
50 
getU8(sal_uInt32 nOffset)51     sal_uInt8 WW8Struct::getU8(sal_uInt32 nOffset)
52     {
53         sal_uInt8 nResult = 0;
54 
55         if (nOffset < mn_size)
56         {
57             nResult = mp_data[mn_offset + nOffset];
58         }
59 
60         return nResult;
61     }
62 
getUString(sal_uInt32 nOffset,sal_uInt32 nCount)63     ::rtl::OUString WW8Struct::getUString(sal_uInt32 nOffset,
64                                           sal_uInt32 nCount)
65     {
66         ::rtl::OUString aResult;
67 
68         if (nCount > 0)
69         {
70             rtl_uString * pNew = 0;
71             rtl_uString_newFromStr_WithLength
72             (&pNew, reinterpret_cast<const sal_Unicode *>(&mp_data[mn_offset + nOffset]),
73              nCount);
74 
75             aResult = rtl::OUString(pNew);
76         }
77 
78 #ifdef DEBUG
79         char sBuffer[256];
80         snprintf(sBuffer, sizeof(sBuffer), "offset=\"%" SAL_PRIuUINT32 "\" count=\"%" SAL_PRIuUINT32 "\"",
81                  nOffset, nCount);
82         ::std::clog << "<WW8Struct-getUString" << sBuffer << ">"
83                     << dbg_out(aResult) << "</WW8Struct-getUString>"
84                     << ::std::endl;
85 #endif
86 
87         return aResult;
88 
89     }
90 
getString(sal_uInt32 nOffset,sal_uInt32 nCount)91     ::rtl::OUString WW8Struct::getString(sal_uInt32 nOffset,
92                                          sal_uInt32 nCount)
93     {
94         ::rtl::OUString aResult;
95 
96         if (nCount > 0)
97         {
98             ::rtl::OString aOStr(reinterpret_cast<const sal_Char *>(&mp_data[mn_offset + nOffset]),
99                                  nCount);
100             ::rtl::OUString aOUStr(rtl::OStringToOUString(aOStr, RTL_TEXTENCODING_ASCII_US));
101             aResult = rtl::OUString(aOUStr);
102         }
103 
104 #ifdef DEBUG
105         char sBuffer[256];
106         snprintf(sBuffer, sizeof(sBuffer), "offset=\"%" SAL_PRIuUINT32 "\" count=\"%" SAL_PRIuUINT32 "\"",
107                  nOffset, nCount);
108         ::std::clog << "<WW8Struct-getString " << sBuffer << ">"
109                     << dbg_out(aResult) << "</WW8Struct-getUString>"
110                     << ::std::endl;
111 #endif
112 
113         return aResult;
114     }
115 }
116