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

DomCR / ACadSharp / 17710069422

14 Sep 2025 10:41AM UTC coverage: 78.147% (-0.1%) from 78.245%
17710069422

Pull #787

github

web-flow
Merge 57c93f01a into 2bca657be
Pull Request #787: Shape shx

6682 of 9285 branches covered (71.97%)

Branch coverage included in aggregate %.

139 of 201 new or added lines in 6 files covered. (69.15%)

8 existing lines in 2 files now uncovered.

25824 of 32311 relevant lines covered (79.92%)

107954.76 hits per line

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

88.24
/src/ACadSharp/IO/ShapeFile.cs
1
using System;
2
using System.Collections.Generic;
3
using System.IO;
4
using System.Linq;
5
using System.Text;
6

7
namespace ACadSharp.IO
8
{
9
        public partial class ShapeFile
10
        {
11
                public const string DefaultShapeFile = "ltypeshp.shx";
12

13
                private const string _sentinelV1 = "AutoCAD-86 shapes 1.0";
14

15
                public static void Open(string file)
16
                {
1✔
17
                        if (string.IsNullOrEmpty(file))
1!
NEW
18
                        {
×
NEW
19
                                throw new ArgumentNullException(nameof(file));
×
20
                        }
21

22
                        using (BinaryReader reader = new BinaryReader(File.OpenRead(file)))
1✔
23
                        {
1✔
24
                                byte[] sentinel = reader.ReadBytes(21);
1✔
25
                                StringBuilder sb = new StringBuilder(21);
1✔
26
                                sb.Append(sentinel.Select(b => (char)b).ToArray());
22✔
27

28
                                if (!sb.ToString().Equals(_sentinelV1, StringComparison.InvariantCulture))
1!
NEW
29
                                {
×
NEW
30
                                        throw new ArgumentException("Not a valid Shape binary file .SHX.", nameof(file));
×
31
                                }
32

33
                                reader.ReadBytes(3);
1✔
34

35
                                ushort firstShape = reader.ReadUInt16();
1✔
36
                                ushort lastShape = reader.ReadUInt16();
1✔
37
                                ushort nEntries = reader.ReadUInt16();
1✔
38

39
                                var shapes = new List<(ushort, ushort)>(nEntries);
1✔
40
                                for (int i = 0; i < nEntries; i++)
4✔
41
                                {
1✔
42
                                        var index = reader.ReadUInt16();
1✔
43
                                        var size = reader.ReadUInt16();
1✔
44
                                        shapes.Add((index, size));
1✔
45
                                }
1✔
46

47
                                for (int i = 0; i < nEntries; i++)
4✔
48
                                {
1✔
49
                                        string name = nullTerminatedString(reader, Encoding.ASCII);
1✔
50
                                        byte[] shape = reader.ReadBytes(shapes[i].Item2 - (name.Length + 1));
1✔
51

52
                                        Geometry.Create(name, shape);
1✔
53
                                }
1✔
54
                        }
1✔
55
                }
1✔
56

57
                private static string nullTerminatedString(BinaryReader reader, Encoding encoding)
58
                {
1✔
59
                        byte c = reader.ReadByte();
1✔
60
                        List<byte> bytes = new List<byte>();
1✔
61
                        while (c != 0) // strings always end with a 0 byte (char NULL)
12✔
62
                        {
11✔
63
                                bytes.Add(c);
11✔
64
                                c = reader.ReadByte();
11✔
65
                        }
11✔
66
                        return encoding.GetString(bytes.ToArray(), 0, bytes.Count);
1✔
67
                }
1✔
68
        }
69
}
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

© 2025 Coveralls, Inc