pgbackrest.git / summary / log / commit / refs
commit aff9693e640c8a0b76e46f31d4fa569fd7d63289
Author: David Steele <david@pgmasters.net>
Date: Mon Nov 12 19:13:55 2018 +0000
Add strEmpty() to String object.
strEmpty() is more concise and explanatory than strSize() == 0.
doc/xml/release.xml | 2 +-
src/common/type/string.c | 13 +++++++++++++
src/common/type/string.h | 1 +
test/src/module/common/typeStringTest.c | 3 ++-
4 files changed, 17 insertions(+), 2 deletions(-)
diff --git a/doc/xml/release.xml b/doc/xml/release.xml
index bc178e0b5..ff5b7a420 100644
--- a/doc/xml/release.xml
+++ b/doc/xml/release.xml
@@ -75,7 +75,7 @@
</release-item>
<release-item>
- <p>Add <code>strCatChr()</code> and constant macros to <code>String</code> object.</p>
+ <p>Add <code>strCatChr()</code>, <code>strEmpty()</code>, and constant macros to <code>String</code> object.</p>
</release-item>
<release-item>
diff --git a/src/common/type/string.c b/src/common/type/string.c
index 37293fc9f..7ff966de6 100644
--- a/src/common/type/string.c
+++ b/src/common/type/string.c
@@ -342,6 +342,19 @@ strDup(const String *this)
FUNCTION_TEST_RESULT(STRING, result);
}
+/***********************************************************************************************************************************
+Is the string empty?
+***********************************************************************************************************************************/
+bool
+strEmpty(const String *this)
+{
+ FUNCTION_TEST_BEGIN();
+ FUNCTION_TEST_PARAM(STRING, this);
+ FUNCTION_TEST_END();
+
+ FUNCTION_TEST_RESULT(BOOL, strSize(this) == 0);
+}
+
/***********************************************************************************************************************************
Does the string end with the specified string?
***********************************************************************************************************************************/
diff --git a/src/common/type/string.h b/src/common/type/string.h
index f00147468..0022dc6e7 100644
--- a/src/common/type/string.h
+++ b/src/common/type/string.h
@@ -28,6 +28,7 @@ String *strCatFmt(String *this, const char *format, ...) __attribute__((format(p
int strCmp(const String *this, const String *compare);
int strCmpZ(const String *this, const char *compare);
String *strDup(const String *this);
+bool strEmpty(const String *this);
bool strEndsWith(const String *this, const String *endsWith);
bool strEndsWithZ(const String *this, const char *endsWith);
bool strEq(const String *this, const String *compare);
diff --git a/test/src/module/common/typeStringTest.c b/test/src/module/common/typeStringTest.c
index 1b3ed8301..bfb5b9bdf 100644
--- a/test/src/module/common/typeStringTest.c
+++ b/test/src/module/common/typeStringTest.c
@@ -15,11 +15,12 @@ testRun(void)
FUNCTION_HARNESS_VOID();
// *****************************************************************************************************************************
- if (testBegin("strNew(), strNewBuf(), strNewN(), strPtr(), and strFree()"))
+ if (testBegin("strNew(), strNewBuf(), strNewN(), strEmpty(), strPtr(), strSize(), and strFree()"))
{
String *string = strNew("static string");
TEST_RESULT_STR(strPtr(string), "static string", "new with static string");
TEST_RESULT_INT(strSize(string), 13, "check size");
+ TEST_RESULT_BOOL(strEmpty(string), false, "is not empty");
TEST_RESULT_INT(strlen(strPtr(string)), 13, "check size with strlen()");
TEST_RESULT_CHAR(strPtr(string)[2], 'a', "check character");
[parent: 38c5f657704c]