X-Git-Url: http://git.vrable.net/?a=blobdiff_plain;f=format.cc;h=08c2f74522c1e60e69b46c7c2437f8dc5c4e90ac;hb=c26f44fe8cd3eeec0d9d849cb2e639d484de5887;hp=e6e11bc346720539d5151d6af60df1bdb314904d;hpb=c5e37e726177856fa06bcc2b4294fc63ae6fa1ef;p=cumulus.git diff --git a/format.cc b/format.cc index e6e11bc..08c2f74 100644 --- a/format.cc +++ b/format.cc @@ -8,9 +8,13 @@ #include #include +#include +#include #include #include +using std::map; +using std::ostream; using std::string; /* Perform URI-style escaping of a string. Bytes which cannot be represented @@ -34,3 +38,21 @@ string uri_encode(const string &in) return out; } + +/* Return the string representation of an integer. */ +string encode_int(long long n) +{ + char buf[64]; + sprintf(buf, "%lld", n); + return buf; +} + +/* Output a dictionary of string key/value pairs to the given output stream. + * The format is a sequence of lines of the form "key: value". */ +void dict_output(ostream &o, map dict) +{ + for (map::const_iterator i = dict.begin(); + i != dict.end(); ++i) { + o << i->first << ": " << i->second << "\n"; + } +}