On Mon, Oct 14, 2013 at 08:47:30AM -0600, [email protected] 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
--

Powered by www.kitware.com

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/cgi-bin/mailman/listinfo/cmake-developers

Reply via email to