Merge branch 'master' into jgrpp-beta
# Conflicts: # src/cargopacket.h # src/lang/korean.txt # src/linkgraph/linkgraph.h # src/linkgraph/linkgraphjob.h # src/linkgraph/linkgraphschedule.h # src/network/network_admin.h # src/network/network_func.h # src/network/network_server.cpp # src/network/network_server.h # src/order_base.h # src/rail_cmd.cpp # src/saveload/company_sl.cpp # src/saveload/depot_sl.cpp # src/saveload/economy_sl.cpp # src/saveload/linkgraph_sl.cpp # src/saveload/map_sl.cpp # src/saveload/newgrf_sl.cpp # src/saveload/order_sl.cpp # src/saveload/saveload.cpp # src/saveload/saveload.h # src/saveload/signs_sl.cpp # src/saveload/station_sl.cpp # src/saveload/subsidy_sl.cpp # src/saveload/town_sl.cpp # src/saveload/vehicle_sl.cpp # src/script/api/script_object.cpp # src/settings.cpp # src/string.cpp # src/string_func.h # src/table/CMakeLists.txt # src/table/settings/settings.ini # src/viewport_sprite_sorter_sse4.cpp
This commit is contained in:
@@ -216,7 +216,7 @@ const char *str_fix_scc_encoded(char *str, const char *last)
|
||||
|
||||
|
||||
template <class T>
|
||||
static void str_validate(T &dst, const char *str, const char *last, StringValidationSettings settings)
|
||||
static void StrMakeValidInPlace(T &dst, const char *str, const char *last, StringValidationSettings settings)
|
||||
{
|
||||
/* Assume the ABSOLUTE WORST to be in str as it comes from the outside. */
|
||||
|
||||
@@ -276,51 +276,52 @@ static void str_validate(T &dst, const char *str, const char *last, StringValida
|
||||
}
|
||||
|
||||
/**
|
||||
* Scans the string for valid characters and if it finds invalid ones,
|
||||
* replaces them with a question mark '?' (if not ignored)
|
||||
* @param str the string to validate
|
||||
* @param last the last valid character of str
|
||||
* @param settings the settings for the string validation.
|
||||
* Scans the string for invalid characters and replaces then with a
|
||||
* question mark '?' (if not ignored).
|
||||
* @param str The string to validate.
|
||||
* @param last The last valid character of str.
|
||||
* @param settings The settings for the string validation.
|
||||
* @return pointer to terminating 0.
|
||||
*/
|
||||
char *str_validate(char *str, const char *last, StringValidationSettings settings)
|
||||
char *StrMakeValidInPlace(char *str, const char *last, StringValidationSettings settings)
|
||||
{
|
||||
char *dst = str;
|
||||
str_validate(dst, str, last, settings);
|
||||
StrMakeValidInPlace(dst, str, last, settings);
|
||||
*dst = '\0';
|
||||
return dst;
|
||||
}
|
||||
|
||||
/**
|
||||
* Scans the string for valid characters and if it finds invalid ones,
|
||||
* replaces them with a question mark '?' (if not ignored)
|
||||
* @param str the string to validate
|
||||
* @param settings the settings for the string validation.
|
||||
* Scans the string for invalid characters and replaces then with a
|
||||
* question mark '?' (if not ignored).
|
||||
* Only use this function when you are sure the string ends with a '\0';
|
||||
* otherwise use StrMakeValidInPlace(str, last, settings) variant.
|
||||
* @param str The string (of which you are sure ends with '\0') to validate.
|
||||
*/
|
||||
std::string str_validate(const std::string &str, StringValidationSettings settings)
|
||||
void StrMakeValidInPlace(char *str, StringValidationSettings settings)
|
||||
{
|
||||
/* We know it is '\0' terminated. */
|
||||
StrMakeValidInPlace(str, str + strlen(str), settings);
|
||||
}
|
||||
|
||||
/**
|
||||
* Scans the string for invalid characters and replaces then with a
|
||||
* question mark '?' (if not ignored).
|
||||
* @param str The string to validate.
|
||||
* @param settings The settings for the string validation.
|
||||
*/
|
||||
std::string StrMakeValid(const std::string &str, StringValidationSettings settings)
|
||||
{
|
||||
auto buf = str.data();
|
||||
auto last = buf + str.size();
|
||||
|
||||
std::ostringstream dst;
|
||||
std::ostreambuf_iterator<char> dst_iter(dst);
|
||||
str_validate(dst_iter, buf, last, settings);
|
||||
StrMakeValidInPlace(dst_iter, buf, last, settings);
|
||||
|
||||
return dst.str();
|
||||
}
|
||||
|
||||
/**
|
||||
* Scans the string for valid characters and if it finds invalid ones,
|
||||
* replaces them with a question mark '?'.
|
||||
* @param str the string to validate
|
||||
*/
|
||||
void ValidateString(const char *str)
|
||||
{
|
||||
/* We know it is '\0' terminated. */
|
||||
str_validate(const_cast<char *>(str), str + strlen(str) + 1);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Checks whether the given string is valid, i.e. contains only
|
||||
* valid (printable) characters and is properly terminated.
|
||||
@@ -496,6 +497,16 @@ size_t Utf8StringLength(const char *s)
|
||||
return len;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the length of an UTF-8 encoded string in number of characters
|
||||
* and thus not the number of bytes that the encoded string contains.
|
||||
* @param s The string to get the length for.
|
||||
* @return The length of the string in characters.
|
||||
*/
|
||||
size_t Utf8StringLength(const std::string &str)
|
||||
{
|
||||
return Utf8StringLength(str.c_str());
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a given ASCII string to lowercase.
|
||||
|
Reference in New Issue
Block a user