Merge branch 'master' into jgrpp-beta
# Conflicts: # .github/workflows/commit-checker.yml # src/company_cmd.cpp # src/console_cmds.cpp # src/crashlog.cpp # src/lang/english.txt # src/lang/german.txt # src/lang/indonesian.txt # src/lang/japanese.txt # src/lang/korean.txt # src/lang/swedish.txt # src/linkgraph/linkgraphjob.cpp # src/linkgraph/mcf.cpp # src/network/core/tcp.cpp # src/network/core/tcp.h # src/network/core/tcp_game.h # src/network/core/udp.h # src/network/network.cpp # src/network/network_admin.cpp # src/network/network_admin.h # src/network/network_chat_gui.cpp # src/network/network_client.cpp # src/network/network_client.h # src/network/network_func.h # src/network/network_internal.h # src/network/network_server.cpp # src/network/network_server.h # src/newgrf.cpp # src/newgrf_station.cpp # src/order_gui.cpp # src/rail_cmd.cpp # src/saveload/saveload.cpp # src/settings.cpp # src/settings_gui.cpp # src/settings_internal.h # src/settings_type.h # src/station_cmd.cpp # src/stdafx.h # src/table/currency_settings.ini # src/table/misc_settings.ini # src/table/settings.h.preamble # src/table/settings.ini # src/terraform_cmd.cpp # src/timetable_gui.cpp # src/train_cmd.cpp # src/tree_cmd.cpp # src/water_cmd.cpp
This commit is contained in:
@@ -358,19 +358,10 @@ bool StrValid(const char *str, const char *last)
|
||||
* When there are spaces at the begin, the whole string is moved forward.
|
||||
* @param str The string to perform the in place left trimming on.
|
||||
*/
|
||||
static void StrLeftTrimInPlace(char *str)
|
||||
static void StrLeftTrimInPlace(std::string &str)
|
||||
{
|
||||
if (StrEmpty(str)) return;
|
||||
|
||||
char *first_non_space = str;
|
||||
while (*first_non_space == ' ') first_non_space++;
|
||||
|
||||
if (first_non_space == str) return;
|
||||
|
||||
/* The source will reach '\0' first, but set the '\0' on the destination afterwards. */
|
||||
char *dst = str;
|
||||
for (char *src = first_non_space; *src != '\0'; dst++, src++) *dst = *src;
|
||||
*dst = '\0';
|
||||
size_t pos = str.find_first_not_of(' ');
|
||||
str.erase(0, pos);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -379,24 +370,10 @@ static void StrLeftTrimInPlace(char *str)
|
||||
* When there are spaces at the end, the '\0' will be moved forward.
|
||||
* @param str The string to perform the in place left trimming on.
|
||||
*/
|
||||
static void StrRightTrimInPlace(char *str)
|
||||
static void StrRightTrimInPlace(std::string &str)
|
||||
{
|
||||
if (StrEmpty(str)) return;
|
||||
|
||||
char *end = str;
|
||||
while (*end != '\0') end++;
|
||||
|
||||
char *last_non_space = end - 1;
|
||||
while (last_non_space >= str && *last_non_space == ' ') last_non_space--;
|
||||
|
||||
/* The last non space points to the last character of the string that is not
|
||||
* a space. For a string with only spaces or an empty string this would be
|
||||
* the position before the begin of the string. The previous search ensures
|
||||
* that this location before the string is not read.
|
||||
* In any case, the character after the last non space character will be
|
||||
* either a space or the existing termination, so it can be set to '\0'.
|
||||
*/
|
||||
last_non_space[1] = '\0';
|
||||
size_t pos = str.find_last_not_of(' ');
|
||||
if (pos != std::string::npos) str.erase(pos + 1);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -406,7 +383,7 @@ static void StrRightTrimInPlace(char *str)
|
||||
* and when there are spaces at the back the '\0' termination is moved.
|
||||
* @param str The string to perform the in place trimming on.
|
||||
*/
|
||||
void StrTrimInPlace(char *str)
|
||||
void StrTrimInPlace(std::string &str)
|
||||
{
|
||||
StrLeftTrimInPlace(str);
|
||||
StrRightTrimInPlace(str);
|
||||
|
Reference in New Issue
Block a user