[cmake-developers] [PATCH] [RFC] handle c dependicies for files?with utf-8 BOM
Evgeniy Dushistov
dushistov at mail.ru
Mon Oct 14 11:10:34 EDT 2013
On Mon, Oct 14, 2013 at 08:47:30AM -0600, clinton at elemtech.com wrote:
> The patch appears to not handle empty files or files with less than 3
> characters. Does it need to?
>
Why do you think that it not handle files with length < 3?
We call std::ifstream::read and then
check read result only if std::ifstream::operator bool return true,
in other case we restore state of std::ifstream with help of
std::ifstream::clear.
You can try my test case for files with zero, one and two
bytes length, it will print the same with or without BOM identification:
#include <fstream>
#include <cstdio>
#include <cassert>
int main(int argc, char *argv[])
{
assert(argc == 2);
std::ifstream fin(argv[1]);
if (fin) {
#if 1//disable and try
static const unsigned char UTF8_BOM[3] = {0xEF, 0xBB, 0xBF};
unsigned char bom[3];
fin.read(reinterpret_cast<char *>(bom), sizeof(bom));
if ((fin && !(bom[0] == UTF8_BOM[0] && bom[1] == UTF8_BOM[1] && bom[2] == UTF8_BOM[2])) || !fin)
{
fin.clear();
fin.seekg(0, std::ios::beg);
}
#endif
char ch;
while (fin.get(ch))
printf("we read %X\n", int(ch));
} else {
printf("Can not open %s\n", argv[1]);
}
return 0;
}
--
/Evgeniy
More information about the cmake-developers
mailing list