diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-15 05:48:59 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-15 05:48:59 +0000 |
commit | c484829272cd13a738e35412498e12f2c9a194ac (patch) | |
tree | a1f5ec09629ee895bd3963fa8820b45f2f4c574b /src/parser/cell_buffer.cpp | |
parent | Initial commit. (diff) | |
download | liborcus-f5bf3877c7cf3538ca1337452cf57cc99b0ace0e.tar.xz liborcus-f5bf3877c7cf3538ca1337452cf57cc99b0ace0e.zip |
Adding upstream version 0.19.2.upstream/0.19.2upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/parser/cell_buffer.cpp')
-rw-r--r-- | src/parser/cell_buffer.cpp | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/src/parser/cell_buffer.cpp b/src/parser/cell_buffer.cpp new file mode 100644 index 0000000..6815d71 --- /dev/null +++ b/src/parser/cell_buffer.cpp @@ -0,0 +1,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: */ |