forked from LogExperts/LogExpert
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathColumn.cs
More file actions
104 lines (76 loc) · 2.63 KB
/
Column.cs
File metadata and controls
104 lines (76 loc) · 2.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
using System;
using System.Collections.Generic;
namespace LogExpert;
public class Column : IColumn
{
#region Fields
private const int MAXLENGTH = 4678 - 3;
private const string REPLACEMENT = "...";
private static readonly List<Func<string, string>> _replacements = [
//replace tab with 3 spaces, from old coding. Needed???
input => input.Replace("\t", " ", StringComparison.Ordinal),
//shorten string if it exceeds maxLength
input => input.Length > MAXLENGTH
? string.Concat(input.AsSpan(0, MAXLENGTH), REPLACEMENT)
: input
];
private string _fullValue;
#endregion
#region cTor
static Column ()
{
if (Environment.Version >= Version.Parse("6.2"))
{
//Win8 or newer support full UTF8 chars with the preinstalled fonts.
//Replace null char with UTF8 Symbol U+2400 (␀)
_replacements.Add(input => input.Replace("\0", "␀", StringComparison.Ordinal));
}
else
{
//Everything below Win8 the installed fonts seems to not to support reliabel
//Replace null char with space
_replacements.Add(input => input.Replace("\0", " ", StringComparison.Ordinal));
}
EmptyColumn = new Column { FullValue = string.Empty };
}
#endregion
#region Properties
public static IColumn EmptyColumn { get; }
public IColumnizedLogLine Parent { get; set; }
public string FullValue
{
get => _fullValue;
set
{
_fullValue = value;
var temp = FullValue;
foreach (var replacement in _replacements)
{
temp = replacement(temp);
}
DisplayValue = temp;
}
}
public string DisplayValue { get; private set; }
public string Text => DisplayValue;
#endregion
#region Public methods
public static Column[] CreateColumns (int count, IColumnizedLogLine parent)
{
return CreateColumns(count, parent, string.Empty);
}
public static Column[] CreateColumns (int count, IColumnizedLogLine parent, string defaultValue)
{
var output = new Column[count];
for (var i = 0; i < count; i++)
{
output[i] = new Column { FullValue = defaultValue, Parent = parent };
}
return output;
}
public override string ToString ()
{
return DisplayValue ?? string.Empty;
}
#endregion
}