This isn't necessary, but is nice for readability.
#include <string>
#include <iostream>
+#include <map>
#include "metadata.h"
#include "ref.h"
#include "util.h"
using std::list;
+using std::map;
using std::string;
using std::ostream;
using std::ostringstream;
return pathcmp(slash1 + 1, slash2 + 1);
}
+/* Encode a dictionary of string key/value pairs into a sequence of lines of
+ * the form "key: value". If it exists, the key "name" is treated specially
+ * and will be listed first. */
+static string encode_dict(const map<string, string>& dict)
+{
+ string result;
+
+ if (dict.find("name") != dict.end()) {
+ result += "name: " + dict.at("name") + "\n";
+ }
+
+ for (map<string, string>::const_iterator i = dict.begin();
+ i != dict.end(); ++i) {
+ if (i->first == "name")
+ continue;
+ result += i->first + ": " + i->second + "\n";
+ }
+
+ return result;
+}
+
MetadataWriter::MetadataWriter(TarSegmentStore *store,
const char *path,
const char *snapshot_name,
{
return strtoll(s.c_str(), NULL, 0);
}
-
-/* Encode a dictionary of string key/value pairs into a sequence of lines of
- * the form "key: value". */
-string encode_dict(const map<string, string>& dict)
-{
- string result;
- for (map<string, string>::const_iterator i = dict.begin();
- i != dict.end(); ++i) {
- result += i->first + ": " + i->second + "\n";
- }
- return result;
-}
-
-/* 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, const map<string, string>& dict)
-{
- o << encode_dict(dict);
-}
std::string uri_encode(const std::string &in);
std::string uri_decode(const std::string &in);
std::string encode_int(long long n, int base=10);
-std::string encode_dict(const std::map<std::string, std::string>& dict);
-void dict_output(std::ostream &o,
- const std::map<std::string, std::string>& dict);
long long parse_int(const std::string &s);