.. _program_listing_file_src_common_utils.h: Program Listing for File utils.h ================================ |exhale_lsh| :ref:`Return to documentation for file ` (``src/common/utils.h``) .. |exhale_lsh| unicode:: U+021B0 .. UPWARDS ARROW WITH TIP LEFTWARDS .. code-block:: cpp #pragma once #include #include #include namespace marian { namespace utils { void trim(std::string& s); void trimLeft(std::string& s); void trimRight(std::string& s); void split(const std::string& line, std::vector& pieces, const std::string& del = " ", bool keepEmpty = false, bool anyOf = false); void splitAny(const std::string& line, std::vector& pieces, const std::string& del = " ", bool keepEmpty = false); // Split tab-separated line into the specified number of fields void splitTsv(const std::string& line, std::vector& fields, size_t numFields); std::vector split(const std::string& line, const std::string& del = " ", bool keepEmpty = false, bool anyOf = false); std::vector splitAny(const std::string& line, const std::string& del = " ", bool keepEmpty = false); // Return a string which is the concatenation of the strings in the given vector std::string join(const std::vector& words, const std::string& del = " "); // Return a string which is the concatenation of values from the given vector of integers std::string join(const std::vector& words, const std::string& del = " "); // Return a string which is the concatenation of values from the given vector of floats std::string join(const std::vector& words, const std::string& del = " ", size_t prec = 5); std::string exec(const std::string& cmd, const std::vector& args = {}, const std::string& arg = ""); std::pair hostnameAndProcessId(); std::string withCommas(size_t n); bool beginsWith(const std::string& text, const std::string& prefix); bool endsWith(const std::string& text, const std::string& suffix); std::string utf8ToUpper(const std::string& s); std::string utf8ToLower(const std::string& s); std::string utf8Capitalized(const std::string& word); // capitalize the first character only std::string toEnglishTitleCase(const std::string& s); std::u32string utf8ToUnicodeString(const std::string& s); std::string utf8FromUnicodeString(const std::u32string& s); std::u16string utf8ToUtf16String(const std::string& s); std::string utf8FromUtf16String(const std::u16string& s); bool isContinuousScript(char32_t c); std::string findReplace(const std::string& in, const std::string& what, const std::string& withWhat, bool all = false); double parseDouble(std::string s); double parseNumber(std::string s); // prints vector values with a custom label. template void Debug(const T *arr, size_t size, const std::string &str) { std::cerr << str << ":" << size << ": "; for (size_t i = 0; i < size; ++i) { std::cerr << arr[i] << " "; } std::cerr << std::endl; } template void Debug(const std::vector &arr, const std::string &str) { Debug(arr.data(), arr.size(), str); } } // namespace utils } // namespace marian