summaryrefslogtreecommitdiffstats
path: root/mmc_updater/src/StringUtils.h
blob: 745b71c9ae863f2f32d01e12f2001787fd18c7cb (plain)
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
38
39
40
41
42
43
44
45
46
#pragma once

#include <string.h>
#include <string>
#include <sstream>
#include <stdlib.h>

template <class T>
inline std::string intToStr(T i)
{
	std::stringstream stream;
	stream << i;
	return stream.str();
}

inline bool strToBool(const std::string& str)
{
	return str == "true" || atoi(str.c_str()) != 0;
}

/** Returns @p text if non-null or a pointer
  * to an empty null-terminated string otherwise.
  */
inline const char* notNullString(const char* text)
{
	if (text)
	{
		return text;
	}
	else
	{
		return "";
	}
}

inline bool endsWith(const std::string& str, const char* text)
{
	size_t length = strlen(text);
	return str.find(text,str.size() - length) != std::string::npos;
}

inline bool startsWith(const std::string& str, const char* text)
{
	return str.find(text,0) == 0;
}