diff options
author | Benji Dial <benji@benjidial.net> | 2024-01-11 23:53:57 -0500 |
---|---|---|
committer | Benji Dial <benji@benjidial.net> | 2024-01-11 23:53:57 -0500 |
commit | c4ab2f6f440f060b1686991b24379a4998aa55a9 (patch) | |
tree | e1b4cc875554a18ac110847cca9ba55261fca9c9 /include/mercury/kernel/utility.hpp | |
parent | 88816732b53eb536fe0e8db3d9ed15f0d1c29bb4 (diff) | |
download | hilbert-os-c4ab2f6f440f060b1686991b24379a4998aa55a9.tar.gz |
file reading, tarfs directory listing
Diffstat (limited to 'include/mercury/kernel/utility.hpp')
-rw-r--r-- | include/mercury/kernel/utility.hpp | 21 |
1 files changed, 21 insertions, 0 deletions
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 <class value_t> struct list { |