stevemarple / IniFile

Arduino library to parse ini files.
GNU Lesser General Public License v2.1
87 stars 45 forks source link

Ignoring/truncating lines that are too long? #36

Open HankLloydRight opened 1 year ago

HankLloydRight commented 1 year ago

Hello,

If I change line 423 in IniFile.cpp from:

return errorBufferTooSmall; to return errorNoError;

Would that result in the validate function not returning an error but instead just truncating lines that are too long (instead of returning an invalid file error)?

What's your reasoning behind invalidating the entire file if any lines are longer than the buffer length instead of just silently (or not silently) truncating them?

My thinking is if an end-user inadvertently has one line go over inibufferlen, the entire file is rejected, instead of just the offending line(s).

Thank you.

stevemarple commented 1 year ago

The file is processed line-by-line which enables IniFile to work with only a small amount of RAM. The parser expects that a buffer contains an entire line. I've not tried but I expect that the change you suggested would be equivalent to splitting the line by inserting a newline character, it won't truncate lines that are too long.

I don't see any point in truncating lines that are too long for the buffer. It is reasonable to assume that all provided key/value pairs are important. So either the file is valid and can be parsed, or else it is not valid.

If you need to support longer line lengths then you need to increase the buffer size.

HankLloydRight commented 1 year ago

If you need to support longer line lengths then you need to increase the buffer size.

I'm thinking more for comment lines which can be safely ignored and has the chance of a user typing too much.

HankLloydRight commented 1 year ago

I guess what I'm asking is it possible for the Ini file validation check to ignore lines that just comments? But continue to check actual key/value pairs for the pre-set buffer length limit.

So end-users who are modifying the ini files can type whatever comments they want without fear of going over a pre-set buffer length (say 100 bytes) and inadvertently invalidating the ini file.

thanks.