Better handling of large input strings and minimise loop opportunities.
This commit is contained in:
parent
a1646ff551
commit
a74e8f8288
1 changed files with 10 additions and 7 deletions
|
@ -1,6 +1,7 @@
|
||||||
using DiscordRPC;
|
using DiscordRPC;
|
||||||
using Ryujinx.Common;
|
using Ryujinx.Common;
|
||||||
using Ryujinx.UI.Common.Configuration;
|
using Ryujinx.UI.Common.Configuration;
|
||||||
|
using System;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
|
||||||
namespace Ryujinx.UI.Common
|
namespace Ryujinx.UI.Common
|
||||||
|
@ -11,6 +12,7 @@ namespace Ryujinx.UI.Common
|
||||||
private const string ApplicationId = "1216775165866807456";
|
private const string ApplicationId = "1216775165866807456";
|
||||||
|
|
||||||
private const int TitleByteLimit = 128;
|
private const int TitleByteLimit = 128;
|
||||||
|
private const string Ellipsis = "…";
|
||||||
|
|
||||||
private static DiscordRpcClient _discordClient;
|
private static DiscordRpcClient _discordClient;
|
||||||
private static RichPresence _discordPresenceMain;
|
private static RichPresence _discordPresenceMain;
|
||||||
|
@ -100,18 +102,19 @@ namespace Ryujinx.UI.Common
|
||||||
return input;
|
return input;
|
||||||
}
|
}
|
||||||
|
|
||||||
string trimmed = input;
|
// Find the length to trim the string to guarantee we have space for the trailing ellipsis.
|
||||||
|
int trimLimit = byteLimit - Encoding.UTF8.GetByteCount(Ellipsis);
|
||||||
|
|
||||||
while (Encoding.UTF8.GetByteCount(trimmed) > byteLimit)
|
// Basic trim to best case scenario of 1 byte characters.
|
||||||
|
input = input[..trimLimit];
|
||||||
|
|
||||||
|
while (Encoding.UTF8.GetByteCount(input) > trimLimit)
|
||||||
{
|
{
|
||||||
// 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];
|
input = input[..^1];
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remove another 3 characters to make sure we have room for "…".
|
return input.TrimEnd() + Ellipsis;
|
||||||
trimmed = trimmed[..^3].TrimEnd() + "…";
|
|
||||||
|
|
||||||
return trimmed;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void Exit()
|
public static void Exit()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue