aboutsummaryrefslogtreecommitdiff
path: root/src/Uri.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/Uri.cpp')
-rw-r--r--src/Uri.cpp64
1 files changed, 43 insertions, 21 deletions
diff --git a/src/Uri.cpp b/src/Uri.cpp
index b0165de..1768849 100644
--- a/src/Uri.cpp
+++ b/src/Uri.cpp
@@ -58,6 +58,8 @@ namespace Uri {
* This contains the private properties of a Uri instance.
*/
struct Uri::Impl {
+ // Properties
+
/**
* This is the "scheme" element of the URI.
*/
@@ -101,6 +103,45 @@ namespace Uri {
* if it has one.
*/
std::string fragment;
+
+ // Methods
+
+ /**
+ * This method builds the internal path element sequence
+ * by parsing it from the given path string.
+ *
+ * @param[in] pathString
+ * This is the string containing the whole path of the URI.
+ *
+ * @return
+ * An indication if the path was parsed correctly or not
+ * is returned.
+ */
+ bool ParsePath(std::string pathString) {
+ path.clear();
+ if (pathString == "/") {
+ // Special case of a path that is empty but needs a single
+ // empty-string element to indicate that it is absolute.
+ path.push_back("");
+ pathString.clear();
+ } else if (!pathString.empty()) {
+ for(;;) {
+ auto pathDelimiter = pathString.find('/');
+ if (pathDelimiter == std::string::npos) {
+ path.push_back(pathString);
+ pathString.clear();
+ break;
+ } else {
+ path.emplace_back(
+ pathString.begin(),
+ pathString.begin() + pathDelimiter
+ );
+ pathString = pathString.substr(pathDelimiter + 1);
+ }
+ }
+ }
+ return true;
+ }
};
Uri::~Uri() = default;
@@ -171,27 +212,8 @@ namespace Uri {
}
// Next, parse the path.
- impl_->path.clear();
- if (pathString == "/") {
- // Special case of a path that is empty but needs a single
- // empty-string element to indicate that it is absolute.
- impl_->path.push_back("");
- pathString.clear();
- } else if (!pathString.empty()) {
- for(;;) {
- auto pathDelimiter = pathString.find('/');
- if (pathDelimiter == std::string::npos) {
- impl_->path.push_back(pathString);
- pathString.clear();
- break;
- } else {
- impl_->path.emplace_back(
- pathString.begin(),
- pathString.begin() + pathDelimiter
- );
- pathString = pathString.substr(pathDelimiter + 1);
- }
- }
+ if (!impl_->ParsePath(pathString)) {
+ return false;
}
// Next, parse the fragment if there is one.