Coverage Report

Created: 2026-02-09 06:05

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/CMake/Source/kwsys/FStream.cxx
Line
Count
Source
1
/* Distributed under the OSI-approved BSD 3-Clause License.  See accompanying
2
   file Copyright.txt or https://cmake.org/licensing#kwsys for details.  */
3
#include "kwsysPrivate.h"
4
#include KWSYS_HEADER(FStream.hxx)
5
6
// Work-around CMake dependency scanning limitation.  This must
7
// duplicate the above list of headers.
8
#if 0
9
#  include "FStream.hxx.in"
10
#endif
11
12
namespace KWSYS_NAMESPACE {
13
namespace FStream {
14
15
BOM ReadBOM(std::istream& in)
16
0
{
17
0
  if (!in.good()) {
18
0
    return BOM_None;
19
0
  }
20
0
  unsigned long orig = in.tellg();
21
0
  unsigned char bom[4];
22
0
  in.read(reinterpret_cast<char*>(bom), 2);
23
0
  if (!in.good()) {
24
0
    in.clear();
25
0
    in.seekg(orig);
26
0
    return BOM_None;
27
0
  }
28
0
  if (bom[0] == 0xEF && bom[1] == 0xBB) {
29
0
    in.read(reinterpret_cast<char*>(bom + 2), 1);
30
0
    if (in.good() && bom[2] == 0xBF) {
31
0
      return BOM_UTF8;
32
0
    }
33
0
  } else if (bom[0] == 0xFE && bom[1] == 0xFF) {
34
0
    return BOM_UTF16BE;
35
0
  } else if (bom[0] == 0x00 && bom[1] == 0x00) {
36
0
    in.read(reinterpret_cast<char*>(bom + 2), 2);
37
0
    if (in.good() && bom[2] == 0xFE && bom[3] == 0xFF) {
38
0
      return BOM_UTF32BE;
39
0
    }
40
0
  } else if (bom[0] == 0xFF && bom[1] == 0xFE) {
41
0
    unsigned long p = in.tellg();
42
0
    in.read(reinterpret_cast<char*>(bom + 2), 2);
43
0
    if (in.good() && bom[2] == 0x00 && bom[3] == 0x00) {
44
0
      return BOM_UTF32LE;
45
0
    }
46
0
    in.seekg(p);
47
0
    return BOM_UTF16LE;
48
0
  }
49
0
  in.clear();
50
0
  in.seekg(orig);
51
0
  return BOM_None;
52
0
}
53
54
} // FStream namespace
55
} // KWSYS_NAMESPACE