src/util.h
browsing at commit = 9881d02ac31dadb3794f4728eb6cef4afe5721d3
#pragma once
#include <cstdint>
#include <ctime>
#include <string>
namespace util {
// True if every character is a lowercase hex digit and the length is plausible
// for an abbreviated or full git object id.
bool is_hex_oid(const std::string &s);
// Human readable byte size, e.g. "1.2 KiB".
std::string human_size(uint64_t bytes);
// UTC timestamp formatted as "YYYY-MM-DD HH:MM".
std::string format_time(std::time_t t);
// Last path component of a '/'-separated path.
std::string basename(const std::string &path);
// Everything before the last '/', or "" if there is no '/'.
std::string parent_path(const std::string &path);
// Remove leading and trailing '/' characters.
std::string trim_slashes(const std::string &path);
// Replaces every character outside [A-Za-z0-9._-] with '_', so the result is
// safe to use as a single filesystem path component.
std::string sanitize_filename(const std::string &name);
// Whether author/committer/tagger email addresses may be shown. False unless
// the SHOW_EMAILS environment variable is "1". Evaluated once.
bool show_emails();
// True for paths ending in a markdown extension (.md, .markdown), case
// insensitive.
bool is_markdown_path(const std::string &path);
// MIME type for a recognised image path by extension (e.g. "image/png"), or
// "" when the path is not a recognised image. Case insensitive.
std::string image_mime_type(const std::string &path);
} // namespace util