~ubuntu-branches/ubuntu/saucy/libwpd/saucy-proposed

« back to all changes in this revision

Viewing changes to src/lib/WPXBinaryData.cpp

  • Committer: Package Import Robot
  • Author(s): Rene Engelhard
  • Date: 2011-11-29 23:31:13 UTC
  • mfrom: (1.2.5)
  • Revision ID: package-import@ubuntu.com-20111129233113-xdtwca9h0y6wdxst
Tags: 0.9.4-1
New upstream release

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
1
2
/* libwpd
2
3
 * Copyright (C) 2007 Fridrich Strba (fridrich.strba@bluewin.ch)
3
4
 *
35
36
{
36
37
public:
37
38
        WPXBinaryDataImpl() : m_buf(), m_stream(NULL) {}
38
 
        ~WPXBinaryDataImpl() { if (m_stream) delete m_stream; }
 
39
        ~WPXBinaryDataImpl()
 
40
        {
 
41
                if (m_stream) delete m_stream;
 
42
        }
39
43
        std::vector<unsigned char> m_buf;
40
44
        WPXMemoryInputStream *m_stream;
 
45
private:
 
46
        // Unimplemented to prevent compiler from creating crasher ones
 
47
        WPXBinaryDataImpl(const WPXBinaryDataImpl &);
 
48
        WPXBinaryDataImpl &operator=(const WPXBinaryDataImpl &);
41
49
};
42
50
 
43
51
WPXBinaryData::~WPXBinaryData()
91
99
}
92
100
 
93
101
unsigned long WPXBinaryData::size() const
94
 
95
 
        return (unsigned long)m_binaryDataImpl->m_buf.size(); 
 
102
{
 
103
        return (unsigned long)m_binaryDataImpl->m_buf.size();
96
104
}
97
105
 
98
 
WPXBinaryData& WPXBinaryData::operator=(const WPXBinaryData &dataBuf)
 
106
WPXBinaryData &WPXBinaryData::operator=(const WPXBinaryData &dataBuf)
99
107
{
100
108
        m_binaryDataImpl->m_buf = dataBuf.m_binaryDataImpl->m_buf;
101
109
        return *this;
102
110
}
103
111
 
104
 
const unsigned char * WPXBinaryData::getDataBuffer() const
 
112
const unsigned char *WPXBinaryData::getDataBuffer() const
105
113
{
106
114
        return &(m_binaryDataImpl->m_buf[0]);
107
115
}
108
116
 
109
117
const WPXString WPXBinaryData::getBase64Data() const
110
118
{
111
 
        static const char* base64Chars =
112
 
                "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
 
119
        static const char *base64Chars =
 
120
            "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
113
121
        char tempCharsToEncode[3];
114
122
        const long len = size();
115
 
        long i = 0; unsigned j = 0; long modifiedLen;
 
123
        long i = 0;
 
124
        unsigned j = 0;
 
125
        long modifiedLen;
116
126
        if (len % 3)
117
127
                modifiedLen = 3 * ((long)(len / 3) + 1);
118
128
        else
119
129
                modifiedLen = len;
120
 
        
 
130
 
121
131
        bool shouldIexit = false;
122
 
        WPXString base64;       
 
132
        WPXString base64;
123
133
        for (; i < modifiedLen; i++)
124
134
        {
125
135
                if (i < len)
144
154
                        {
145
155
                                base64.append(base64Chars[(tempCharsToEncode[0] & 0xfc) >> 2]);
146
156
                                base64.append(base64Chars[((tempCharsToEncode[0] & 0x03) << 4) | ((tempCharsToEncode[1] & 0xf0) >> 4)]);
147
 
                                base64.append('='); base64.append('=');
 
157
                                base64.append('=');
 
158
                                base64.append('=');
148
159
                                break;
149
160
                        }
150
161
                }
160
171
        return base64;
161
172
}
162
173
 
163
 
const WPXInputStream* WPXBinaryData::getDataStream() const
 
174
const WPXInputStream *WPXBinaryData::getDataStream() const
164
175
{
165
176
        if (m_binaryDataImpl->m_stream)
166
177
                delete (m_binaryDataImpl->m_stream);
167
178
        return ((m_binaryDataImpl->m_stream) = new WPXMemoryInputStream(&(m_binaryDataImpl->m_buf[0]), m_binaryDataImpl->m_buf.size()));
168
179
}
 
180
/* vim:set shiftwidth=4 softtabstop=4 noexpandtab: */