Coverage Report

Created: 2026-10-28 06:38

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
71.2k
{
17
71.2k
  if (!in.good()) {
18
0
    return BOM_None;
19
0
  }
20
71.2k
  unsigned long orig = in.tellg();
21
71.2k
  unsigned char bom[4];
22
71.2k
  in.read(reinterpret_cast<char*>(bom), 2);
23
71.2k
  if (!in.good()) {
24
368
    in.clear();
25
368
    in.seekg(orig);
26
368
    return BOM_None;
27
368
  }
28
70.9k
  if (bom[0] == 0xEF && bom[1] == 0xBB) {
29
357
    in.read(reinterpret_cast<char*>(bom + 2), 1);
30
357
    if (in.good() && bom[2] == 0xBF) {
31
270
      return BOM_UTF8;
32
270
    }
33
70.5k
  } else if (bom[0] == 0xFE && bom[1] == 0xFF) {
34
31
    return BOM_UTF16BE;
35
70.5k
  } else if (bom[0] == 0x00 && bom[1] == 0x00) {
36
185
    in.read(reinterpret_cast<char*>(bom + 2), 2);
37
185
    if (in.good() && bom[2] == 0xFE && bom[3] == 0xFF) {
38
19
      return BOM_UTF32BE;
39
19
    }
40
70.3k
  } else if (bom[0] == 0xFF && bom[1] == 0xFE) {
41
183
    unsigned long p = in.tellg();
42
183
    in.read(reinterpret_cast<char*>(bom + 2), 2);
43
183
    if (in.good() && bom[2] == 0x00 && bom[3] == 0x00) {
44
28
      return BOM_UTF32LE;
45
28
    }
46
155
    in.seekg(p);
47
155
    return BOM_UTF16LE;
48
183
  }
49
70.4k
  in.clear();
50
70.4k
  in.seekg(orig);
51
70.4k
  return BOM_None;
52
70.9k
}
53
54
} // FStream namespace
55
} // KWSYS_NAMESPACE