|
lipsum-cpp 0.5.4
A basic library written in C++ for generating placeholder Lorem Ipsum text.
|
Main class of lipsum-cpp. More...
#include <generator.hpp>
Public Member Functions | |
| Generator () | |
| Default constructor for Generator. | |
| Generator (int seed) | |
| Constructor for Generator. | |
| Generator (const std::string &path, int seed) | |
| Constructor for Generator. | |
| ~Generator () | |
| Generator (const std::string &path) | |
| Constructor for Generator. | |
| void | load_source (const std::string &path) |
| Reload a source. | |
| void | load_seed (int seed) |
| Reload a seed. | |
| void | change_setting (const std::string &setting, const ArgVec2 &value) |
| Change a setting. | |
| void | change_setting (const std::string &setting, int minValue, int maxValue) |
| Change a setting. | |
| void | toggle_lazy () |
| Toggle the lazy flag. | |
| std::string | word (int num=1) |
| Generate words. | |
| std::string | fragment () |
| Generate a sentence fragment. | |
| std::string | sentence (int num=1, bool useLipsum=true) |
| Generate sentences. | |
| std::string | paragraph (int num=1, bool useLipsum=true) |
| Generate paragraphs. | |
| std::string | text (bool useLipsum=true) |
| Generate a random number of random paragraphs. | |
| std::string | scramble (int length=16, char minChar=' ', char maxChar='~') |
| Generate a random character scramble. | |
| std::string | url () |
| Generate a URL. | |
| std::string | plain_url () |
| Generate a plain URL. | |
| std::string | email () |
| Generate an email. | |
| std::string | slug (char separator='-') |
| Generate a slug. | |
| std::string | case_slug (CaseSlugCase case_=CaseSlugCase::CamelCase) |
| Generate a case slug. | |
| std::string | code (CodeLanguage lang=CodeLanguage::Cpp) |
| Generate a code block. | |
| std::string | ip_addr (bool useIpv6=false, bool usePort=false) |
| Generate an IP address. | |
| std::string | phone_number () |
| Generate a phone number. | |
| std::string | fmt_paragraph (int num=1, bool useLipsum=true, bool useHtml=false) |
| Generate Markdown or HTML paragraphs. | |
| std::string | fmt_text (int numElements=15, bool useHtml=false) |
| Generate a Markdown or HTML document. | |
| std::string | fmt_header (int level=1, bool useHtml=false) |
| Generate a Markdown or HTML header. | |
| std::string | fmt_emphasis (bool isBold=true, bool useHtml=false) |
| Generate an emphasized Markdown or HTML sentence. | |
| std::string | fmt_link (bool useHtml=false) |
| Generate a Markdown or HTML link. | |
| std::string | fmt_list (bool ordered=false, bool useHtml=false) |
| Generate a Markdown or HTML list. | |
| std::string | xml (int choices=30) |
| Generate an XML document. | |
| std::string | json (int maxDepth=3, bool isObject=true) |
| Generate a JSON object or array. | |
| std::string | json_value (int maxDepth=3) |
| Generate a JSON value. | |
| std::string | csv () |
| Generate a CSV document. | |
Private Member Functions | |
| std::string | single_sentence (const ArgVec2 &wordArg, const ArgVec2 &frag) |
| Generate a single sentence. | |
| std::string | single_paragraph (bool useLipsum) |
| Generate a single paragraph. | |
| std::string | single_fmt_paragraph (bool useLipsum, bool useHtml) |
| Generate a single Markdown or HTML paragraph. | |
| std::string | json_string () |
| Generate a random JSON string. | |
| std::string | json_number () |
| Generate a random JSON number. | |
| template<internal::UniformDistributionType T> | |
| T | random_number (T min, T max) |
| Generate a random number. | |
| char | random_number (char min, char max) |
| Overload of random_number() for char. | |
| bool | random_number (bool min, bool max) |
| Overload of random_number() for bool. | |
| int | weighted_random_idx (const std::vector< int > &weights) |
| Choose a random index based off weights. | |
| std::string | tld () |
| Pick a random TLD. | |
Private Attributes | |
| GeneratorSettings | m_Settings |
| Settings for generation. | |
| std::mt19937 | m_Gen |
| Random number generator. | |
| Source | m_Source |
| Source used for generation. | |
Main class of lipsum-cpp.
This is the main class for generation using lipsum-cpp.
| lipsum::Generator::Generator | ( | ) |
Default constructor for Generator.
Load the default lorem ipsum source and choose a random seed.
| lipsum::Generator::Generator | ( | int | seed | ) |
Constructor for Generator.
Load the default lorem ipsum source and the specified seed.
| seed | The seed specified. |
| lipsum::Generator::Generator | ( | const std::string & | path, |
| int | seed ) |
Constructor for Generator.
Load the specified lorem ipsum source and the specified seed.
| path | The filepath or name of the lorem ipsum source. |
| seed | The seed specified. |
| lipsum::Generator::~Generator | ( | ) |
| lipsum::Generator::Generator | ( | const std::string & | path | ) |
Constructor for Generator.
Load the specified lorem ipsum source into m_Source. If path is invalid, it will print a warning and default to the standard lorem-ipsum source.
| path | The filepath or name of the lorem ipsum source. |
| std::string lipsum::Generator::case_slug | ( | CaseSlugCase | case_ = CaseSlugCase::CamelCase | ) |
Generate a case slug.
Generate a case slug in the specified case, e.g. camel case, snake case, etc.
| case_ | The case. By default camel case. |
| void lipsum::Generator::change_setting | ( | const std::string & | setting, |
| const ArgVec2 & | value ) |
Change a setting.
Change a setting for generation. Valid setting names include "word", "frag", "sent", "para", "point", "wordFmt", "fragFmt", "wordURL", "level", and "jsonLength". If an invalid setting name is used, raise a warning and ignore.
| setting | The name of the setting. |
| value | The new value for the setting. |
| void lipsum::Generator::change_setting | ( | const std::string & | setting, |
| int | minValue, | ||
| int | maxValue ) |
Change a setting.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
| setting | The name of the setting. |
| minValue | The new minimum value of the setting. |
| maxValue | The new maximum value of the setting. |
| std::string lipsum::Generator::code | ( | CodeLanguage | lang = CodeLanguage::Cpp | ) |
Generate a code block.
Generate a pseudo main function in the specified programming language.
| lang | The language chosen. By default C++. |
| std::string lipsum::Generator::csv | ( | ) |
Generate a CSV document.
Generate a CSV document. It does this by choosing a random number of rows and columns, and selecting the types of each column out of the following: integers, floating point values, sentences, words, emails, and scrambles. It sets up the top row, and then for every row, fill each column.
| std::string lipsum::Generator::email | ( | ) |
Generate an email.
Generate two words separated by a period, with an at-sign and a plain url.
| std::string lipsum::Generator::fmt_emphasis | ( | bool | isBold = true, |
| bool | useHtml = false ) |
Generate an emphasized Markdown or HTML sentence.
Generate a bold or italic sentence in Markdown or HTML format that is either bold or italic. If isBold is true, make the sentence bold; else italic. If useHtml is true, use HTML bold or italic tags. If useHtml is false, use Markdown bold or italic specifiers. Formerly known as md_emphasis(). If doing a minimum build, return an empty string.
| isBold | Whether the sentence is bold or italic. By default true. (bold) |
| useHtml | Whether HTML should be outputted instead of Markdown. By default false. |
| std::string lipsum::Generator::fmt_header | ( | int | level = 1, |
| bool | useHtml = false ) |
Generate a Markdown or HTML header.
Generate a header in Markdown or HTML format. If level is less than 1 or greater than 6, print a warning to the console. If useHtml is true, start an HTML heading tag at the specified level. If useHtml is false, start a Markdown heading at the specified level. Append a sentence fragment with the first letter capitalized, close the HTML tag and append two newlines. Formerly known as md_header(). If doing a minimum build, return an empty string.
| level | The level of the heading. By default 1. |
| useHtml | Whether HTML should be outputted instead of Markdown. By default false. |
| std::string lipsum::Generator::fmt_link | ( | bool | useHtml = false | ) |
Generate a Markdown or HTML link.
Generate a link in Markdown or HTML format. Generate a random sentence and random URL; if useHtml is false, return an opening square bracket, the sentence, a closing square bracket and opening parenthesis, the URL, and a closing parenthesis to form a Markdown URL. If useHtml is true, return an HTML <a> tag linking to the url with the sentence. Formerly known as md_link(). If doing a minimum build, return an empty string.
| useHtml | Whether HTML should be outputted instead of Markdown. By default false. |
| std::string lipsum::Generator::fmt_list | ( | bool | ordered = false, |
| bool | useHtml = false ) |
Generate a Markdown or HTML list.
Generate an ordered or unordered list in Markdown or HTML format. It does this by picking a random number of points, and if useHtml is true, start an HTML list tag. Repeat the number of points: if useHtml is false and ordered is true, append the current index and a period; if useHtml is false and ordered is false, append a hyphen and a space. If useHtml is true, start an <li> HTML tag. Append a random sentence, and append a newline or close the HTML tag. End the loop, and close the HTML list tag. Formerly known as md_list(). If doing a minimum build, return an empty string.
| ordered | Whether the list is ordered. By default false. |
| useHtml | Whether HTML should be outputted instead of Markdown. By default false. |
| std::string lipsum::Generator::fmt_paragraph | ( | int | num = 1, |
| bool | useLipsum = true, | ||
| bool | useHtml = false ) |
Generate Markdown or HTML paragraphs.
Generate multiple paragraphs in Markdown or HTML format. Formerly known as md_paragraph(). If num is negative, print a warning to the console. If doing a minimum build, return an empty string.
| num | The number of paragraphs. By default 1. |
| useLipsum | Whether "Lorem ipsum..." should start the paragraph. By default true. |
| useHtml | Whether HTML should be outputted instead of Markdown. By default false. |
| std::string lipsum::Generator::fmt_text | ( | int | numElements = 15, |
| bool | useHtml = false ) |
Generate a Markdown or HTML document.
Generate a document in Markdown or HTML format. Formerly known as md_text(). If numElements is negative, print a warning to the console. If numElements is greater than or equal to 1, add a heading. If numElements is greater than or equal to 2, add a formatted paragraph. For every numElements beyond 2, pick a random number from 0 to 2. If it is equal to 1 and the last roll resulted in 1, or there is only 3 total elements, set it to 0. This is meant to stop headings after each other and headings at the end of a document. Choose if a list will be ordered, and if the random number is equal to 0, add a formatted paragraph. If the random number is equal to 1, add a heading. If it is equal to 2, add a list. If doing a minimum build, return an empty string.
| numElements | The number of elements (paragraph, list, heading) in the document. By default 15. |
| useHtml | Whether HTML should be outputted instead of Markdown. By default false. |
| std::string lipsum::Generator::fragment | ( | ) |
Generate a sentence fragment.
Generate a sentence fragment by choosing a random number of words and calling word(). Formerly known as sentence_fragment().
| std::string lipsum::Generator::ip_addr | ( | bool | useIpv6 = false, |
| bool | usePort = false ) |
Generate an IP address.
Generate an IPv4 or IPv6 IP address, optionally with a port. Start by choosing a port. If useIpv6 is false, generate 4 numbers from 0-255 and fill them into the format x.x.x.x, or x.x.x.x:port. If useIpv6 is true, generate 8 hexadecimal numbers from 0-65536 and fill them into the format x:x:x:x:x:x:x:x, or
| useIpv6 | Whether to use IPv6. By default false (IPv4). |
| usePort | Whether to add a port. By default false. |
| std::string lipsum::Generator::json | ( | int | maxDepth = 3, |
| bool | isObject = true ) |
Generate a JSON object or array.
Generate an object or array in JSON format. If doing a minimum build, return an empty string.
| maxDepth | The maximum level of recursion. By default 3. |
| isObject | Whether to output an object (true) or an array (false). By default true. |
|
private |
Generate a random JSON number.
Generate a random number from -1000 to 1000, converted to a string. This function is private. If doing a minimum build, return an empty string.
|
private |
Generate a random JSON string.
Generate a random word, surrounded by quotes. This function is private. If doing a minimum build, return an empty string.
| std::string lipsum::Generator::json_value | ( | int | maxDepth = 3 | ) |
Generate a JSON value.
Generate an object, array, number, string, boolean, or null in JSON format. If maxDepth is greater than or equal to 50, print a warning. If doing a minimum build, return an empty string.
| maxDepth | The maximum level of recursion. By default 3. |
| void lipsum::Generator::load_seed | ( | int | seed | ) |
Reload a seed.
Reload the seed of m_Gen.
| seed | The seed specified. |
| void lipsum::Generator::load_source | ( | const std::string & | path | ) |
Reload a source.
Reload the specified lorem ipsum source into m_Source. If path is invalid, it will print a warning and default to the standard lorem-ipsum source.
| path | The filepath or name of the lorem ipsum source. |
| std::string lipsum::Generator::paragraph | ( | int | num = 1, |
| bool | useLipsum = true ) |
Generate paragraphs.
Generate multiple paragraphs. If num is negative, print a warning to the console.
| num | The number of paragraphs. By default 1. |
| useLipsum | Whether "Lorem ipsum..." should start the paragraph(s). By default true. |
| std::string lipsum::Generator::phone_number | ( | ) |
Generate a phone number.
Generate a phone number in the format "(+1) xxx-xxx-xxxx".
| std::string lipsum::Generator::plain_url | ( | ) |
Generate a plain URL.
Generate a URL with "lpsmcpp-" and a random word followed by a random TLD.
|
private |
Overload of random_number() for bool.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
| min | The minimum value. |
| max | The maximum value. |
|
private |
Overload of random_number() for char.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
| min | The minimum value. |
| max | The maximum value. |
|
inlineprivate |
Generate a random number.
Generate a random number between min and max, inclusive. If T is an integer, use std::uniform_int_distribution. Else, use std::uniform_real_distribution. This function is private.
| T | The type of the random number. Must be a uniform-distribution type, i.e. ints (excluding chars and bool) and floats. |
| min | The minimum value. |
| max | The maximum value. |
| std::string lipsum::Generator::scramble | ( | int | length = 16, |
| char | minChar = ' ', | ||
| char | maxChar = '~' ) |
Generate a random character scramble.
Generate a random string of text with random characters. If length is negative, print a warning to the console. Add length number of random characters from minChar to maxChar to the string.
| length | The number of characters. By default 16. |
| minChar | The lowest-valued ASCII character that can appear. By default a space. |
| maxChar | The highest-valued ASCII character than can appear. By default a tilde. |
| std::string lipsum::Generator::sentence | ( | int | num = 1, |
| bool | useLipsum = true ) |
Generate sentences.
Generate multiple sentences separated by spaces. If num is negative, print a warning to the console. If useLipsum is true, make the first sentence the default lorem-ipsum sentence.
| num | The number of sentences. By default 1. |
| useLipsum | Whether "Lorem ipsum..." should start the sentence(s). By default true. |
|
private |
Generate a single Markdown or HTML paragraph.
Generate a single paragraph in Markdown or HTML format. This function is private. Formerly known as single_md_paragraph(). It works by first choosing a random number of sentences, and if useHtml is true, start an HTML paragraph tag. It then loops that number of times, choosing an internal value fmtRoll with a 1 in 15 chance of being 1. If fmtRoll is 1, choose whether to add a link and whether an emphasized sentence will be bold or italic. If useLipsum is true and it is currently on the first line, add the default lorem-ipsum sentence. Else, if fmtRoll is 1 and a link is being added, append a link. Else, if fmtRoll is 1 and a link is not being added, append an emphasized sentence. Else, append a normal sentence. Then, append a space. If useHtml is true, close the HTML paragraph tag. Finally, end with two new line characters. If doing a minimum build, return an empty string.
| useLipsum | Whether "Lorem ipsum..." should start the paragraph. |
| useHtml | Whether HTML should be outputted instead of Markdown. |
|
private |
Generate a single paragraph.
Generate a single paragraph. This function is private. It works by starting the paragraph with a single tab character and picking a random number of sentences. It loops that number of times, and if useLipsum is true and it is the first line, add the default lorem-ipsum sentence. Else, add a random sentence. It then will add a space. Once the loop is done, if the string is not empty, remove the last trailing space, and finally end with a newline.
| useLipsum | Whether "Lorem ipsum..." should start the paragraph. |
|
private |
Generate a single sentence.
Generate a single sentence. This function is private. It works by picking a random number of sentence fragments and joining them with random punctuation marks (weighted towards commas, but semicolons, colons, and dashes can appear). It ends the sentence with a period, exclamation mark, or comma. It then capitalizes the first letter of the sentence. If in minimum build mode, only use commas and periods.
| wordArg | The minimum and maximum possible number of words in a sentence fragment. |
| frag | The minimum and maximum possible number of sentence fragments in the sentence. |
| std::string lipsum::Generator::slug | ( | char | separator = '-' | ) |
Generate a slug.
Generate a sentence fragment with the spaces replaced with the specified separator character.
| separator | The separator character. By default a hyphen. |
| std::string lipsum::Generator::text | ( | bool | useLipsum = true | ) |
Generate a random number of random paragraphs.
Generate a random number of random paragraphs by choosing a random number of paragraphs and calling paragraph().
| useLipsum | Whether "Lorem ipsum..." should start the paragraph(s). By default true. |
|
private |
Pick a random TLD.
This function picks a random TLD out of .com, .org, .net, .edu, .io, .ca, and .co.uk, each with chances of 70%, 10%, 7%, 5%, 5%, 2%, and 1% respectively. This function is private. If doing a minimum build, choose .com.
| void lipsum::Generator::toggle_lazy | ( | ) |
Toggle the lazy flag.
Toggle the lazy flag. If "lazy" is false, set it to true; else, set it to false.
| std::string lipsum::Generator::url | ( | ) |
Generate a URL.
Generate a URL starting in https://, followed by a plain url, followed by a slash and a random HTML id as a slug separated by hyphens.
|
private |
Choose a random index based off weights.
This function chooses a random index of weights, with higher valued weights being more likely. To do this, it passes the weights into an std::discrete_distribution.
| weights | The weights. |
| std::string lipsum::Generator::word | ( | int | num = 1 | ) |
Generate words.
Generate the specified number of words, separated by spaces. If num is negative, print a warning to the console.
| num | The number of words. By default 1. |
| std::string lipsum::Generator::xml | ( | int | choices = 30 | ) |
Generate an XML document.
Generate a document in XML format. It does this by starting the XML prolog, choosing the root element, and starting it. It then repeats choices times: it generates a random number from 0 to 2. If it is 0, start an XML tag with a random element with optionally an attribute, and also add it to the tag stack. If the number is 1, add a closed element with a random sentence inside. If the number is 2, close the previously opened tag if possible. Finally, end the loop and close all remaining tags in the tag stack, and close the root element. If doing a minimum build, return an empty string.
| choices | The number of choices (start element, end element, add data element) that are made. By default 30. |
|
private |
Source used for generation.
The source passed into functions. By default the lorem-ipsum source "lorem" from sample.inl.