1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2026-01-18 12:33:17 +01:00

Begin writing IniReader

This commit is contained in:
Ted John
2017-02-12 21:11:28 +00:00
parent 9abff205c3
commit d5ee210797
6 changed files with 186 additions and 2 deletions

View File

@@ -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);
}
}
}