Re: File-Reading Best Practices?
Andreas Wenzke <andreas.wenzke@gmx.de> writes:
I want to parse an XML file manually (but my question would be the same
for any other file format):
What are best-practice guidelines for doing that?
I currently use a char buffer in conjunction with istream::read and then
walk through the buffer step by step.
You seem to think about implementations ("char buffer") early.
I prefer to think about interfaces (.getNextSymbol()) early.
A char is a byte, while XML files are composed of Unicode
characters (code points). If you read them as chars, you
will first have to decode them, so you should at least
implement an UTF-8-reader.
However, problems will arise when tags span across the buffer, i.e. when
the buffer contains "<h" at the end and the next characters to be read
from the stream are "tml>".
I'm considering using memmove, but I just think there has to be a better
option.
Again, it seems strange to me, to mention parsing and then
mention memmove, too low-level thinking. You are thinking
about low-level implementation details too early. They should
be hidden behind interfaces, so that they can be changed
later.
As this is for a university project, I'm not allowed to use the STL
(std::string and so on).
This newsgroup is about using C++, and when you are not
allowed to use ::std::string and so on, you are not allowed
to use C++, so you are in the wrong newsgroup. In C++, also,
there is nothing that is being called ?STL? by
ISO/IEC 14882:2003(E), so you possibly are being taught
out-dated terms. Maybe that university also is too low-level.