6 #include "../common/DBuffer.h"
7 #include "../common/DString.h"
8 #include "../common/bufio.h"
9 #include "../common/StringList.h"
11 #include "sectStringArray.h"
12 #include "sectStringArray.fdh"
15 // decode the raw section data into the given StringList object
16 bool SIFStringArraySect::Decode(const uint8_t *data
, int datalen
, StringList
*out
)
18 const uint8_t *data_end
= data
+ (datalen
- 1);
21 nstrings
= read_U16(&data
, data_end
);
22 for(i
=0;i
<nstrings
;i
++)
26 staterr("SIFStringArraySect::Decode: section corrupt: overran end of data");
31 ReadPascalString(&data
, data_end
, &string
);
33 out
->AddString(string
.String());
41 uint8_t *SIFStringArraySect::Encode(StringList
*strings
, int *datalen_out
)
45 if (strings
->CountItems() > 65535)
47 staterr("SIFStringArraySect::Encode: too many strings in list");
51 buf
.Append16(strings
->CountItems());
54 const char *str
= strings
->StringAt(i
);
57 WritePascalString(str
, &buf
);
60 if (datalen_out
) *datalen_out
= buf
.Length();
61 return buf
.TakeData();
65 void c------------------------------() {}
68 void SIFStringArraySect::ReadPascalString(const uint8_t **data
, const uint8_t *data_end
, DString
*out
)
70 int len
= read_U8(data
, data_end
);
71 if (len
== 255) len
= read_U16(data
, data_end
);
74 for(int i
=0;i
<len
;i
++)
76 out
->AppendChar(read_U8(data
, data_end
));
80 void SIFStringArraySect::WritePascalString(const char *str
, DBuffer
*out
)
82 int len
= strlen(str
);
83 if (len
> 65535) len
= 65535;
95 for(int j
=0;j
<len
;j
++)