feat add uri
This commit is contained in:
parent
1b3f711b7c
commit
d5bfd91089
@ -68,7 +68,9 @@ target_sources(
|
||||
src/sigslot.cc
|
||||
src/status.cc
|
||||
src/system_time.cc
|
||||
src/time_utils.cc)
|
||||
src/time_utils.cc
|
||||
src/uri.cc
|
||||
)
|
||||
# set(BUILD_RTTR_DYNAMIC OFF) set(BUILD_UNIT_TESTS OFF)
|
||||
# set(BUILD_WITH_STATIC_RUNTIME_LIBS ON) set(BUILD_WITH_DOCUMENTATION OFF)
|
||||
# add_subdirectory(3party/rttr EXCLUDE_FROM_ALL)
|
||||
@ -109,6 +111,7 @@ if(SLED_BUILD_TESTS)
|
||||
src/system/fiber/fiber_test.cc
|
||||
src/system/thread_pool_test.cc
|
||||
src/rx_test.cc
|
||||
src/uri_test.cc
|
||||
)
|
||||
target_link_libraries(sled_tests PRIVATE sled GTest::gtest GTest::gtest_main)
|
||||
add_test(NAME sled_tests COMMAND sled_tests)
|
||||
|
55
include/sled/uri.h
Normal file
55
include/sled/uri.h
Normal file
@ -0,0 +1,55 @@
|
||||
#pragma once
|
||||
#include <map>
|
||||
#ifndef SLED_URI_H
|
||||
#define SLED_URI_H
|
||||
#include <string>
|
||||
|
||||
namespace sled {
|
||||
namespace internal {
|
||||
#define __SLED_URI_GETTER_AND_SETTER(type, name) \
|
||||
type &name() & { return name##_; } \
|
||||
type &&name() && { return std::move(name##_); } \
|
||||
type const &name() const & { return name##_; } \
|
||||
void set_##name(type const &v) { name##_ = v; } \
|
||||
void set_##name(type &&v) { name##_ = std::move(v); }
|
||||
|
||||
}// namespace internal
|
||||
|
||||
class URI {
|
||||
public:
|
||||
// using ParamType = std::pair<std::string, std::string>;
|
||||
using ParamMap = std::map<std::string, std::string>;
|
||||
// http://xxx.com/index.html?field=value
|
||||
static URI ParseAbsoluteURI(const std::string &uri);
|
||||
// http://xxx.com/index.html?field=value#download
|
||||
static URI ParseURI(const std::string &uri);
|
||||
// http://xxx.com/index.html
|
||||
static URI ParseURIReference(const std::string &uri);
|
||||
|
||||
// setter getter
|
||||
__SLED_URI_GETTER_AND_SETTER(std::string, scheme)
|
||||
__SLED_URI_GETTER_AND_SETTER(std::string, username)
|
||||
__SLED_URI_GETTER_AND_SETTER(std::string, password)
|
||||
__SLED_URI_GETTER_AND_SETTER(std::string, host)
|
||||
__SLED_URI_GETTER_AND_SETTER(std::string, port)
|
||||
__SLED_URI_GETTER_AND_SETTER(std::string, path)
|
||||
__SLED_URI_GETTER_AND_SETTER(std::string, file_name)
|
||||
__SLED_URI_GETTER_AND_SETTER(std::string, file_extension)
|
||||
__SLED_URI_GETTER_AND_SETTER(ParamMap, query)
|
||||
__SLED_URI_GETTER_AND_SETTER(std::string, anchor)
|
||||
|
||||
private:
|
||||
std::string scheme_;
|
||||
std::string username_;
|
||||
std::string password_;
|
||||
std::string host_;
|
||||
std::string port_;
|
||||
std::string path_;
|
||||
std::string file_name_;
|
||||
std::string file_extension_;
|
||||
ParamMap query_;
|
||||
std::string anchor_;
|
||||
};
|
||||
}// namespace sled
|
||||
|
||||
#endif// SLED_URI_H
|
16
src/uri.cc
Normal file
16
src/uri.cc
Normal file
@ -0,0 +1,16 @@
|
||||
#include "sled/uri.h"
|
||||
#include "sled/strings/utils.h"
|
||||
|
||||
namespace sled {
|
||||
URI
|
||||
URI::ParseURI(const std::string &uri_str)
|
||||
{
|
||||
if (uri_str.empty()) { return {}; }
|
||||
URI uri;
|
||||
// TODO: decode before
|
||||
auto start_pos = uri_str.find_first_not_of(" ");
|
||||
auto end_pos = uri_str.find(':');
|
||||
|
||||
return std::move(uri);
|
||||
}
|
||||
}// namespace sled
|
2
src/uri_test.cc
Normal file
2
src/uri_test.cc
Normal file
@ -0,0 +1,2 @@
|
||||
#include <gtest/gtest.h>
|
||||
#include <sled/uri.h>
|
Loading…
x
Reference in New Issue
Block a user