MCPcopy Create free account
hub / github.com/OpenTTD/OpenTTD / StrTrimInPlace

Function StrTrimInPlace

src/string.cpp:228–239  ·  view source on GitHub ↗

* Trim the spaces from given string in place, i.e. the string buffer that * is passed will be modified whenever spaces exist in the given string. * When there are spaces at the begin, the whole string is moved forward * and when there are spaces at the back the '\0' termination is moved. * @param str The string to perform the in place trimming on. */

Source from the content-addressed store, hash-verified

226 * @param str The string to perform the in place trimming on.
227 */
228void StrTrimInPlace(std::string &str)
229{
230 size_t first_pos = str.find_first_not_of(StringConsumer::WHITESPACE_NO_NEWLINE);
231 if (first_pos == std::string::npos) {
232 str.clear();
233 return;
234 }
235 str.erase(0, first_pos);
236
237 size_t last_pos = str.find_last_not_of(StringConsumer::WHITESPACE_NO_NEWLINE);
238 str.erase(last_pos + 1);
239}
240
241std::string_view StrTrimView(std::string_view str, std::string_view characters_to_trim)
242{

Callers 4

CheckClientAndServerNameFunction · 0.85
string_func.cppFile · 0.85

Calls 2

clearMethod · 0.45
eraseMethod · 0.45

Tested by

no test coverage detected