Added some std::string functions from c++ 20
parent
12ec6a9334
commit
69ab5d7079
|
@ -9,7 +9,7 @@
|
|||
|
||||
template<typename K, typename V, typename HASH = std::hash<K>>
|
||||
class hashmap {
|
||||
|
||||
|
||||
};
|
||||
|
||||
#endif //BLT_TESTS_MAP_H
|
||||
|
|
|
@ -13,6 +13,31 @@
|
|||
#include <vector>
|
||||
|
||||
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
|
||||
|
|
|
@ -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";
|
||||
}
|
Loading…
Reference in New Issue