1
0
mirror of https://github.com/pgbackrest/pgbackrest.git synced 2024-12-14 10:13:05 +02:00

Add strCatChr() to String object.

This commit is contained in:
David Steele 2018-11-09 09:54:55 -05:00
parent 3e695af961
commit b5a3c8c84b
4 changed files with 36 additions and 9 deletions

View File

@ -74,6 +74,10 @@
<p>Add <code>lstInsert()</code> to <code>List</code> object.</p>
</release-item>
<release-item>
<p>Add <code>strCatChr()</code> to <code>String</code> object.</p>
</release-item>
<release-item>
<release-item-contributor-list>
<release-item-contributor id="cynthia.shang"/>

View File

@ -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
***********************************************************************************************************************************/

View File

@ -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);

View File

@ -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);
}
// *****************************************************************************************************************************