LibAC-cpp/src/utils/StringBuilder.cpp
2024-07-30 22:30:55 -07:00

65 lines
1.4 KiB
C++

#include "StringBuilder.h"
#include <string>
#include <sstream>
using namespace std;
namespace libac
{
StringBuilder::StringBuilder() : buffer() {}
bool StringBuilder::isEmpty() const
{
return buffer.empty();
}
void StringBuilder::append(const std::string &value)
{
buffer.append(value);
}
void StringBuilder::clear()
{
buffer.clear();
}
std::string StringBuilder::toString() const
{
return buffer;
}
// Overload operator<< for std::string
StringBuilder& StringBuilder::operator<<(const std::string& value) {
append(value);
return *this;
}
// Overload operator<< for C-style strings
StringBuilder& StringBuilder::operator<<(const char* value) {
append(value);
return *this;
}
// Overload operator<< for single characters
StringBuilder& StringBuilder::operator<<(char value) {
buffer += value;
return *this;
}
// Overload operator<< for integers
StringBuilder& StringBuilder::operator<<(int value) {
std::stringstream oss;
oss << value;
append(oss.str());
return *this;
}
// Overload operator<< for doubles
StringBuilder& StringBuilder::operator<<(double value) {
std::stringstream oss;
oss << value;
append(oss.str());
return *this;
}
}