From c4ab2f6f440f060b1686991b24379a4998aa55a9 Mon Sep 17 00:00:00 2001 From: Benji Dial Date: Thu, 11 Jan 2024 23:53:57 -0500 Subject: file reading, tarfs directory listing --- include/mercury/kernel/utility.hpp | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'include/mercury/kernel/utility.hpp') diff --git a/include/mercury/kernel/utility.hpp b/include/mercury/kernel/utility.hpp index f12101a..1648e67 100644 --- a/include/mercury/kernel/utility.hpp +++ b/include/mercury/kernel/utility.hpp @@ -29,6 +29,27 @@ namespace mercury::kernel::utility { return len; } + //if c appears in str, this returns the index of the last time it appears. + //otherwise, this returns len. + static inline unsigned find_last(const char *str, unsigned len, char c) { + for (unsigned i = len; i > 0; --i) + if (str[i - 1] == c) + return i - 1; + return len; + } + + //str1 starts with str2 + static inline bool starts_with( + const char *str1, unsigned str1_len, const char *str2, unsigned str2_len + ) { + if (str1_len < str2_len) + return false; + for (unsigned i = 0; i < str2_len; ++i) + if (str1[i] != str2[i]) + return false; + return true; + } + template struct list { -- cgit v1.2.3