mirror of
https://github.com/ppy/osu
synced 2025-02-08 22:27:14 +00:00
Make ellipsis length into a static
This commit is contained in:
parent
f1f9e1f658
commit
36dd0e6998
@ -98,17 +98,17 @@ namespace osu.Desktop
|
|||||||
client.SetPresence(presence);
|
client.SetPresence(presence);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static readonly int ellipsis_length = Encoding.UTF8.GetByteCount(new[] { '…' });
|
||||||
|
|
||||||
private string truncate(ReadOnlySpan<char> str)
|
private string truncate(ReadOnlySpan<char> str)
|
||||||
{
|
{
|
||||||
if (Encoding.UTF8.GetByteCount(str) <= 128)
|
if (Encoding.UTF8.GetByteCount(str) <= 128)
|
||||||
return new string(str);
|
return new string(str);
|
||||||
|
|
||||||
int ellipsisLength = Encoding.UTF8.GetByteCount(new[] { '…' });
|
|
||||||
|
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
str = str[..^1];
|
str = str[..^1];
|
||||||
} while (Encoding.UTF8.GetByteCount(str) + ellipsisLength > 128);
|
} while (Encoding.UTF8.GetByteCount(str) + ellipsis_length > 128);
|
||||||
|
|
||||||
return new string(str) + '…';
|
return new string(str) + '…';
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user