diff options
| author | Carl Hetherington <cth@carlh.net> | 2014-02-19 10:47:11 +0000 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2014-02-19 10:47:11 +0000 |
| commit | b5b20f829ed95febe7aba55ebe3679c998b35b5e (patch) | |
| tree | fa4013a9646aee272ac8e7474275e2ad07cfec3e /src/lib/util.cc | |
| parent | 6a15d65585af0e19b72200d1fd67e256cd1a7c6c (diff) | |
Add some basic JSON stuff.
Diffstat (limited to 'src/lib/util.cc')
| -rw-r--r-- | src/lib/util.cc | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/src/lib/util.cc b/src/lib/util.cc index b2f8c4470..a86033e57 100644 --- a/src/lib/util.cc +++ b/src/lib/util.cc @@ -89,6 +89,7 @@ using std::min; using std::max; using std::list; using std::multimap; +using std::map; using std::istream; using std::numeric_limits; using std::pair; @@ -939,6 +940,52 @@ make_signer () return shared_ptr<const libdcp::Signer> (new libdcp::Signer (chain, signer_key)); } +map<string, string> +split_get_request (string url) +{ + enum { + AWAITING_QUESTION_MARK, + KEY, + VALUE + } state = AWAITING_QUESTION_MARK; + + map<string, string> r; + string k; + string v; + for (size_t i = 0; i < url.length(); ++i) { + switch (state) { + case AWAITING_QUESTION_MARK: + if (url[i] == '?') { + state = KEY; + } + break; + case KEY: + if (url[i] == '=') { + v.clear (); + state = VALUE; + } else { + k += url[i]; + } + break; + case VALUE: + if (url[i] == '&') { + r.insert (make_pair (k, v)); + k.clear (); + state = KEY; + } else { + v += url[i]; + } + break; + } + } + + if (state == VALUE) { + r.insert (make_pair (k, v)); + } + + return r; +} + libdcp::Size fit_ratio_within (float ratio, libdcp::Size full_frame) { @@ -959,3 +1006,10 @@ wrapped_av_malloc (size_t s) return p; } +string +entities_to_text (string e) +{ + boost::algorithm::replace_all (e, "%3A", ":"); + boost::algorithm::replace_all (e, "%2F", "/"); + return e; +} |
