1

add overloads for bse::string

This commit is contained in:
2022-07-24 00:08:22 +02:00
parent 4aa6d089ca
commit 520445b66e
10 changed files with 84 additions and 48 deletions

View File

@ -23,6 +23,7 @@
#define __OutStream_include__
#include "lib/StringBuffer.h"
#include "user/lib/String.h"
// Some basic width formatting
class fillw {
@ -82,14 +83,21 @@ public:
// Darstellung einer nullterminierten Zeichenkette
template<typename T>
friend T& operator<<(T& os, char* string) {
char* pos = string;
friend T& operator<<(T& os, const char* string) {
const char* pos = string;
while (*pos) {
os.put(*pos);
pos++;
}
os.fill_finalize(); // NOTE: I added this
os.fill_finalize();
return os;
}
// Can not use this exclusively for strings as these are heap allocated
template<typename T>
friend T& operator<<(T& os, const bse::string& string) {
os << (const char*)string;
return os;
}

View File

@ -31,7 +31,7 @@
void StringBuffer::put(char c) {
buffer[pos] = c;
pos++;
if (pos == sizeof(buffer)) {
if (pos == buffer.size()) {
flush();
}
}

View File

@ -18,8 +18,9 @@
#ifndef __StringBuffer_include__
#define __StringBuffer_include__
class StringBuffer {
#include "user/lib/Array.h"
class StringBuffer {
private:
StringBuffer(const StringBuffer& copy); // Verhindere Kopieren
@ -30,13 +31,12 @@ private:
// werden und kann dann auch public werden.
protected:
char buffer[80];
bse::array<char, 80> buffer;
int pos;
// StringBuffer: Im Konstruktor wird der Puffer als leer markiert.
StringBuffer() : pos(0) {}
// NOTE: I changed this
// Fuegt ein Zeichen in den Puffer ein. Wenn der Puffer
virtual void put(char c);