diff --git a/common/src/util.cpp b/common/src/util.cpp index 5c02379e7e1f64696d6bf77e0bc784733f610aa6..d6362cc6441c4614efde9b0d39796fed11faa79b 100644 --- a/common/src/util.cpp +++ b/common/src/util.cpp @@ -11,31 +11,28 @@ #include <ctime> #include <algorithm> -namespace util -{ - -int printedLength(std::string_view s) +int util::printedLength(std::string_view s) { return splitAsUtf8(s).size(); } -std::string_view getFilenameFromPath(std::string_view s) +std::string_view util::getFilenameFromPath(std::string_view s) { int indexOfSlash = s.find_last_of('/'); return {s.data()+indexOfSlash+1, s.size()-1-indexOfSlash}; } -bool isSeparator(utf8char c) +bool util::isSeparator(utf8char c) { return c == ' ' || isIllegal(c); } -bool isIllegal(utf8char c) +bool util::isIllegal(utf8char c) { return c == '\n' || c == '\t'; } -std::vector<std::string_view> split(std::string_view remaining, char delimiter) +std::vector<std::string_view> util::split(std::string_view remaining, char delimiter) { std::vector<std::string_view> result; @@ -52,7 +49,7 @@ std::vector<std::string_view> split(std::string_view remaining, char delimiter) return result; } -utf8string splitAsUtf8(std::string_view s) +util::utf8string util::splitAsUtf8(std::string_view s) { utf8string result; const char * beginPtr = s.data(); @@ -78,28 +75,28 @@ utf8string splitAsUtf8(std::string_view s) return result; } -void warning(std::string_view message, const std::experimental::source_location & location) +void util::warning(std::string_view message, const std::experimental::source_location & location) { fmt::print(stderr, "WARNING ({}) : {}\n", location, message); } -void error(std::string_view message, const std::experimental::source_location & location) +void util::error(std::string_view message, const std::experimental::source_location & location) { fmt::print(stderr, "ERROR ({}) : {}\n", location, message); exit(1); } -void error(const std::exception & e, const std::experimental::source_location & location) +void util::error(const std::exception & e, const std::experimental::source_location & location) { error(e.what(), location); } -void myThrow(std::string_view message, const std::experimental::source_location & location) +void util::myThrow(std::string_view message, const std::experimental::source_location & location) { throw std::invalid_argument(fmt::format("from ({}) {}", location, message)); } -std::string int2HumanStr(int number) +std::string util::int2HumanStr(int number) { std::string nb = std::to_string(number); std::string result; @@ -114,7 +111,7 @@ std::string int2HumanStr(int number) return result; } -bool doIfNameMatch(const std::regex & reg, const std::string & name, const std::function<void(const std::smatch &)> & f) +bool util::doIfNameMatch(const std::regex & reg, const std::string & name, const std::function<void(const std::smatch &)> & f) { std::smatch sm; std::regex_match(name, sm, reg); @@ -124,7 +121,5 @@ bool doIfNameMatch(const std::regex & reg, const std::string & name, const std:: f(sm); return true; -}; - -}; +}