Cppsimpleuri
A modern C++ uri & query parser
Install / Use
/learn @salzaverde/CppsimpleuriREADME
cppsimpleuri
A modern C++ uri & query parser.
Status
Features
- According to RFC3986
- Includes Query Parser & Builder
- Includes percent-encoding & -decoding
- Easy to use & understand
- Comprehensively tested
Requirements
- CMake
- C++14
Integration
Include cppsimpleuri in your cmake project using fetchContent:
# CMakeLists.txt
add_executable(my_target_name ...)
include(FetchContent)
FetchContent_Declare(
cppsimpleuri
GIT_REPOSITORY https://github.com/salzaverde/cppsimpleuri.git
GIT_TAG v2.2.1
)
FetchContent_MakeAvailable(cppsimpleuri)
target_link_libraries(my_target_name PRIVATE
cppsimpleuri
)
Examples
URI Parsing
#include <salzaverde/uri.h>
using namespace salzaverde;
auto myRawUri = std::string("https://salzaverde@github.io:1176/my/music?sort_by=title&before=2020#artist=rhcp");
auto uri = URI::parse(myRawUri);
std::cout << "Scheme: " << uri.scheme << std::endl;
std::cout << "Userinfo: " << uri.userinfo << std::endl;
std::cout << "Host: " << uri.host << std::endl;
std::cout << "Port: " << uri.port << std::endl;
std::cout << "Path: " << uri.path << std::endl;
std::cout << "Query: " << uri.query << std::endl;
std::cout << "Fragment: " << uri.fragment << std::endl;
uri.dump(); //Outputs the raw uri
Query Parsing
#include <salzaverde/query.h>
using namespace salzaverde;
auto raw = "sort_by=title&before=2020"
auto query = Query::parse(raw);
query["sort_by"] == "title"; //true
Query Info
auto keys = query.list(); //Contains "sort_by", "before"
query.contains("sort_by"); //true
Query Editing
query["sort_by"] = "length";
query.dump(); //Query is now: "sort_by=length&before=2020"
query.erase("sort_by");
query.dump(); //Query is now: "before=2020"
Query Construction
#include <salzaverde/query.h>
using namespace salzaverde;
std::vector<std::pair<Query::Key, Query::Value>> parameters;
parameters.push_back({"artistfilter", "rhcp"});
parameters.push_back({"sortby", "name"});
auto query1 = Query(parameters);
auto query2 = Query({
{"artistfilter", "rhcp"},
{"sortby", "name"}
});
Related Skills
node-connect
340.5kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
84.2kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
340.5kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
commit-push-pr
84.2kCommit, push, and open a PR
