rsys

Basic data structures and low-level features
git clone git://git.meso-star.fr/rsys.git
Log | Files | Refs | README | LICENSE

commit 9b56d59dd270f4ef76e6c1ff28da822068d1f644
parent fa43a576c1274e494121458f481408baf23baf40
Author: vaplv <vaplv@free.fr>
Date:   Wed,  7 Jan 2015 10:40:58 +0100

Add and test the str_is_empty function

Diffstat:
Mcmake/CMakeLists.txt | 2+-
Msrc/str.h | 7+++++++
Msrc/test_str.c | 2++
3 files changed, 10 insertions(+), 1 deletion(-)

diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt @@ -39,7 +39,7 @@ include(rcmake) # Configure and define targets ################################################################################ set(VERSION_MAJOR 0) -set(VERSION_MINOR 0) +set(VERSION_MINOR 1) set(VERSION_PATCH 0) set(VERSION ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}) diff --git a/src/str.h b/src/str.h @@ -56,6 +56,13 @@ str_len(const struct str* str) return str->len; } +static INLINE char +str_is_empty(const struct str* str) +{ + ASSERT(str); + return str_len(str) == 0; +} + static INLINE void str_clear(struct str* str) { diff --git a/src/test_str.c b/src/test_str.c @@ -29,10 +29,12 @@ main(int argc, char** argv) str_init(&allocator_proxy, &str); CHECK(strcmp(str_get(&str), ""), 0); CHECK(str_len(&str), 0); + CHECK(str_is_empty(&str), 1); CHECK(str_set(&str, "Foo"), RES_OK); CHECK(strcmp(str_get(&str), "Foo"), 0); CHECK(str_len(&str), strlen("Foo")); + CHECK(str_is_empty(&str), 0); str_clear(&str); CHECK(strcmp(str_get(&str), ""), 0);