ファイル

32 行
1.2 KiB
C#

namespace UndoTree;
internal static class UndoTreeText
{
public const int MaxLength = 60;
const string LineBreakMark = "↵";
public static string SingleLine(string text) => text.ReplaceLineEndings(LineBreakMark);
public static string Shorten(string text)
{
if (text.Length <= MaxLength)
return text;
var length = char.IsHighSurrogate(text[MaxLength - 1]) ? MaxLength - 1 : MaxLength;
return text[..length] + "…";
}
public static string Join(string target, string member)
=> target.Length == 0 ? member : member.Length == 0 ? target : $"{target} / {member}";
public static string WithDetail(string text, string detail) => detail.Length > 0 ? $"{text}: {detail}" : text;
public static string WithNote(string text, string note) => note.Length > 0 ? $"{text} — {note}" : text;
public static string BranchMark(string name) => $"[{string.Format(Texts.BranchMark, name)}]";
public static string Marks(bool isCompareBase, bool isSaved, string tag, string branches)
=> (isCompareBase ? $"[{Texts.BaseMark}]" : string.Empty) + (isSaved ? $"[{Texts.SavedMark}]" : string.Empty) + (tag.Length > 0 ? $"[{tag}]" : string.Empty) + branches;
}