summaryrefslogtreecommitdiffhomepage
path: root/examples
diff options
context:
space:
mode:
authorAmlal El Mahrouss <amlal.elmahrouss@icloud.com>2025-03-20 05:01:48 +0100
committerAmlal El Mahrouss <amlal.elmahrouss@icloud.com>2025-03-20 05:01:48 +0100
commit67670dd3be23a731e3ac4156c36e873102159042 (patch)
treede3f9bad8fb74152ca61188df608428d13201a43 /examples
parent8e2b464e968883a5e133360ad7849c5f8b3111ab (diff)
META: Better checksum example, using modern C++ classes.
META: make use of .hpp, instead of confusing the user with lacking a .hpp at the end.
Diffstat (limited to 'examples')
-rw-r--r--examples/str_checksum.cc13
1 files changed, 5 insertions, 8 deletions
diff --git a/examples/str_checksum.cc b/examples/str_checksum.cc
index 05cdfd8..a4d5e87 100644
--- a/examples/str_checksum.cc
+++ b/examples/str_checksum.cc
@@ -4,17 +4,14 @@
licensed under GPL-2 license
*/
-#include <stdx>
+#include <stdx.hpp>
+#include <string>
-extern "C" {
-# include <string.h>
-}
-
-static const char do_hash(const char* in)
+static const char do_hash(const std::string& in)
{
int hash = 0;
- for (long index = 0; index < strlen(in); ++index)
+ for (long index = 0; index < in.size(); ++index)
{
hash += in[index];
}
@@ -22,7 +19,7 @@ static const char do_hash(const char* in)
return hash;
}
-static auto do_some(const char* recv_data, const char* check_data)
+static auto do_some(const std::string recv_data, const std::string check_data)
{
const int hash_to_check = do_hash(check_data); /* here we assume this should match opt_hash */
const int opt_hash = do_hash(recv_data); /* we assume that the hash is correct */