Skip to content

Utility

Mister Mjir edited this page Dec 23, 2019 · 3 revisions

Utility

Provides utility methods for pTable under the namespace pTable.

Header (utility.h)

Macros

STR_PARAM

  • const std::string &, used for string parameters

void doNothing() {}

Does nothing

void doNothing(METHOD_ARGS) {}

Does nothing, used for Method structs

bool checkstrnocase(STR_PARAM str1, STR_PARAM str2)

Case-insensitive string check

bool checkstrnocase(STR_PARAM str1, STR_PARAM str2)
{
	return ((str1.size() == str2.size()) &&
	         std::equal(str1.begin(), str1.end(), str2.begin(),
	           [](const char &c1, const char &c2) {return (c1 == c2 || std::toupper(c1) == std::toupper(c2));}
	        ));
}

Parameters

  • STR_PARAM str1
    • A string to check
  • STR_PARAM str2
    • Another string to check

Return

A boolean holding true if the strings passed the check or false if they failed.

std::vector<std::string> seperateString(std::string str, std::string sepStr)

Seperates a string into a vector of substrings separated by whatever you want

std::vector<std::string> seperateString(std::string str, std::string sepStr)
{
	std::vector<std::string> list;
	std::string word = "";

	for (auto letter : str)
	{
		std::string strLetter(1, letter);
		if (strLetter.compare(sepStr) == 0)
		{
			list.push_back(word);
			word = "";
		}
		else
			word += letter;
	}
	list.push_back(word);

	return list;
}

Parameters

  • std::string str
    • The string to seperate
  • std::string sepStr
    • Tells how to seperate the string (ex. " " to seperate into words)

V 2.2.0