diff --git a/include/blt/std/map.h b/include/blt/std/map.h index 5f96993..1b9a17e 100644 --- a/include/blt/std/map.h +++ b/include/blt/std/map.h @@ -9,7 +9,7 @@ template> class hashmap { - + }; #endif //BLT_TESTS_MAP_H diff --git a/include/blt/std/string.h b/include/blt/std/string.h index d7b2950..1056438 100644 --- a/include/blt/std/string.h +++ b/include/blt/std/string.h @@ -13,6 +13,31 @@ #include namespace blt::String { + + static inline bool starts_with(const std::string& string, const std::string& search){ + if (search.length() > string.length()) + return false; + auto chars = string.c_str(); + auto search_chars = search.c_str(); + for (int i = 0; i < search.length(); i++){ + if (chars[i] != search_chars[i]) + return false; + } + return true; + } + + static inline bool ends_with(const std::string& string, const std::string& search){ + if (search.length() > string.length()) + return false; + auto chars = string.c_str(); + auto search_chars = search.c_str(); + auto startPosition = string.length() - search.length(); + for (int i = 0; i < search.length(); i++){ + if (chars[startPosition + i] != search_chars[i]) + return false; + } + return true; + } /** * Converts the string into lower case * @param s string to lower case diff --git a/src/tests/main.cpp b/src/tests/main.cpp index 749b61c..1002e5e 100644 --- a/src/tests/main.cpp +++ b/src/tests/main.cpp @@ -1,6 +1,10 @@ #include "binary_trees.h" +#include "blt/std/string.h" int main() { binaryTreeTest(); + + std::string hello = "superSexyMax"; + std::cout << "String starts with: " << blt::String::ends_with(hello, "Max") << "\n"; } \ No newline at end of file