HooverChessUtils_PgnReader 0.9.0
Loading...
Searching...
No Matches
stringbuilder.h
Go to the documentation of this file.
1// Hoover Chess Utilities / PGN reader
2// Copyright (C) 2023-2025 Sami Kiminki
3//
4// This program is free software: you can redistribute it and/or modify
5// it under the terms of the GNU General Public License as published by
6// the Free Software Foundation, either version 3 of the License, or
7// (at your option) any later version.
8//
9// This program is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12// GNU General Public License for more details.
13//
14// You should have received a copy of the GNU General Public License
15// along with this program. If not, see <https://www.gnu.org/licenses/>.
16
17#ifndef HOOVER_CHESS_UTILS__PGN_READER__STRINGBUILDER_H_INCLUDED
18#define HOOVER_CHESS_UTILS__PGN_READER__STRINGBUILDER_H_INCLUDED
19
20#include <cstddef>
21#include <string_view>
22
23
25{
26
28{
29private:
30 char *m_buf { };
31 char *m_strEnd { };
32 char *m_bufEnd { };
33
34 void growAndAppend(const char *str, std::size_t len);
35
36 bool hasRoom(std::size_t newChars) const
37 {
38 return m_strEnd + newChars <= m_bufEnd;
39 }
40
41public:
42 static constexpr std::size_t ctDynamicAllocBase { 4096 };
43 static constexpr std::size_t ctDynamicGrowthFactor { 2 };
44
46
48
49 bool isEmpty() const noexcept
50 {
51 return m_buf == m_strEnd;
52 }
53
54 std::string_view getStringView() const noexcept
55 {
56 return std::string_view { m_buf, m_strEnd };
57 }
58
59 void clear() noexcept
60 {
62 }
63
64 void pushBack(char c);
65
66 void appendString(const char *str, std::size_t len);
67
68};
69
70}
71#endif
void appendString(const char *str, std::size_t len)
void clear() noexcept
Definition stringbuilder.h:59
bool hasRoom(std::size_t newChars) const
Definition stringbuilder.h:36
char * m_buf
Definition stringbuilder.h:30
std::string_view getStringView() const noexcept
Definition stringbuilder.h:54
char * m_bufEnd
Definition stringbuilder.h:32
bool isEmpty() const noexcept
Definition stringbuilder.h:49
char * m_strEnd
Definition stringbuilder.h:31
static constexpr std::size_t ctDynamicGrowthFactor
Definition stringbuilder.h:43
void growAndAppend(const char *str, std::size_t len)
static constexpr std::size_t ctDynamicAllocBase
Definition stringbuilder.h:42
Definition chessboard-types-squareset.h:30