- Notifications
You must be signed in to change notification settings - Fork23
A C++ library that implements the WhatWG URL specification
License
cpp-netlib/url
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
I've changed the name of the default branch frommaster tomain. Please make futurePRs to themain branch on thecpp-netlib repo.
This library provides:
- A
skyr::urlclass that implements a generic URL parser,conforming with theWhatWG URL specification - URL serialization and comparison
- Percent encoding and decoding functions
- IDNA and Punycode functions for domain name parsing
- Basic Unicode conversion functions
This project requires the availability of a C++17 compliant compilerand standard library.
skyr::url is available onvcpkg.It can be installed by executing the following steps:
>cd${VCPKG_ROOT}> git init> git remote add origin https://github.com/Microsoft/vcpkg.git> git fetch origin master> git checkout -b master origin/master> ./bootstrap-vcpkg.sh> ./vcpkg install skyr-url
On Windows - for example, using Powershell - replace thecall tobootstrap-vcpkg.sh withbootstrap-vcpkg.bat.
Usingvcpkg, install the library dependencies:
>cd${VCPKG_ROOT}> git init> git remote add origin https://github.com/Microsoft/vcpkg.git> git fetch origin master> git checkout -b master origin/master> ./bootstrap-vcpkg.sh> ./vcpkg install tl-expected range-v3 catch2 nlohmann-json fmt
From a terminal, execute the following sequence of commands:
> mkdir _build> cmake \ -B _build \ -G"Ninja" \ -DCMAKE_TOOLCHAIN_FILE=${VCPKG_ROOT}/vcpkg/scripts/buildsystems/vcpkg.cmake \.> cmake --build _build
To run the tests:
> cmake --build _build --targettest
On Windows, replace the target withRUN_TESTS:
> cmake--build _build--target RUN_TESTS
To install the library:
> cmake --build _build --target install> cmake .. \ -G"Ninja" \ -DCMAKE_TOOLCHAIN_FILE=${VCPKG_ROOT}/vcpkg/scripts/buildsystems/vcpkg.cmake \ -DCMAKE_INSTALL_PREFIX=$PREFIX> ninja> ninjatest> ninja install
Where$PREFIX is the location where you want to install thelibrary. Depending on the location of$PREFIX, you may need to runthe install command as an administrator (e.g. on Linux assudo).
Here is an example of how to use theskyr::url class to parse aURL string and to process the components:
// url_parts.cpp#include<skyr/url.hpp>#include<skyr/percent_encoding/percent_decode.hpp>#include<iostream>intmain() {usingnamespaceskyr::literals;auto url ="http://sub.example.إختبار:8090/\xcf\x80?a=1&c=2&b=\xe2\x80\x8d\xf0\x9f\x8c\x88"_url; std::cout <<"Protocol:" << url.protocol() << std::endl; std::cout <<"Domain?" << std::boolalpha << url.is_domain() << std::endl; std::cout <<"Domain:" << url.hostname() << std::endl; std::cout <<"Domain:" << url.u8domain().value() << std::endl; std::cout <<"Port:" << url.port<std::uint16_t>().value() << std::endl; std::cout <<"Pathname:" <<skyr::percent_decode(url.pathname()).value() << std::endl; std::cout <<"Search parameters:" << std::endl;constauto &search = url.search_parameters();for (constauto &[key, value] : search) { std::cout <<"" <<"key:" << key <<", value =" << value << std::endl; }}
Here is theCMake script to build the example:
# CMakeLists.txtcmake_minimum_required(VERSION 3.16)project(my_project)find_package(tl-expected CONFIG REQUIRED)find_package(range-v3 CONFIG REQUIRED)find_package(skyr-url CONFIG REQUIRED)set(CMAKE_CXX_STANDARD 17)add_executable(url_parts url_parts.cpp)target_link_libraries(url_partsPRIVATE skyr::skyr-url)
The output of this program is:
Protocol: http:Domain?trueDomain: sub.example.xn--kgbechtvDomain: sub.example.إختبارPort: 8090Pathname: /πSearch parameters: key: a, value = 1 key: c, value = 2 key: b, value = 🌈
This library usesexpectedandRange v3.
The tests useCatch2,nlohmann-json andfmtlib.
This library includes a modified implementation ofutfcpp.
Look at theGitHub Actions Statusfor all of the configurations for which this library is tested.
This library is released under the Boost Software License (please seehttp://boost.org/LICENSE_1_0.txt or the accompanyingLICENSE_1_0.txtfile for the full text).
This name was chosen by a random project name generator, whichitself was randomly chosen.
Any questions about this library can be addressed to the cpp-netlibdevelopers mailing list. Issues canbe filed on ourGitHub page.
You can also contact me via Twitter@glynos.
About
A C++ library that implements the WhatWG URL specification
Topics
Resources
License
Code of conduct
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Uh oh!
There was an error while loading.Please reload this page.
Languages
- C++96.3%
- CMake3.0%
- Python0.7%