CMake/FStream.cxx
KWSys Robot f096786d54 KWSys 2014-03-03 (b1916e0a)
Extract upstream KWSys using the following shell commands.

$ git archive --prefix=upstream-kwsys/ b1916e0a | tar x
$ git shortlog --no-merges --abbrev=8 --format='%h %s' 606d7d6f..b1916e0a
Adrien Destugues (1):
      b1916e0a SystemInformation: Update CPU count code for Haiku

Clinton Stimpson (3):
      0d8ef429 Encoding:  Help enforce the use of wide apis on Windows.
      cfbc1cc8 FStream: Remove unused basic_filebuf declaration.
      b3b20cc0 FStream: Add ability to detect BOM.

Jiri Malak (1):
      e66d99b8 SystemTools: Fix compilation with Open Watcom

Matt McCormick (1):
      b3db597b SystemInformation: Mark EXECINFO_LIB as advanced

Change-Id: I154a92be7a3ec4c7c12bffbfcd7b50ec7de53c5f
2014-03-04 10:19:28 -05:00

77 lines
1.8 KiB
C++

/*============================================================================
KWSys - Kitware System Library
Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
Distributed under the OSI-approved BSD License (the "License");
see accompanying file Copyright.txt for details.
This software is distributed WITHOUT ANY WARRANTY; without even the
implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the License for more information.
============================================================================*/
#include "kwsysPrivate.h"
#include KWSYS_HEADER(FStream.hxx)
// Work-around CMake dependency scanning limitation. This must
// duplicate the above list of headers.
#if 0
# include "FStream.hxx.in"
#endif
namespace KWSYS_NAMESPACE
{
namespace FStream
{
BOM ReadBOM(std::istream& in)
{
if(!in.good())
{
return BOM_None;
}
unsigned long orig = in.tellg();
unsigned char bom[4];
in.read(reinterpret_cast<char*>(bom), 2);
if(!in.good())
{
in.seekg(orig);
return BOM_None;
}
if(bom[0] == 0xEF && bom[1] == 0xBB)
{
in.read(reinterpret_cast<char*>(bom+2), 1);
if(in.good() && bom[2] == 0xBF)
{
return BOM_UTF8;
}
}
else if(bom[0] == 0xFE && bom[1] == 0xFF)
{
return BOM_UTF16BE;
}
else if(bom[0] == 0x00 && bom[1] == 0x00)
{
in.read(reinterpret_cast<char*>(bom+2), 2);
if(in.good() && bom[2] == 0xFE && bom[3] == 0xFF)
{
return BOM_UTF32BE;
}
}
else if(bom[0] == 0xFF && bom[1] == 0xFE)
{
unsigned long p = in.tellg();
in.read(reinterpret_cast<char*>(bom+2), 2);
if(in.good() && bom[2] == 0x00 && bom[3] == 0x00)
{
return BOM_UTF32LE;
}
in.seekg(p);
return BOM_UTF16LE;
}
in.seekg(orig);
return BOM_None;
}
} // FStream namespace
} //KWSYS_NAMESPACE