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); 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) + '…';
} }