mirror of
https://github.com/hrydgard/ppsspp.git
synced 2026-09-08 13:43:27 +02:00
Infrastructure username handling: Add separate username, pick Nickname as default if valid.
This commit is contained in:
@@ -105,6 +105,38 @@ int countChar(std::string_view haystack, char needle) {
|
||||
return count;
|
||||
}
|
||||
|
||||
std::string SanitizeString(std::string_view input, StringRestriction restriction, int maxLength) {
|
||||
if (restriction == StringRestriction::None) {
|
||||
return std::string(input);
|
||||
}
|
||||
// First, remove any chars not in A-Za-z0-9_-. This will effectively get rid of any Unicode char, emojis etc too.
|
||||
std::string sanitized;
|
||||
for (auto c : input) {
|
||||
switch (restriction) {
|
||||
case StringRestriction::None:
|
||||
sanitized.push_back(c);
|
||||
break;
|
||||
case StringRestriction::AlphaNumDashUnderscore:
|
||||
if ((c >= 'A' && c <= 'Z') ||
|
||||
(c >= 'a' && c <= 'z') ||
|
||||
(c >= '0' && c <= '9') || c == '-' || c == '_') {
|
||||
// Allowed chars.
|
||||
sanitized.push_back(c);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (maxLength >= 0) {
|
||||
// TODO: Cut at whole UTF-8 chars!
|
||||
if (sanitized.size() > maxLength) {
|
||||
sanitized.resize(maxLength);
|
||||
}
|
||||
}
|
||||
|
||||
return sanitized;
|
||||
}
|
||||
|
||||
bool CharArrayFromFormatV(char* out, int outsize, const char* format, va_list args)
|
||||
{
|
||||
int writtenCount = vsnprintf(out, outsize, format, args);
|
||||
|
||||
Reference in New Issue
Block a user