#ifndef _utl_Strings_h_ #define _utl_Strings_h_ #include #include #include #include namespace utl { std::string ToStringOfIds(std::vector ids); inline const char* Plural(const int n) { return (n > 1) ? "s" : ""; } template inline std::string ToStringOfMapKeys(const Map& m, const std::string& quote = "'", const std::string& separator = ", ") { std::ostringstream os; typename Map::const_iterator mIt = m.begin(); if (mIt != m.end()) { os << quote << mIt->first << quote; for (++mIt; mIt != m.end(); ++mIt) os << separator << quote << mIt->first << quote; } return os.str(); } void StationIdListWithMessage(const std::vector& stationIds, const std::string& message); std::string StationIdListWithMessageString(const std::vector& stationIds, const std::string& message); /// converts integer-type numbers into a string of binary representation template std::string ToBinaryString(const T number, const int maxBits = 8*sizeof(T), const char separator = ' ', const int stride = 4) { std::ostringstream os; int bit = std::min(maxBits, int(8*sizeof(T))); if (bit) { T mask = (T(1) << --bit); os << bool(number & mask); for (--bit; bit >= 0; --bit) { mask >>= 1; if (!((bit+1) % stride)) os << separator; os << bool(number & mask); } } return os.str(); } } #endif