Skip to content

Commit

Permalink
Make it easier to produce a manifold URI from a ManifoldPath FileSpec
Browse files Browse the repository at this point in the history
Summary: FileSpec can't always be expressed as URI, but manifold paths typically should. This diff makes it easier to generate a manifold URI.

Reviewed By: hanghu

Differential Revision: D58962253

fbshipit-source-id: 7ff73215f4605856ea8668ecdb938685d0898979
  • Loading branch information
Georges Berenger authored and facebook-github-bot committed Jun 24, 2024
1 parent 3311de6 commit 84ef957
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 15 deletions.
13 changes: 13 additions & 0 deletions vrs/FileSpec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

#include "FileHandler.h"

#include <cctype>
#include <cstring>

#include <tuple>
Expand Down Expand Up @@ -453,4 +454,16 @@ int FileSpec::urldecode(const string& in, string& out) {
return 0;
}

void FileSpec::setExtra(const string& name, const string& value) {
extras[name] = value;
}

void FileSpec::setExtra(const string& name, const char* value) {
extras[name] = value;
}

void FileSpec::setExtra(const string& name, bool value) {
extras[name] = value ? "1" : "0";
}

} // namespace vrs
21 changes: 6 additions & 15 deletions vrs/FileSpec.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,13 @@ struct FileSpec {
static int decodeQuery(const string& query, string& outKey, string& outValue);
static int urldecode(const string& in, string& out);

void setExtra(const string& name, const string& value);
void setExtra(const string& name, const char* value);
void setExtra(const string& name, bool value);
template <typename T>
void setExtra(const string& name, const T& value);
void setExtra(const string& name, T value) {
extras[name] = std::to_string(value);
}

/// Unset an extra parameter
void unsetExtra(const string& name);
Expand All @@ -137,18 +142,4 @@ struct FileSpec {
map<string, string> extras;
};

template <>
inline void FileSpec::setExtra(const string& name, const string& value) {
extras[name] = value;
}

template <>
inline void FileSpec::setExtra(const string& name, const bool& value) {
extras[name] = value ? "1" : "0";
}

template <typename T>
inline void FileSpec::setExtra(const string& name, const T& value) {
extras[name] = std::to_string(value);
}
} // namespace vrs

0 comments on commit 84ef957

Please sign in to comment.