mirror of
https://github.com/Ryujinx/Ryujinx.git
synced 2024-07-05 04:04:01 +00:00
Allow an early function return and simplify logic.
This commit is contained in:
parent
c381567328
commit
a1646ff551
|
@ -95,21 +95,23 @@ namespace Ryujinx.UI.Common
|
||||||
|
|
||||||
private static string TruncateToByteLength(string input, int byteLimit)
|
private static string TruncateToByteLength(string input, int byteLimit)
|
||||||
{
|
{
|
||||||
bool isModified = false;
|
if (Encoding.UTF8.GetByteCount(input) <= byteLimit)
|
||||||
|
{
|
||||||
|
return input;
|
||||||
|
}
|
||||||
|
|
||||||
string trimmed = input;
|
string trimmed = input;
|
||||||
|
|
||||||
while (Encoding.UTF8.GetByteCount(trimmed) > byteLimit)
|
while (Encoding.UTF8.GetByteCount(trimmed) > byteLimit)
|
||||||
{
|
{
|
||||||
// Remove one character from the end of the string at a time.
|
// Remove one character from the end of the string at a time.
|
||||||
trimmed = trimmed[..^1];
|
trimmed = trimmed[..^1];
|
||||||
|
|
||||||
isModified = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remove another 3 characters to make sure we have room for "…".
|
// Remove another 3 characters to make sure we have room for "…".
|
||||||
trimmed = trimmed[..^3].TrimEnd() + "…";
|
trimmed = trimmed[..^3].TrimEnd() + "…";
|
||||||
|
|
||||||
return isModified ? trimmed : input;
|
return trimmed;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void Exit()
|
public static void Exit()
|
||||||
|
|
Loading…
Reference in a new issue