1 /* LBS: An LFS-inspired filesystem backup system
2 * Copyright (C) 2007 Michael Vrable
4 * Utility functions for converting various datatypes to text format (and
5 * later, for parsing them back, perhaps).
20 /* Perform URI-style escaping of a string. Bytes which cannot be represented
21 * directly are encoded in the form %xx (where "xx" is a string of two
22 * hexadecimal digits). */
23 string uri_encode(const string &in)
27 for (size_t i = 0; i < in.length(); i++) {
28 unsigned char c = in[i];
30 if (c > '%' && c <= 0x7f) {
34 sprintf(buf, "%%%02x", c);
42 /* Return the string representation of an integer. */
43 string encode_int(long long n)
46 sprintf(buf, "%lld", n);
50 /* Output a dictionary of string key/value pairs to the given output stream.
51 * The format is a sequence of lines of the form "key: value". */
52 void dict_output(ostream &o, map<string, string> dict)
54 for (map<string, string>::const_iterator i = dict.begin();
55 i != dict.end(); ++i) {
56 o << i->first << ": " << i->second << "\n";