mirror of
https://github.com/OpenRCT2/OpenRCT2
synced 2026-01-18 12:33:17 +01:00
Begin writing IniReader
This commit is contained in:
@@ -393,4 +393,44 @@ namespace String
|
||||
{
|
||||
return String::Set(buffer, bufferSize, TrimStart(src));
|
||||
}
|
||||
|
||||
std::string Trim(const std::string &s)
|
||||
{
|
||||
const utf8 * firstNonWhitespace = nullptr;
|
||||
|
||||
codepoint_t codepoint;
|
||||
const utf8 * ch = s.c_str();
|
||||
const utf8 * nextCh;
|
||||
while ((codepoint = GetNextCodepoint(ch, &nextCh)) != '\0')
|
||||
{
|
||||
bool isWhiteSpace = codepoint <= WCHAR_MAX && iswspace((wchar_t)codepoint);
|
||||
if (isWhiteSpace)
|
||||
{
|
||||
if (firstNonWhitespace != nullptr)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (firstNonWhitespace == nullptr)
|
||||
{
|
||||
firstNonWhitespace = ch;
|
||||
}
|
||||
}
|
||||
ch = nextCh;
|
||||
}
|
||||
|
||||
if (firstNonWhitespace != nullptr &&
|
||||
firstNonWhitespace != s.c_str())
|
||||
{
|
||||
size_t newStringSize = ch - firstNonWhitespace;
|
||||
return std::string(firstNonWhitespace, newStringSize);
|
||||
}
|
||||
else
|
||||
{
|
||||
size_t newStringSize = ch - s.c_str();
|
||||
return std::string(s.c_str(), newStringSize);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user