#ifndef C10_UTIL_STRINGUTIL_H_ #define C10_UTIL_STRINGUTIL_H_ #include #include #include #include #include #include #include namespace c10 { namespace detail { // Obtains the base name from a full path. C10_API std::string StripBasename(const std::string& full_path); inline std::ostream& _str(std::ostream& ss) { return ss; } template inline std::ostream& _str(std::ostream& ss, const T& t) { ss << t; return ss; } template inline std::ostream& _str(std::ostream& ss, const T& t, const Args&... args) { return _str(_str(ss, t), args...); } } // namespace detail // Convert a list of string-like arguments into a single string. template inline std::string str(const Args&... args) { std::ostringstream ss; detail::_str(ss, args...); return ss.str(); } // Specializations for already-a-string types. template <> inline std::string str(const std::string& str) { return str; } inline std::string str(const char* c_str) { return c_str; } template inline std::string Join(const std::string& delimiter, const Container& v) { std::stringstream s; int cnt = static_cast(v.size()) - 1; for (auto i = v.begin(); i != v.end(); ++i, --cnt) { s << (*i) << (cnt ? delimiter : ""); } return s.str(); } // Replace all occurrences of "from" substring to "to" string. // Returns number of replacements size_t C10_API ReplaceAll(std::string& s, const char* from, const char* to); /// Represents a location in source code (for debugging). struct C10_API SourceLocation { const char* function; const char* file; uint32_t line; }; std::ostream& operator<<(std::ostream& out, const SourceLocation& loc); } // namespace c10 #endif // C10_UTIL_STRINGUTIL_H_