Initial Commit

This commit is contained in:
2025-06-19 16:25:25 +02:00
commit d62635c7d9
5 changed files with 123 additions and 0 deletions

32
str_utils.cpp Normal file
View File

@@ -0,0 +1,32 @@
//
// Created by server on 6/19/25.
//
#include "str_utils.h"
#include <cstring>
bool startWith(const char * str, const char ch) {
if (str == nullptr) return false; // Fail if str is empty
if (ch == 0) return false; // Fail if ch is NULL
if (str[0] != ch) return false; // Fail if str[0] != ch
return true; // str[0] == ch
}
bool contains(const char * str, const char ch) {
if (str == nullptr) return false; // Fail if str is null
if (ch == 0) return false; // Fail if ch is null
const size_t len = strlen(str);
if (len == 0) return false; // Fail if str is empty
for (int i = 0; i < len; i++) {
if (str[i] == ch) return true; // Found ch in str
}
return false; // ch is not in str
}
bool endsWith(const char * str, const char ch) {
if (str == nullptr) return false; // Fail if str is empty
if (ch == 0) return false; // Fail if ch is NULL
const size_t len = strlen(str);
if (str[len-1] != ch) return false; // Fail if str[len-1] != ch
return true; // str[len-1] == ch
}