aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Uri.cpp76
1 files changed, 58 insertions, 18 deletions
diff --git a/src/Uri.cpp b/src/Uri.cpp
index 7580723..77e561a 100644
--- a/src/Uri.cpp
+++ b/src/Uri.cpp
@@ -521,6 +521,62 @@ namespace Uri {
}
return true;
}
+
+ /**
+ * This method takes the part of a URI string that has just
+ * the query element with its delimiter, and breaks off
+ * and decodes the query.
+ *
+ * @param[in] queryWithDelimiter
+ * This is the part of a URI string that has just
+ * the query element with its delimiter.
+ *
+ * @return
+ * An indication of whether or not the method succeeded
+ * is returned.
+ */
+ bool ParseQuery(const std::string& queryWithDelimiter) {
+ if (queryWithDelimiter.empty()) {
+ query.clear();
+ } else {
+ query = queryWithDelimiter.substr(1);
+ }
+ return DecodeQueryOrFragment(query);
+ }
+
+ /**
+ * This method takes the part of a URI string that has just
+ * the query and/or fragment elements, and breaks off
+ * and decodes the fragment part, returning the rest,
+ * which will be either empty or have the query with the
+ * query delimiter still attached.
+ *
+ * @param[in] queryAndOrFragment
+ * This is the part of a URI string that has just
+ * the query and/or fragment elements.
+ *
+ * @param[out] rest
+ * This is where to store the rest of the input string
+ * after removing any fragment and fragment delimiter.
+ *
+ * @return
+ * An indication of whether or not the method succeeded
+ * is returned.
+ */
+ bool ParseFragment(
+ const std::string& queryAndOrFragment,
+ std::string& rest
+ ) {
+ const auto fragmentDelimiter = queryAndOrFragment.find('#');
+ if (fragmentDelimiter == std::string::npos) {
+ fragment.clear();
+ rest = queryAndOrFragment;
+ } else {
+ fragment = queryAndOrFragment.substr(fragmentDelimiter + 1);
+ rest = queryAndOrFragment.substr(0, fragmentDelimiter);
+ }
+ return DecodeQueryOrFragment(fragment);
+ }
};
Uri::~Uri() = default;
@@ -594,28 +650,12 @@ namespace Uri {
}
// Next, parse the fragment if there is one.
- const auto fragmentDelimiter = queryAndOrFragment.find('#');
- if (fragmentDelimiter == std::string::npos) {
- impl_->fragment.clear();
- rest = queryAndOrFragment;
- } else {
- impl_->fragment = queryAndOrFragment.substr(fragmentDelimiter + 1);
- rest = queryAndOrFragment.substr(0, fragmentDelimiter);
- }
- if (!DecodeQueryOrFragment(impl_->fragment)) {
+ if (!impl_->ParseFragment(queryAndOrFragment, rest)) {
return false;
}
// Finally, if anything is left, it's the query.
- if (rest.empty()) {
- impl_->query.clear();
- } else {
- impl_->query = rest.substr(1);
- }
- if (!DecodeQueryOrFragment(impl_->query)) {
- return false;
- }
- return true;
+ return impl_->ParseQuery(rest);
}
std::string Uri::GetScheme() const {