summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--icespider/common/pathparts.cpp18
-rw-r--r--icespider/common/pathparts.h22
-rw-r--r--icespider/compile/routeCompiler.cpp4
-rw-r--r--icespider/core/irouteHandler.cpp6
-rw-r--r--icespider/core/irouteHandler.h6
5 files changed, 28 insertions, 28 deletions
diff --git a/icespider/common/pathparts.cpp b/icespider/common/pathparts.cpp
index 553e90a..23e6f31 100644
--- a/icespider/common/pathparts.cpp
+++ b/icespider/common/pathparts.cpp
@@ -5,18 +5,18 @@
namespace ba = boost::algorithm;
namespace IceSpider {
- Path::Path(const std::string & p) :
+ Path::Path(const std::string_view & p) :
path(p)
{
auto relp = p.substr(1);
if (relp.empty()) return;
for (auto pi = ba::make_split_iterator(relp, ba::first_finder("/", ba::is_equal())); pi != decltype(pi)(); ++pi) {
- std::string pp(pi->begin(), pi->end());
+ std::string_view pp(pi->begin(), pi->end() - pi->begin());
if (pp.front() == '{' && pp.back() == '}') {
- parts.push_back(std::make_shared<PathParameter>(pp));
+ parts.push_back(std::make_unique<PathParameter>(pp));
}
else {
- parts.push_back(std::make_shared<PathLiteral>(pp));
+ parts.push_back(std::make_unique<PathLiteral>(pp));
}
}
}
@@ -27,24 +27,24 @@ namespace IceSpider {
return parts.size();
}
- PathLiteral::PathLiteral(const std::string & p) :
+ PathLiteral::PathLiteral(const std::string_view & p) :
value(p)
{
}
bool
- PathLiteral::matches(const std::string & v) const
+ PathLiteral::matches(const std::string_view & v) const
{
return value == v;
}
- PathParameter::PathParameter(const std::string & s) :
- name(boost::algorithm::trim_copy_if(s, ispunct))
+ PathParameter::PathParameter(const std::string_view & s) :
+ name(s.substr(1, s.length() - 2))
{
}
bool
- PathParameter::matches(const std::string &) const
+ PathParameter::matches(const std::string_view &) const
{
return true;
}
diff --git a/icespider/common/pathparts.h b/icespider/common/pathparts.h
index e4d97a1..7626873 100644
--- a/icespider/common/pathparts.h
+++ b/icespider/common/pathparts.h
@@ -2,7 +2,7 @@
#define ICESPIDER_CORE_PATHS_H
#include <vector>
-#include <string>
+#include <string_view>
#include <memory>
#include <visibility.h>
@@ -11,35 +11,35 @@ namespace IceSpider {
public:
virtual ~PathPart() = default;
- virtual bool matches(const std::string &) const = 0;
+ virtual bool matches(const std::string_view &) const = 0;
};
- typedef std::shared_ptr<PathPart> PathPartPtr;
+ typedef std::unique_ptr<PathPart> PathPartPtr;
class DLL_PUBLIC PathLiteral : public PathPart {
public:
- PathLiteral(const std::string & v);
+ PathLiteral(const std::string_view & v);
- bool matches(const std::string &) const;
+ bool matches(const std::string_view &) const;
- const std::string value;
+ const std::string_view value;
};
class DLL_PUBLIC PathParameter : public PathPart {
public:
- PathParameter(const std::string &);
+ PathParameter(const std::string_view &);
- bool matches(const std::string &) const;
+ bool matches(const std::string_view &) const;
- const std::string name;
+ const std::string_view name;
};
class DLL_PUBLIC Path {
public:
typedef std::vector<PathPartPtr> PathParts;
- Path(const std::string &);
+ Path(const std::string_view &);
- const std::string path;
+ const std::string_view path;
unsigned int pathElementCount() const;
diff --git a/icespider/compile/routeCompiler.cpp b/icespider/compile/routeCompiler.cpp
index 40ce5fd..6d8f7e1 100644
--- a/icespider/compile/routeCompiler.cpp
+++ b/icespider/compile/routeCompiler.cpp
@@ -137,7 +137,7 @@ namespace IceSpider {
Path path(r.second->path);
d->hasUserSource = std::find_if(path.parts.begin(), path.parts.end(), [d](const auto & pp) {
if (auto par = dynamic_cast<PathParameter *>(pp.get())) {
- return par->name == d->key;
+ return par->name == *d->key;
}
return false;
}) != path.parts.end();
@@ -402,7 +402,7 @@ namespace IceSpider {
unsigned int idx = -1;
for (const auto & pp : path.parts) {
if (auto par = dynamic_cast<PathParameter *>(pp.get())) {
- if (par->name == p.second->key) {
+ if (par->name == *p.second->key) {
idx = &pp - &path.parts.front();
}
}
diff --git a/icespider/core/irouteHandler.cpp b/icespider/core/irouteHandler.cpp
index 7a44fb3..f64658e 100644
--- a/icespider/core/irouteHandler.cpp
+++ b/icespider/core/irouteHandler.cpp
@@ -12,12 +12,12 @@ namespace IceSpider {
const RouteOptions IRouteHandler::defaultRouteOptions {
};
- IRouteHandler::IRouteHandler(HttpMethod m, const std::string & p) :
+ IRouteHandler::IRouteHandler(HttpMethod m, const std::string_view & p) :
IRouteHandler(m, p, defaultRouteOptions)
{
}
- IRouteHandler::IRouteHandler(HttpMethod m, const std::string & p, const RouteOptions & ro) :
+ IRouteHandler::IRouteHandler(HttpMethod m, const std::string_view & p, const RouteOptions & ro) :
Path(p),
method(m)
{
@@ -55,7 +55,7 @@ namespace IceSpider {
}
void
- IRouteHandler::requiredParameterNotFound(const char *, const std::string &) const
+ IRouteHandler::requiredParameterNotFound(const char *, const std::string_view &) const
{
throw Http400_BadRequest();
}
diff --git a/icespider/core/irouteHandler.h b/icespider/core/irouteHandler.h
index 4fbb581..f80c240 100644
--- a/icespider/core/irouteHandler.h
+++ b/icespider/core/irouteHandler.h
@@ -16,8 +16,8 @@ namespace IceSpider {
public:
const static RouteOptions defaultRouteOptions;
- IRouteHandler(HttpMethod, const std::string & path);
- IRouteHandler(HttpMethod, const std::string & path, const RouteOptions &);
+ IRouteHandler(HttpMethod, const std::string_view & path);
+ IRouteHandler(HttpMethod, const std::string_view & path, const RouteOptions &);
virtual ~IRouteHandler();
virtual void execute(IHttpRequest * request) const = 0;
@@ -31,7 +31,7 @@ namespace IceSpider {
typedef std::map<MimeType, StreamSerializerFactoryPtr> RouteSerializers;
RouteSerializers routeSerializers;
- void requiredParameterNotFound(const char *, const std::string & key) const;
+ void requiredParameterNotFound(const char *, const std::string_view & key) const;
template <typename T, typename K>
inline T requiredParameterNotFound(const char * s, const K & key) const