Coverage Report

Created: 2026-09-01 06:43

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/shaderc/glslc/src/file.h
Line
Count
Source
1
// Copyright 2015 The Shaderc Authors. All rights reserved.
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
6
//
7
//     http://www.apache.org/licenses/LICENSE-2.0
8
//
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
14
15
#ifndef GLSLC_FILE_H_
16
#define GLSLC_FILE_H_
17
18
#include "libshaderc_util/string_piece.h"
19
20
namespace glslc {
21
22
// Given a file name, returns its extension. If no extension exists,
23
// returns an empty string_piece.
24
shaderc_util::string_piece GetFileExtension(
25
    const shaderc_util::string_piece& filename);
26
27
// Returns true if the given file name ends with a known shader file extension.
28
0
inline bool IsStageFile(const shaderc_util::string_piece& filename) {
29
0
  const shaderc_util::string_piece extension =
30
0
      glslc::GetFileExtension(filename);
31
0
  return extension == "vert" || extension == "frag" || extension == "tesc" ||
32
0
         extension == "tese" || extension == "geom" || extension == "comp";
33
0
}
34
35
// Returns the file extension if is either "glsl" or "hlsl", or an empty
36
// string otherwise.
37
inline std::string GetGlslOrHlslExtension(
38
0
    const shaderc_util::string_piece& filename) {
39
0
  auto extension = glslc::GetFileExtension(filename);
40
0
  if ((extension == "glsl") || (extension == "hlsl")) return extension.str();
41
0
  return "";
42
0
}
43
44
}  // namespace glslc
45
46
#endif  // GLSLC_FILE_H_