You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

47 lines
937 B

/**
* @file string.cpp
* @author n0m1s
*/
#include "./string.h"
bool string_starts_by(char const* hay, char const* needle)
{
if(needle == nullptr)
return true;
if(hay == nullptr)
return false;
for(unsigned int i = 0; needle[i] != '\0'; ++i)
{
if(hay[i] == '\0')
return false;
if(hay[i] != needle[i])
return false;
}
return true;
}
bool string_equals(char const* a, char const* b)
{
if(a == nullptr) return b == nullptr;
if(b == nullptr) return false;
unsigned int i = 0;
for(; a[i] != '\0' && b[i] != '\0'; ++i)
if(a[i] != b[i]) return false;
//either a or b is finished, so we check that both are
return a[i] == b[i];
}
char* string_copy(char const* s)
{
unsigned int const len = strlen(s)+1;
char * ret = new char[len];
for(unsigned int i = 0; i < len; ++i)
ret[i] = s[i];
return ret;
}