-
Notifications
You must be signed in to change notification settings - Fork 2
/
FrensHelpers.cpp
37 lines (35 loc) · 982 Bytes
/
FrensHelpers.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include "FrensHelpers.h"
namespace Frens {
// string helper functions
//
// test if string ends with suffix
//
bool endsWith(std::string const &str, std::string const &suffix)
{
if (str.length() < suffix.length())
{
return false;
}
return str.compare(str.length() - suffix.length(), suffix.length(), suffix) == 0;
}
//
// returns lowercase of string s
//
std::string str_tolower(std::string s)
{
std::transform(s.begin(), s.end(), s.begin(),
[](unsigned char c)
{ return std::tolower(c); } // correct
);
return s;
}
bool cstr_endswith(const char *string, const char *width) {
int lstring = strlen(string);
int wlen = strlen(width);
if ( wlen >= lstring ) {
return false;
}
int pos = lstring - wlen;
return( strcmp(string + pos, width) == 0);
}
}