blob: 6815d71b814774c1e7b706f800f66dac9112ffbf (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#include "orcus/cell_buffer.hpp"
#include <cstring>
#define ORCUS_DEBUG_CELL_BUFFER 0
#if ORCUS_DEBUG_CELL_BUFFER
#include <iostream>
using std::cout;
using std::endl;
#endif
namespace orcus {
cell_buffer::cell_buffer() : m_buf_size(0) {}
cell_buffer::~cell_buffer() = default;
void cell_buffer::append(const char* p, size_t len)
{
if (!len)
return;
#if ORCUS_DEBUG_CELL_BUFFER
cout << "cell_buffer::append: '" << std::string(p, len) << "'" << endl;
#endif
size_t size_needed = m_buf_size + len;
if (m_buffer.size() < size_needed)
m_buffer.resize(size_needed);
char* p_dest = &m_buffer[m_buf_size];
std::strncpy(p_dest, p, len);
m_buf_size += len;
}
void cell_buffer::reset()
{
m_buf_size = 0;
}
std::string_view cell_buffer::str() const
{
return std::string_view{m_buffer.data(), m_buf_size};
}
bool cell_buffer::empty() const
{
return m_buf_size == 0;
}
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|