From 153b34e490032d22fa71a7125fb78a120f9f848d Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Thu, 10 Aug 2023 00:04:24 -0700 Subject: Added some handy operators to Bu::BlobBuilder --- src/unit/blobbuilder.unit | 21 +++++++++++++++++++-- src/unstable/blobbuilder.cpp | 18 ++++++++++++++++++ src/unstable/blobbuilder.h | 3 +++ 3 files changed, 40 insertions(+), 2 deletions(-) diff --git a/src/unit/blobbuilder.unit b/src/unit/blobbuilder.unit index c9480bb..30aece7 100644 --- a/src/unit/blobbuilder.unit +++ b/src/unit/blobbuilder.unit @@ -17,13 +17,11 @@ suite BlobBuilder { test append { - Bu::BlobBuilder a; a.append("a"); a.append("bc"); a += "def"; a.append("abcdef"); - } test appendChar @@ -35,4 +33,23 @@ suite BlobBuilder } unitTest( a.getBlob() == "AAAAAAAAAAAAAAAAAAAA" ); } + + test operators1 + { + Bu::BlobBuilder a; + + a << "Hello" << " " << Bu::Blob("there") << " how are you?"; + unitTest( a.getBlob() == "Hello there how are you?" ); + } + + test operators2 + { + Bu::BlobBuilder a; + + a += "Hello"; + a += " "; + a += Bu::Blob("there"); + a += " how are you?"; + unitTest( a.getBlob() == "Hello there how are you?" ); + } } diff --git a/src/unstable/blobbuilder.cpp b/src/unstable/blobbuilder.cpp index 901c72e..3c55e3c 100644 --- a/src/unstable/blobbuilder.cpp +++ b/src/unstable/blobbuilder.cpp @@ -396,3 +396,21 @@ Bu::BlobBuilder &Bu::BlobBuilder::operator+=( const char chr ) return *this; } +Bu::BlobBuilder &Bu::BlobBuilder::operator<<( const Blob &rSrc ) +{ + append( rSrc ); + return *this; +} + +Bu::BlobBuilder &Bu::BlobBuilder::operator<<( const char *pSrc ) +{ + append( pSrc ); + return *this; +} + +Bu::BlobBuilder &Bu::BlobBuilder::operator<<( const char chr ) +{ + append( chr ); + return *this; +} + diff --git a/src/unstable/blobbuilder.h b/src/unstable/blobbuilder.h index 7ad4255..fd368fa 100644 --- a/src/unstable/blobbuilder.h +++ b/src/unstable/blobbuilder.h @@ -120,6 +120,9 @@ namespace Bu BlobBuilder &operator+=( const Blob &rSrc ); BlobBuilder &operator+=( const char *pSrc ); BlobBuilder &operator+=( const char chr ); + BlobBuilder &operator<<( const Blob &rSrc ); + BlobBuilder &operator<<( const char *pSrc ); + BlobBuilder &operator<<( const char chr ); private: }; }; -- cgit v1.2.3