1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-12 15:22:55 +08:00

Make ellipsis length into a static

This commit is contained in:
smoogipoo 2019-12-25 11:14:40 +09:00
parent f1f9e1f658
commit 36dd0e6998

View File

@ -98,17 +98,17 @@ namespace osu.Desktop
client.SetPresence(presence);
}
private static readonly int ellipsis_length = Encoding.UTF8.GetByteCount(new[] { '…' });
private string truncate(ReadOnlySpan<char> str)
{
if (Encoding.UTF8.GetByteCount(str) <= 128)
return new string(str);
int ellipsisLength = Encoding.UTF8.GetByteCount(new[] { '…' });
do
{
str = str[..^1];
} while (Encoding.UTF8.GetByteCount(str) + ellipsisLength > 128);
} while (Encoding.UTF8.GetByteCount(str) + ellipsis_length > 128);
return new string(str) + '…';
}