def GetHeaderGuardCPPVariable()

in cpplint.py [0:0]


def GetHeaderGuardCPPVariable(filename):
    """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.

  """

    # Restores original filename in case that cpplint is invoked from Emacs's
    # flymake.
    filename = re.sub(r'_flymake\.h$', '.h', filename)
    filename = re.sub(r'/\.flymake/([^/]*)$', r'/\1', filename)
    # Replace 'c++' with 'cpp'.
    filename = filename.replace('C++', 'cpp').replace('c++', 'cpp')

    fileinfo = FileInfo(filename)
    file_path_from_root = fileinfo.RepositoryName()

    def FixupPathFromRoot():
        if _root_debug:
            sys.stderr.write("\n_root fixup, _root = '%s', repository name = '%s'\n"
                             % (_root, fileinfo.RepositoryName()))

        # Process the file path with the --root flag if it was set.
        if not _root:
            if _root_debug:
                sys.stderr.write("_root unspecified\n")
            return file_path_from_root

        def StripListPrefix(lst, prefix):
            # f(['x', 'y'], ['w, z']) -> None  (not a valid prefix)
            if lst[:len(prefix)] != prefix:
                return None
            # f(['a, 'b', 'c', 'd'], ['a', 'b']) -> ['c', 'd']
            return lst[(len(prefix)):]

        # root behavior:
        #   --root=subdir , lstrips subdir from the header guard
        maybe_path = StripListPrefix(PathSplitToList(file_path_from_root),
                                     PathSplitToList(_root))

        if _root_debug:
            sys.stderr.write(("_root lstrip (maybe_path=%s, file_path_from_root=%s," +
                              " _root=%s)\n") % (maybe_path, file_path_from_root, _root))

        if maybe_path:
            return os.path.join(*maybe_path)

        #   --root=.. , will prepend the outer directory to the header guard
        full_path = fileinfo.FullName()
        root_abspath = os.path.abspath(_root)

        maybe_path = StripListPrefix(PathSplitToList(full_path),
                                     PathSplitToList(root_abspath))

        if _root_debug:
            sys.stderr.write(("_root prepend (maybe_path=%s, full_path=%s, " +
                              "root_abspath=%s)\n") % (maybe_path, full_path, root_abspath))

        if maybe_path:
            return os.path.join(*maybe_path)

        if _root_debug:
            sys.stderr.write("_root ignore, returning %s\n" % (file_path_from_root))

        #   --root=FAKE_DIR is ignored
        return file_path_from_root

    file_path_from_root = FixupPathFromRoot()
    return re.sub(r'[^a-zA-Z0-9]', '_', file_path_from_root).upper() + '_'