From b25ac43bd133c585ea7024534475e45f06060328 Mon Sep 17 00:00:00 2001 From: Ludovic 'Archivist' Lagouardette Date: Tue, 11 Jun 2019 11:50:26 +0200 Subject: [PATCH] Better cstring manipulation --- include/rigid_paradise/string.h | 10 ++++++++++ src/yes/yes.cpp | 4 ++-- 2 files changed, 12 insertions(+), 2 deletions(-) create mode 100644 include/rigid_paradise/string.h diff --git a/include/rigid_paradise/string.h b/include/rigid_paradise/string.h new file mode 100644 index 0000000..2073cc6 --- /dev/null +++ b/include/rigid_paradise/string.h @@ -0,0 +1,10 @@ +#pragma once +#include + + +namespace cstring{ + constexpr size_t strlen( const char* s ) noexcept + { + return *s ? 1 + strlen(s + 1) : 0; + } +} \ No newline at end of file diff --git a/src/yes/yes.cpp b/src/yes/yes.cpp index dd5e245..5af901d 100644 --- a/src/yes/yes.cpp +++ b/src/yes/yes.cpp @@ -3,7 +3,7 @@ #include #include #include -#include +#include #ifndef EXIT_FAILURE #define EXIT_FAILURE -1 @@ -17,7 +17,7 @@ usage: yes [STRING]*\n\ yes --help\n\ yes --version\n\ Display this text.\n"; -const size_t help_len = strlen(help); +const size_t help_len = cstring::strlen(help); int main(int argc, char** argv) {