String.h

Go to the documentation of this file.
00001 
00020 #ifndef HYPERTABLE_STRING_H
00021 #define HYPERTABLE_STRING_H
00022 
00023 #include <string>
00024 #include <sstream>
00025 
00026 namespace Hypertable {
00032   typedef std::string String;
00033   typedef long unsigned int Lu;         // shortcut for printf format
00034   typedef long long unsigned int Llu;   // ditto
00035   typedef long long int Lld;            // ditto
00036 
00044   String format(const char *fmt, ...) __attribute__((format (printf, 1, 2)));
00045 
00050   String format_number(int64_t n, int sep = ',');
00051 
00056   String
00057   format_bytes(size_t n, const void *buf, size_t len,
00058                const char *trailer = "...");
00059 
00064   template <class SequenceT>
00065   String format_list(const SequenceT &seq, const char *sep = ", ") {
00066     typedef typename SequenceT::const_iterator Iterator;
00067     Iterator it = seq.begin(), end = seq.end();
00068     std::ostringstream out;
00069     out <<'[';
00070 
00071     if (it != end) {
00072       out << *it;
00073       ++it;
00074     }
00075     for (; it != end; ++it)
00076       out << sep << *it;
00077 
00078     out <<']';
00079     return out.str();
00080   }
00081 
00082 } // namespace Hypertable
00083 
00084 #endif // HYPERTABLE_STRING_H