Commit 551d9bca authored by W. Trevor King's avatar W. Trevor King
Browse files

Fix DynamicLabelsField parsing algorithm.

The old algorithm collapsed null bytes early on.  The new algorithm
keeps the null bytes until the 32-byte chunks have been read.

Parsing hooke/test/data/vclamp_mfp3d/Line0004Point0001.ibw with the
old algorithm gave labels as

  [[], ['RawDeflLVDT'], [], []]

The new algorithm gives

  [[], ['', 'Raw', 'Defl', 'LVDT'], [], []]
parent 75ddaa01
......@@ -458,15 +458,22 @@ class DynamicLabelsField (DynamicStringField):
wave_structure = parents[-1]
wave_data = self._get_structure_data(parents, data, wave_structure)
bin_header = wave_data['bin_header']
d = b''.join(wave_data[self.name])
d = wave_data[self.name]
dim_labels = []
start = 0
for size in bin_header[self._size_field]:
end = start + size
if end > start:
dim_data = d[start:end]
# split null-delimited strings
labels = dim_data.split(b'\x00')
chunks = []
for i in range(size//32):
chunks.append(dim_data[32*i:32*(i+1)])
labels = [b'']
for chunk in chunks:
labels[-1] = labels[-1] + b''.join(chunk)
if b'\x00' in chunk:
labels.append(b'')
labels.pop(-1)
start = end
else:
labels = []
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment