Skip to content

Commit 4b1a55c

Browse files
committed
RF: helper function for converting str to int
Add / use helper function for converting string to integer, where empty string maps to 0.
1 parent aa4db53 commit 4b1a55c

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

nibabel/gifti/parse_gifti_fast.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,11 @@ def read_data_block(encoding, endian, ordering, datatype, shape, data):
7777
return newarr
7878

7979

80+
def _str2int(in_str):
81+
# Convert string to integer, where empty string gives 0
82+
return int(in_str) if in_str else 0
83+
84+
8085
class GiftiImageParser(XmlParser):
8186

8287
def __init__(self, encoding=None, buffer_size=35000000, verbose=0):
@@ -186,8 +191,8 @@ def StartElementHandler(self, name, attrs):
186191
self.da.endian = gifti_endian_codes.code[attrs["Endian"]]
187192
if "ExternalFileName" in attrs:
188193
self.da.ext_fname = attrs["ExternalFileName"]
189-
if "ExternalFileOffset" in attrs and attrs["ExternalFileOffset"]:
190-
self.da.ext_offset = int(attrs["ExternalFileOffset"])
194+
if "ExternalFileOffset" in attrs:
195+
self.da.ext_offset = _str2int(attrs["ExternalFileOffset"])
191196
self.img.darrays.append(self.da)
192197
self.fsm_state.append('DataArray')
193198

0 commit comments

Comments
 (0)