diff options
author | Brad King <brad.king@kitware.com> | 2014-03-04 15:19:33 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2014-03-04 15:19:33 (GMT) |
commit | 7db95df39d8c191f3de92f4d60a0e4106700dda5 (patch) | |
tree | 2ad8cf29089fb986eb82a397e4ed87642a06c835 /Source/kwsys/FStream.cxx | |
parent | 74b982ce734dd55a4155ba8ba0462fef894d6ec0 (diff) | |
parent | f096786d5428505f8313f6b01f4631f5a34b27a2 (diff) | |
download | CMake-7db95df39d8c191f3de92f4d60a0e4106700dda5.zip CMake-7db95df39d8c191f3de92f4d60a0e4106700dda5.tar.gz CMake-7db95df39d8c191f3de92f4d60a0e4106700dda5.tar.bz2 |
Merge branch 'upstream-kwsys' into update-kwsys
Diffstat (limited to 'Source/kwsys/FStream.cxx')
-rw-r--r-- | Source/kwsys/FStream.cxx | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/Source/kwsys/FStream.cxx b/Source/kwsys/FStream.cxx new file mode 100644 index 0000000..018652c --- /dev/null +++ b/Source/kwsys/FStream.cxx @@ -0,0 +1,76 @@ +/*============================================================================ + 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 |