diff --git a/doc/xml/release.xml b/doc/xml/release.xml index 0d18656fb..8814d0e49 100644 --- a/doc/xml/release.xml +++ b/doc/xml/release.xml @@ -74,6 +74,10 @@

Add lstInsert() to List object.

+ +

Add strCatChr() to String object.

+
+ diff --git a/src/common/type/string.c b/src/common/type/string.c index 6af5c2849..473068073 100644 --- a/src/common/type/string.c +++ b/src/common/type/string.c @@ -221,6 +221,33 @@ strCat(String *this, const char *cat) FUNCTION_TEST_RESULT(STRING, this); } +/*********************************************************************************************************************************** +Append a character +***********************************************************************************************************************************/ +String * +strCatChr(String *this, char cat) +{ + FUNCTION_TEST_BEGIN(); + FUNCTION_TEST_PARAM(STRING, this); + FUNCTION_TEST_PARAM(CHAR, cat); + + FUNCTION_TEST_ASSERT(this != NULL); + FUNCTION_TEST_ASSERT(cat != 0); + FUNCTION_TEST_END(); + + // Allocate and append character + MEM_CONTEXT_BEGIN(this->memContext) + { + this->buffer = memGrowRaw(this->buffer, this->size + 2); + } + MEM_CONTEXT_END(); + + this->buffer[this->size++] = cat; + this->buffer[this->size] = 0; + + FUNCTION_TEST_RESULT(STRING, this); +} + /*********************************************************************************************************************************** Append a formatted string ***********************************************************************************************************************************/ diff --git a/src/common/type/string.h b/src/common/type/string.h index 5c9863752..104dfd341 100644 --- a/src/common/type/string.h +++ b/src/common/type/string.h @@ -23,6 +23,7 @@ String *strBase(const String *this); bool strBeginsWith(const String *this, const String *beginsWith); bool strBeginsWithZ(const String *this, const char *beginsWith); String *strCat(String *this, const char *cat); +String *strCatChr(String *this, char cat); String *strCatFmt(String *this, const char *format, ...) __attribute__((format(printf, 2, 3))); int strCmp(const String *this, const String *compare); int strCmpZ(const String *this, const char *compare); diff --git a/test/src/module/common/typeStringTest.c b/test/src/module/common/typeStringTest.c index 5e496bdc9..20126a1d9 100644 --- a/test/src/module/common/typeStringTest.c +++ b/test/src/module/common/typeStringTest.c @@ -56,21 +56,16 @@ testRun(void) } // ***************************************************************************************************************************** - if (testBegin("strCat() and strCatFmt()")) + if (testBegin("strCat(), strCatChr(), and strCatFmt()")) { String *string = strNew("XXXX"); String *string2 = strNew("ZZZZ"); - strCat(string, "YYYY"); - TEST_RESULT_STR(strPtr(string), "XXXXYYYY", "cat string"); - - strCatFmt(string, "%05d", 777); - TEST_RESULT_STR(strPtr(string), "XXXXYYYY00777", "cat formatted string"); + TEST_RESULT_STR(strPtr(strCat(string, "YYYY")), "XXXXYYYY", "cat string"); + TEST_RESULT_STR(strPtr(strCatFmt(string, "%05d", 777)), "XXXXYYYY00777", "cat formatted string"); + TEST_RESULT_STR(strPtr(strCatChr(string, '!')), "XXXXYYYY00777!", "cat chr"); TEST_RESULT_STR(strPtr(string2), "ZZZZ", "check unaltered string"); - - strFree(string); - strFree(string2); } // *****************************************************************************************************************************