Merge branch 'master' into jgrpp-beta

# Conflicts:
#	.github/workflows/ci-build.yml
#	CMakeLists.txt
#	src/lang/finnish.txt
#	src/lang/french.txt
#	src/lang/korean.txt
#	src/lang/norwegian_bokmal.txt
#	src/lang/russian.txt
#	src/lang/spanish.txt
#	src/misc_gui.cpp
#	src/newgrf.cpp
This commit is contained in:
Jonathan G Rennison
2021-10-28 23:51:24 +01:00
44 changed files with 315 additions and 216 deletions

View File

@@ -390,6 +390,33 @@ void StrTrimInPlace(std::string &str)
StrRightTrimInPlace(str);
}
/**
* Check whether the given string starts with the given prefix.
* @param str The string to look at.
* @param prefix The prefix to look for.
* @return True iff the begin of the string is the same as the prefix.
*/
bool StrStartsWith(const std::string_view str, const std::string_view prefix)
{
size_t prefix_len = prefix.size();
if (str.size() < prefix_len) return false;
return str.compare(0, prefix_len, prefix, 0, prefix_len) == 0;
}
/**
* Check whether the given string ends with the given suffix.
* @param str The string to look at.
* @param suffix The suffix to look for.
* @return True iff the end of the string is the same as the suffix.
*/
bool StrEndsWith(const std::string_view str, const std::string_view suffix)
{
size_t suffix_len = suffix.size();
if (str.size() < suffix_len) return false;
return str.compare(str.size() - suffix_len, suffix_len, suffix, 0, suffix_len) == 0;
}
/** Scans the string for colour codes and strips them */
void str_strip_colours(char *str)
{