A lightweight, header-only C++ library for generating sample Lorem Ipsum text. Useful for prototyping apps, UI testing, and anywhere placeholder text is needed.
- Header-only (just
lipsum.hppandlipsum.inlrequired) - Customizable number of paragraphs, sentences, sentence fragments, and words
- C++ and C API (static/shared library and wrapper builds supported)
- CMake support for easy integration
- Example code and live demo available
lipsum-cpp has been mainly tested on Linux and WebAssembly as well as cross-compiled to Windows, although it could likely run on other operating systems as well.
- A C/C++ compiler
- Optionally CMake, a build system (e.g. Make, Ninja, Visual Studio, ...), Doxygen, Python, and Git
#Required
sudo apt update
sudo apt install build-essential
#Recommended
sudo apt install cmake
#Optional
sudo apt install ninja-build python3 doxygen gitSimply copy lipsum.hpp and lipsum.inl into your source tree.
Not recommended.
mkdir -p obj
mkdir -p bin
g++ -c src/lipsum.cpp -DLIPSUM_BUILD_STATIC -o obj/lipsum.o
g++ -c src/lipsum_h.cpp -DLIPSUM_BUILD_STATIC -o obj/lipsum_h.o
ar rcs bin/liblipsum-cpp.a obj/lipsum_h.o obj/lipsum.o
# build example
gcc examples/CWrapper.c -Isrc -Lbin -llipsum-cpp -DLIPSUM_BUILD_STATIC -o bin/CWrapper
-
Clone or add this repo as a submodule:
git submodule add https://github.com/LambBread/lipsum-cpp.git
-
Add to your CMake project:
add_subdirectory(lipsum-cpp) target_link_libraries(your_target lipsum-cpp)
-
To build as a static library (optional):
SetLPSM_BUILD_STATIC=ONin your CMake options. -
To build as a shared library (optional): Set
LPSM_BUILD_SHARED=ONin your CMake options. -
For C wrapper builds, set either
LPSM_BUILD_STATICorLPSM_BUILD_SHARED, andLPSM_BUILD_CWRAPPERall toON.
#ifndef LIPSUM_BUILD_STATIC
#define LIPSUM_IMPLEMENTATION //only for header-only usage
#endif
#include "lipsum.hpp"
#include <iostream>
int main()
{
// Create a generator with random seed.
lpsm::Generator generator;
// Generate 3 paragraphs.
std::cout << generator.paragraph(3, true);
// Generate 6 sentences.
std::cout << generator.sentence(6, true) << '\n';
// Generate a sentence fragment.
std::cout << generator.sentence_fragment() << '\n';
// Generate a word.
std::cout << generator.word() << '\n';
return 0;
}
#ifndef LIPSUM_BUILD_STATIC
#define LIPSUM_IMPLEMENTATION //only for header-only usage
#endif
#include "lipsum.hpp"
#include <iostream>
int main()
{
//generate 5 paragraphs
//of 5-8 sentences
//of 1-3 sentence fragments
//of 4-9 words,
//starting with "Lorem ipsum..." and random seed (default)
std::cout << lpsm::GenerateParagraphs();
//generate 10 paragraphs
//of 7-10 sentences
//of 3-6 sentence fragments
//of 6-9 words,
//not starting with "Lorem ipsum...", and seed 69
std::cout << lpsm::GenerateParagraphs(
10,
lpsm::ArgVec2(6, 9),
lpsm::ArgVec2(3, 6),
lpsm::ArgVec2(7, 10),
false, 69
);
return 0;
}The documentation is available here
For C projects, use the C wrapper (lipsum.h) and call functions with the lpsm_ prefix. See the examples/README.md for details.
Utility scripts (see scripts/):
split.py: Converts the samplelipsum.txtinto a vector forlipsum.inl.lipsum.txt: Source text for Lorem Ipsum sample generation.
lipsum-cpp is under the BSD Zero-Clause License, a very permissive public-domain equivalent license. See LICENSE.md for details.
Created by LambBread