Official C++ port of Sqids. Generate short unique IDs from numbers.
See the codeSqids (pronounced "squids") is a small library that lets you generate YouTube-looking IDs from numbers. It's good for link shortening, fast & URL-safe ID generation and decoding back into numbers for quicker database lookups.
Features:
include directory into your project rootGood for:
Not good for:
Note This step is fully optional. The easiest way to use this library is to merge the
includedirectory into your project root and directly include thesqids.hppheader:
#include "include/sqids/sqids.hpp"
To install the headers on your system using CMake, run:
mkdir -p build
cd build
cmake ..
cmake --build . --config Release --target install
The last command typically needs to run as sudo.
(By default, the headers will be installed to include/sqids/, relative to the CMake install prefix, which is usually /usr/local/ on Linux/Unix.)
In your code, include the library with:
#include <sqids/sqids.hpp>
For CMake-based projects, a minimal CMakeLists.txt configuration may consist of the following:
project("sqids-example")
find_package(sqids CONFIG REQUIRED)
add_executable(sqids-example main.cpp)
target_link_libraries(sqids-example INTERFACE sqids)
cmake -S . -B build
cmake --build build
cd build
ctest -V
sqidscxx::Sqids sqids;
auto id = sqids.encode({ 1, 2, 3 });
sqidscxx::Sqids sqids;
auto numbers = sqids.decode("86Rf07");
for (auto number : numbers) {
std::cout << number << std::endl;
}
sqidscxx::Sqids sqids({ minLength: 10 });
auto id = sqids.encode({ 1, 2, 3 });
std::cout << id << std::endl;
Output is 86Rf07xd4z.
sqidscxx::Sqids sqids({ alphabet: "FxnXM1kBN6cuhsAvjW3Co7l2RePyY8DwaU04Tzt9fHQrqSVKdpimLGIJOgb5ZE" });
auto id = sqids.encode({ 1, 2, 3 });
std::cout << id << std::endl;
Output is B4aajs.
sqidscxx::Sqids sqids({ blocklist: {{ "86Rf07" }} });
auto id = sqids.encode({ 1, 2, 3 });
std::cout << id << std::endl;
Output is se8ojk.
60 followers Β· starred Jan 2024
Official C++ port of Sqids. Generate short unique IDs from numbers.
See the codeSqids (pronounced "squids") is a small library that lets you generate YouTube-looking IDs from numbers. It's good for link shortening, fast & URL-safe ID generation and decoding back into numbers for quicker database lookups.
Features:
include directory into your project rootGood for:
Not good for:
Note This step is fully optional. The easiest way to use this library is to merge the
includedirectory into your project root and directly include thesqids.hppheader:
#include "include/sqids/sqids.hpp"
To install the headers on your system using CMake, run:
mkdir -p build
cd build
cmake ..
cmake --build . --config Release --target install
The last command typically needs to run as sudo.
(By default, the headers will be installed to include/sqids/, relative to the CMake install prefix, which is usually /usr/local/ on Linux/Unix.)
In your code, include the library with:
#include <sqids/sqids.hpp>
For CMake-based projects, a minimal CMakeLists.txt configuration may consist of the following:
project("sqids-example")
find_package(sqids CONFIG REQUIRED)
add_executable(sqids-example main.cpp)
target_link_libraries(sqids-example INTERFACE sqids)
cmake -S . -B build
cmake --build build
cd build
ctest -V
sqidscxx::Sqids sqids;
auto id = sqids.encode({ 1, 2, 3 });
sqidscxx::Sqids sqids;
auto numbers = sqids.decode("86Rf07");
for (auto number : numbers) {
std::cout << number << std::endl;
}
sqidscxx::Sqids sqids({ minLength: 10 });
auto id = sqids.encode({ 1, 2, 3 });
std::cout << id << std::endl;
Output is 86Rf07xd4z.
sqidscxx::Sqids sqids({ alphabet: "FxnXM1kBN6cuhsAvjW3Co7l2RePyY8DwaU04Tzt9fHQrqSVKdpimLGIJOgb5ZE" });
auto id = sqids.encode({ 1, 2, 3 });
std::cout << id << std::endl;
Output is B4aajs.
sqidscxx::Sqids sqids({ blocklist: {{ "86Rf07" }} });
auto id = sqids.encode({ 1, 2, 3 });
std::cout << id << std::endl;
Output is se8ojk.
60 followers Β· starred Jan 2024