• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

DomCR / ACadSharp / 29143042407

11 Jul 2026 06:34AM UTC coverage: 2.912% (-73.0%) from 75.918%
29143042407

push

github

web-flow
Merge pull request #1146 from ilCosmico/acds-read-payload-anchor

Read the AcDs payload area offset from the data segment header

264 of 12999 branches covered (2.03%)

Branch coverage included in aggregate %.

0 of 30 new or added lines in 1 file covered. (0.0%)

31243 existing lines in 465 files now uncovered.

1337 of 41984 relevant lines covered (3.18%)

5.38 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/ACadSharp/Text/TextProcessor.cs
1
using CSUtilities.Extensions;
2
using System;
3
using System.Collections.Generic;
4
using System.Text;
5

6
namespace ACadSharp.Text
7
{
8
        public static class TextProcessor
9
        {
10
                public static string Parse(string text, out List<string> groups)
UNCOV
11
                {
×
UNCOV
12
                        groups = new List<string>();
×
UNCOV
13
                        if (string.IsNullOrEmpty(text))
×
14
                        {
×
15
                                return text;
×
16
                        }
17

UNCOV
18
                        StringBuilder sb = new StringBuilder();
×
19

UNCOV
20
                        int index = 0;
×
UNCOV
21
                        bool openGroup = false;
×
UNCOV
22
                        while (index < text.Length)
×
UNCOV
23
                        {
×
UNCOV
24
                                char? prev = text.TryGet(index - 1);
×
UNCOV
25
                                char? current = text.TryGet(index);
×
UNCOV
26
                                char? next = text.TryGet(index + 1);
×
27

UNCOV
28
                                if (current == '\\' && next.HasValue)
×
UNCOV
29
                                {
×
UNCOV
30
                                        switch (next)
×
31
                                        {
32
                                                case '}':
33
                                                case '{':
34
                                                case '\\':
UNCOV
35
                                                        sb.Append(next);
×
UNCOV
36
                                                        index += 2;
×
UNCOV
37
                                                        break;
×
38
                                                case 'A':
UNCOV
39
                                                        jump(text, index, out index);
×
UNCOV
40
                                                        break;
×
41
                                                case 'c':
42
                                                case 'C':
UNCOV
43
                                                        processColor(text, index, out index);
×
UNCOV
44
                                                        break;
×
45
                                                case 'f':
46
                                                case 'F':
UNCOV
47
                                                        processFont(text, index, out index);
×
UNCOV
48
                                                        break;
×
49
                                                case 'h':
50
                                                case 'H':
UNCOV
51
                                                        processHeight(text, index, out index);
×
UNCOV
52
                                                        break;
×
53
                                                case 'p':
UNCOV
54
                                                        processJustification(text, index, out index);
×
UNCOV
55
                                                        break;
×
56
                                                case 'P':
57
                                                case 'n':
UNCOV
58
                                                        sb.Append(Environment.NewLine);
×
UNCOV
59
                                                        index += 2;
×
UNCOV
60
                                                        break;
×
61
                                                default:
UNCOV
62
                                                        index++;
×
UNCOV
63
                                                        break;
×
64
                                        }
UNCOV
65
                                }
×
UNCOV
66
                                else if (current == '{' && prev != '\\')
×
UNCOV
67
                                {
×
UNCOV
68
                                        openGroup = true;
×
UNCOV
69
                                        index++;
×
UNCOV
70
                                }
×
UNCOV
71
                                else if (current == '}' && prev != '\\')
×
UNCOV
72
                                {
×
UNCOV
73
                                        openGroup = false;
×
UNCOV
74
                                        index++;
×
UNCOV
75
                                }
×
76
                                else
UNCOV
77
                                {
×
UNCOV
78
                                        sb.Append(current);
×
UNCOV
79
                                        index++;
×
UNCOV
80
                                }
×
UNCOV
81
                        }
×
82

UNCOV
83
                        return sb.ToString();
×
UNCOV
84
                }
×
85

86

87
                public static string Unescape(string text)
88
                {
×
89
                        if (string.IsNullOrEmpty(text))
×
90
                        {
×
91
                                return text;
×
92
                        }
93

94
                        StringBuilder sb = new StringBuilder();
×
95

96
                        int index = 0;
×
97
                        bool openGroup = false;
×
98
                        while (index < text.Length)
×
99
                        {
×
100
                                int currIndex = text.IndexOf(@"\", index);
×
101
                                if (currIndex <= 0)
×
102
                                {
×
103
                                        string s = text.Substring(index, text.Length - index);
×
104
                                        if (openGroup && s.Contains("}"))
×
105
                                        {
×
106
                                                s = s.Replace("}", string.Empty);
×
107
                                                openGroup = false;
×
108
                                        }
×
109
                                        sb.Append(s);
×
110
                                        break;
×
111
                                }
112

113
                                char prev = text[currIndex - 1];
×
114
                                char current = text[currIndex];
×
115
                                char next = text[currIndex + 1];
×
116

117
                                if (prev == '{')
×
118
                                {
×
119
                                        currIndex--;
×
120
                                        openGroup = true;
×
121
                                }
×
122

123
                                if (currIndex > index)
×
124
                                {
×
125
                                        string s = text.Substring(index, currIndex - index);
×
126
                                        if (openGroup && s.Contains("}"))
×
127
                                        {
×
128
                                                s = s.Replace("}", string.Empty);
×
129
                                                openGroup = false;
×
130
                                        }
×
131
                                        sb.Append(s);
×
132
                                }
×
133

134
                                int f;
135
                                switch (next)
×
136
                                {
137
                                        case 'f':
138
                                        case 'F':
139
                                                processFont(text, currIndex, out f);
×
140
                                                currIndex = f;
×
141
                                                break;
×
142
                                        case 'c':
143
                                        case 'C':
144
                                                processColor(text, currIndex, out f);
×
145
                                                currIndex = f;
×
146
                                                break;
×
147
                                        case 'P':
148
                                        case 'n':
149
                                                sb.Append(Environment.NewLine);
×
150
                                                currIndex += 2;
×
151
                                                break;
×
152
                                        case 'r':
153
                                                break;
×
154
                                        case '}':
155
                                        case '{':
156
                                        case '\\':
157
                                                sb.Append(next);
×
158
                                                break;
×
159
                                }
160

161
                                index = currIndex;
×
162
                        }
×
163

164
                        return sb.ToString();
×
165
                }
×
166

167
                private static void processFont(string text, int start, out int end)
UNCOV
168
                {
×
169
                        //Example:
170
                        //- Font: {\\fCalibri|b0|i0|c0|p34;Calibri\\Fcdm|c0; CDM \\fConsolas|b0|i0|c0|p49;Consolas\\P}
UNCOV
171
                        end = text.IndexOf(';', start);
×
UNCOV
172
                        end += 1;
×
UNCOV
173
                        var data = text.Substring(start, end - start).Split('|');
×
174

UNCOV
175
                        FontData fontData = new FontData
×
UNCOV
176
                        {
×
UNCOV
177
                                Name = data[0],
×
UNCOV
178
                        };
×
UNCOV
179
                }
×
180

181
                private static void jump(string text, int start, out int end)
UNCOV
182
                {
×
183
                        //Example:
184
                        //\\(unknown escape code)(escape text);
UNCOV
185
                        end = text.IndexOf(';', start);
×
UNCOV
186
                        end += 1;
×
UNCOV
187
                }
×
188

189
                private static void processColor(string text, int start, out int end)
UNCOV
190
                {
×
191
                        //Example:
192
                        //- Color text {\\C3;green}, {\\C5;blue}, {\\C1;red}, ByLayer, {\\C0;ByBlock}, {\\C21;\\c5872631;TrueColor}
UNCOV
193
                        end = text.IndexOf(';', start);
×
UNCOV
194
                        end += 1;
×
UNCOV
195
                }
×
196

197
                private static void processHeight(string text, int start, out int end)
UNCOV
198
                {
×
199
                        //Example:
200
                        //- {\\H2x;Double height \\H0.875x;height is: 0.35\\H1.14286x;\\P}
UNCOV
201
                        end = text.IndexOf(';', start);
×
UNCOV
202
                        end += 1;
×
UNCOV
203
                }
×
204

205
                private static void processJustification(string text, int start, out int end)
UNCOV
206
                {
×
207
                        //Example:
208
                        //\\pxqc;Text in the center\\P\\pq*;Hello this is an mText\\P
UNCOV
209
                        end = text.IndexOf(';', start);
×
UNCOV
210
                        end += 1;
×
UNCOV
211
                }
×
212
        }
213

214
        internal struct FontData
215
        {
UNCOV
216
                public string Name { get; set; }
×
217
        }
218
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc