git repos / sago_web_git

src/util.h

browsing at commit = 4fe276c400f51581a3858e55f7b9a48a1f90f419

raw · blame · history

#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);

// 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);

} // namespace util