diff options
author | KWSys Robot <kwrobot@kitware.com> | 2014-03-03 13:32:13 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2014-03-04 15:19:28 (GMT) |
commit | f096786d5428505f8313f6b01f4631f5a34b27a2 (patch) | |
tree | 08bf378742ee9bde2006ba48d0e0ab5369ca0741 /FStream.cxx | |
parent | 4709c7ad4eb4d11d653f552b9ac1f39af5cc1014 (diff) | |
download | CMake-f096786d5428505f8313f6b01f4631f5a34b27a2.zip CMake-f096786d5428505f8313f6b01f4631f5a34b27a2.tar.gz CMake-f096786d5428505f8313f6b01f4631f5a34b27a2.tar.bz2 |
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
Diffstat (limited to 'FStream.cxx')
-rw-r--r-- | FStream.cxx | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/FStream.cxx b/FStream.cxx new file mode 100644 index 0000000..018652c --- /dev/null +++ b/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 |