MCPcopy Index your code
hub / github.com/cpplint/cpplint / GetHeaderGuardCPPVariable

Function GetHeaderGuardCPPVariable

cpplint.py:2494–2572  ·  view source on GitHub ↗

Returns the CPP variable that should be used as a header guard. Args: filename: The name of a C++ header file. Returns: The CPP variable that should be used as a header guard in the named file.

(filename)

Source from the content-addressed store, hash-verified

2492
2493
2494def GetHeaderGuardCPPVariable(filename):
2495 """Returns the CPP variable that should be used as a header guard.
2496
2497 Args:
2498 filename: The name of a C++ header file.
2499
2500 Returns:
2501 The CPP variable that should be used as a header guard in the
2502 named file.
2503
2504 """
2505
2506 # Restores original filename in case that cpplint is invoked from Emacs's
2507 # flymake.
2508 filename = re.sub(r"_flymake\.h$", ".h", filename)
2509 filename = re.sub(r"/\.flymake/([^/]*)$", r"/\1", filename)
2510 # Replace 'c++' with 'cpp'.
2511 filename = filename.replace("C++", "cpp").replace("c++", "cpp")
2512
2513 fileinfo = FileInfo(filename)
2514 file_path_from_root = fileinfo.RepositoryName()
2515
2516 def FixupPathFromRoot():
2517 if _root_debug:
2518 sys.stderr.write(
2519 f"\n_root fixup, _root = '{_root}',"
2520 f" repository name = '{fileinfo.RepositoryName()}'\n"
2521 )
2522
2523 # Process the file path with the --root flag if it was set.
2524 if not _root:
2525 if _root_debug:
2526 sys.stderr.write("_root unspecified\n")
2527 return file_path_from_root
2528
2529 def StripListPrefix(lst, prefix):
2530 # f(['x', 'y'], ['w, z']) -> None (not a valid prefix)
2531 if lst[: len(prefix)] != prefix:
2532 return None
2533 # f(['a, 'b', 'c', 'd'], ['a', 'b']) -> ['c', 'd']
2534 return lst[(len(prefix)) :]
2535
2536 # root behavior:
2537 # --root=subdir , lstrips subdir from the header guard
2538 maybe_path = StripListPrefix(PathSplitToList(file_path_from_root), PathSplitToList(_root))
2539
2540 if _root_debug:
2541 sys.stderr.write(
2542 ("_root lstrip (maybe_path=%s, file_path_from_root=%s," + " _root=%s)\n")
2543 % (maybe_path, file_path_from_root, _root)
2544 )
2545
2546 if maybe_path:
2547 return os.path.join(*maybe_path)
2548
2549 # --root=.. , will prepend the outer directory to the header guard
2550 full_path = fileinfo.FullName()
2551 # adapt slashes for windows

Callers 1

ProcessFileDataFunction · 0.85

Calls 3

RepositoryNameMethod · 0.95
FileInfoClass · 0.85
FixupPathFromRootFunction · 0.85

Tested by

no test coverage detected