diff options
| author | Carl Hetherington <cth@carlh.net> | 2015-03-24 23:57:22 +0000 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2015-03-24 23:57:22 +0000 |
| commit | a71a3b3d0f8545e44af75ded10dfda4a382158f2 (patch) | |
| tree | efb300dac7006409079d544eecc9dc1e5b792e45 /src/lib/util.cc | |
| parent | 86aaba4f392c35ccf28221049f87b8cdba868777 (diff) | |
Hand-apply e30fd8d; resurrect JSON server code.
Diffstat (limited to 'src/lib/util.cc')
| -rw-r--r-- | src/lib/util.cc | 49 |
1 files changed, 48 insertions, 1 deletions
diff --git a/src/lib/util.cc b/src/lib/util.cc index 6bb16c442..2b5eb69fb 100644 --- a/src/lib/util.cc +++ b/src/lib/util.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2012-2014 Carl Hetherington <cth@carlh.net> + Copyright (C) 2012-2015 Carl Hetherington <cth@carlh.net> This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -70,6 +70,7 @@ using std::endl; using std::vector; using std::min; using std::max; +using std::map; using std::list; using std::multimap; using std::istream; @@ -576,3 +577,49 @@ subtitle_period (AVSubtitle const & sub) return period; } + +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; +} |
