mirror of
https://github.com/OpenRCT2/OpenRCT2
synced 2026-01-26 08:14:38 +01:00
Split declarations and definitions to improve compile times when editing (#13332)
* Split FileStream declarations and definitions * Split JobPool declarations and definitions * Split StringBuilder declarations and definitions * Split StringReader declarations and definitions * Split ZoomLevel declarations and definitions * Fix missing include in FileClassifier.cpp * Remove pragma once from source files * Fix missing include in StringBuilder.h * Update Xcode project * Fix compilation of tests Co-authored-by: Michael Steenbeek <m.o.steenbeek@gmail.com>
This commit is contained in:
72
src/openrct2/core/StringBuilder.cpp
Normal file
72
src/openrct2/core/StringBuilder.cpp
Normal file
@@ -0,0 +1,72 @@
|
||||
/*****************************************************************************
|
||||
* Copyright (c) 2014-2020 OpenRCT2 developers
|
||||
*
|
||||
* For a complete list of all authors, please refer to contributors.md
|
||||
* Interested in contributing? Visit https://github.com/OpenRCT2/OpenRCT2
|
||||
*
|
||||
* OpenRCT2 is licensed under the GNU General Public License version 3.
|
||||
*****************************************************************************/
|
||||
|
||||
#include "StringBuilder.h"
|
||||
|
||||
#include "String.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
#include <iterator>
|
||||
|
||||
StringBuilder::StringBuilder(size_t capacity)
|
||||
{
|
||||
_buffer.reserve(capacity);
|
||||
}
|
||||
|
||||
void StringBuilder::Append(int32_t codepoint)
|
||||
{
|
||||
Append(static_cast<codepoint_t>(codepoint));
|
||||
}
|
||||
|
||||
void StringBuilder::Append(codepoint_t codepoint)
|
||||
{
|
||||
size_t codepointLength = String::GetCodepointLength(codepoint);
|
||||
std::basic_string<utf8> data(codepointLength, {});
|
||||
String::WriteCodepoint(data.data(), codepoint);
|
||||
_buffer.insert(_buffer.end(), data.begin(), data.end());
|
||||
}
|
||||
|
||||
void StringBuilder::Append(const utf8* text)
|
||||
{
|
||||
size_t textLength = String::SizeOf(text);
|
||||
Append(text, textLength);
|
||||
}
|
||||
|
||||
void StringBuilder::Append(const utf8* text, size_t textLength)
|
||||
{
|
||||
_buffer.insert(_buffer.end(), text, text + textLength);
|
||||
}
|
||||
|
||||
void StringBuilder::Append(const StringBuilder* sb)
|
||||
{
|
||||
Append(sb->GetBuffer(), sb->GetLength());
|
||||
}
|
||||
|
||||
void StringBuilder::Clear()
|
||||
{
|
||||
_buffer.clear();
|
||||
}
|
||||
|
||||
std::string StringBuilder::GetStdString() const
|
||||
{
|
||||
return std::string(GetBuffer(), GetLength());
|
||||
}
|
||||
|
||||
const utf8* StringBuilder::GetBuffer() const
|
||||
{
|
||||
// buffer may be empty, so return an immutable empty string
|
||||
if (_buffer.empty())
|
||||
return "";
|
||||
return _buffer.c_str();
|
||||
}
|
||||
|
||||
size_t StringBuilder::GetLength() const
|
||||
{
|
||||
return _buffer.size();
|
||||
}
|
||||
Reference in New Issue
Block a user