X-Git-Url: http://git.vrable.net/?a=blobdiff_plain;f=format.cc;h=19cf28f687b69ab8352530d6f19cac5c5128705c;hb=58a0d3f8749111c15e9afa9d929016d65ed32250;hp=e6e11bc346720539d5151d6af60df1bdb314904d;hpb=c5e37e726177856fa06bcc2b4294fc63ae6fa1ef;p=cumulus.git diff --git a/format.cc b/format.cc index e6e11bc..19cf28f 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 @@ -23,7 +27,7 @@ string uri_encode(const string &in) for (size_t i = 0; i < in.length(); i++) { unsigned char c = in[i]; - if (c > '%' && c <= 0x7f) { + if (c >= '+' && c < 0x7f) { out += c; } else { char buf[4]; @@ -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"; + } +}