Faker C++
Loading...
Searching...
No Matches
faker::string Namespace Reference

Classes

struct  CharCount
 

Typedefs

using GuaranteeMap = std::map<char, CharCount>
 

Enumerations

enum class  StringCasing { Mixed , Lower , Upper }
 

Functions

FAKER_CXX_EXPORT bool isValidGuarantee (GuaranteeMap &guarantee, std::set< char > &targetCharacters, unsigned length)
 Checks if the given guarantee map is valid for given targetCharacters and length.
 
FAKER_CXX_EXPORT std::string generateAtLeastString (const GuaranteeMap &guarantee)
 Generates the least required string for a given guarantee map.
 
FAKER_CXX_EXPORT std::string uuidV1 ()
 Generates an Universally Unique Identifier version 1.
 
FAKER_CXX_EXPORT std::string uuidV3 ()
 Generates an Universally Unique Identifier version 3.
 
FAKER_CXX_EXPORT std::string uuidV4 ()
 Generates an Universally Unique Identifier version 4.
 
FAKER_CXX_EXPORT std::string uuidV5 (const std::string &input, const std::string &namespaceUuid="dbedb1fb-a628-49f3-9e4d-58166108df5f")
 Generates an Universally Unique Identifier version 5.
 
FAKER_CXX_EXPORT std::string uuidV6 ()
 Generates an Universally Unique Identifier version 6.
 
FAKER_CXX_EXPORT std::string uuidV7 ()
 Generates an Universally Unique Identifier version 7.
 
FAKER_CXX_EXPORT std::string ulid (time_t refDate=std::time(nullptr))
 Generates an Universally Unique Lexicographically Sortable Identifier.
 
FAKER_CXX_EXPORT std::string sample (unsigned length=10)
 Returns a string containing UTF-16 chars between 33 and 125 (`!` to `}`).
 
FAKER_CXX_EXPORT std::string sample (GuaranteeMap &&guarantee, unsigned length=10)
 Returns a string containing UTF-16 chars between 33 and 125 (`!` to `}`).
 
FAKER_CXX_EXPORT std::string symbol (unsigned minLength=1, unsigned maxLength=10)
 Returns a string containing "~`!@#$%^&*()_-+={[}]|:;\"'<,>.?/".
 
FAKER_CXX_EXPORT std::string fromCharacters (const std::string &characters, unsigned length=1)
 Generates a string consisting of given characters.
 
FAKER_CXX_EXPORT std::string fromCharacters (GuaranteeMap &&guarantee, const std::string &characters, unsigned length=1)
 Generates a string consisting of given characters.
 
FAKER_CXX_EXPORT std::string alpha (unsigned length=1, StringCasing casing=StringCasing::Mixed, const std::string &excludeCharacters="")
 Generates a string consisting of letters in the English alphabet.
 
FAKER_CXX_EXPORT std::string alpha (GuaranteeMap &&guarantee, unsigned length=1, StringCasing casing=StringCasing::Mixed)
 Generates a string consisting of letters in the English alphabet.
 
FAKER_CXX_EXPORT std::string alphanumeric (unsigned length=1, StringCasing casing=StringCasing::Mixed, const std::string &excludeCharacters="")
 Generates a string consisting of alpha characters and digits.
 
FAKER_CXX_EXPORT std::string alphanumeric (GuaranteeMap &&guarantee, unsigned length=1, StringCasing casing=StringCasing::Mixed)
 Generates a string consisting of alpha characters and digits.
 
FAKER_CXX_EXPORT std::string numeric (unsigned length=1, bool allowLeadingZeros=true)
 Generates a given length string of digits.
 
FAKER_CXX_EXPORT std::string numeric (GuaranteeMap &&guarantee, unsigned length=1, bool allowLeadingZeros=true)
 Generates a given length string of digits.
 
FAKER_CXX_EXPORT std::string nanoId (int length)
 Generates a unique, URL-safe string identifier of the specified length.
 
FAKER_CXX_EXPORT std::string nanoId ()
 Generates a unique, URL-safe string identifier of default length.
 
FAKER_CXX_EXPORT std::string nanoId (int minLength, int maxLength)
 Generates a unique, URL-safe string identifier of random length within a specified range.
 

Typedef Documentation

◆ GuaranteeMap

using faker::string::GuaranteeMap = std::map<char, CharCount>

Enumeration Type Documentation

◆ StringCasing

enum class faker::string::StringCasing
strong
Enumerator
Mixed 
Lower 
Upper 

Function Documentation

◆ alpha() [1/2]

FAKER_CXX_EXPORT std::string faker::string::alpha ( GuaranteeMap && guarantee,
unsigned length = 1,
StringCasing casing = StringCasing::Mixed )

Generates a string consisting of letters in the English alphabet.

Parameters
guaranteeA map specifying char count constraints if any
lengthThe number of characters to generate. Defaults to `1`.
casingThe casing of the characters. Defaults to `StringCasingMixed`.
Returns
Alpha string.

◆ alpha() [2/2]

FAKER_CXX_EXPORT std::string faker::string::alpha ( unsigned length = 1,
StringCasing casing = StringCasing::Mixed,
const std::string & excludeCharacters = "" )

Generates a string consisting of letters in the English alphabet.

Parameters
lengthThe number of characters to generate. Defaults to `1`.
casingThe casing of the characters. Defaults to `StringCasingMixed`.
excludeCharactersThe characters to be excluded from the string to generate. Defaults to ``.
Returns
Alpha string.

◆ alphanumeric() [1/2]

FAKER_CXX_EXPORT std::string faker::string::alphanumeric ( GuaranteeMap && guarantee,
unsigned length = 1,
StringCasing casing = StringCasing::Mixed )

Generates a string consisting of alpha characters and digits.

Parameters
guaranteeA map specifying char count constraints if any
lengthThe number of characters to generate. Defaults to `1`.
casingThe casing of the characters. Defaults to `StringCasingMixed`.
Returns
Alphanumeric string.

◆ alphanumeric() [2/2]

FAKER_CXX_EXPORT std::string faker::string::alphanumeric ( unsigned length = 1,
StringCasing casing = StringCasing::Mixed,
const std::string & excludeCharacters = "" )

Generates a string consisting of alpha characters and digits.

Parameters
lengthThe number of characters to generate. Defaults to `1`.
casingThe casing of the characters. Defaults to `StringCasingMixed`.
excludeCharactersThe characters to be excluded from alphanumeric characters to generate string from. Defaults to ``.
Returns
Alphanumeric string.

◆ fromCharacters() [1/2]

FAKER_CXX_EXPORT std::string faker::string::fromCharacters ( const std::string & characters,
unsigned length = 1 )

Generates a string consisting of given characters.

Parameters
charactersThe characters to generate string with.
lengthThe number of characters to generate. Defaults to `1`.
Returns
String from characters.

◆ fromCharacters() [2/2]

FAKER_CXX_EXPORT std::string faker::string::fromCharacters ( GuaranteeMap && guarantee,
const std::string & characters,
unsigned length = 1 )

Generates a string consisting of given characters.

Parameters
guaranteeA map specifying char count constraints if any
charactersThe characters to generate string with.
lengthThe number of characters to generate. Defaults to `1`.
Returns
String from characters.

◆ generateAtLeastString()

FAKER_CXX_EXPORT std::string faker::string::generateAtLeastString ( const GuaranteeMap & guarantee)

Generates the least required string for a given guarantee map.

Parameters
guaranteeA std::map<char,CharCount> which stores the guarantee specified by the user
Returns
Least required std::string.

◆ isValidGuarantee()

FAKER_CXX_EXPORT bool faker::string::isValidGuarantee ( GuaranteeMap & guarantee,
std::set< char > & targetCharacters,
unsigned length )

Checks if the given guarantee map is valid for given targetCharacters and length.

Parameters
guaranteeA std::map that maps the count range of specific characters required
targetCharactersA std::string consisting of all chars available for that string generating function
lengthThe number of characters to generate.
Returns
A bool.

◆ nanoId() [1/3]

FAKER_CXX_EXPORT std::string faker::string::nanoId ( )

Generates a unique, URL-safe string identifier of default length.

This function generates a unique identifier with a default length of 10 characters. The identifier is URL-safe and created using a cryptographically secure random number generator.

Returns
A unique, URL-safe string identifier of default length (10 characters).

◆ nanoId() [2/3]

FAKER_CXX_EXPORT std::string faker::string::nanoId ( int length)

Generates a unique, URL-safe string identifier of the specified length.

This function generates a unique identifier using a cryptographically secure random number generator, with the output length set by the `length` parameter.

Parameters
lengthThe exact length of the identifier to generate.
Returns
A unique, URL-safe string identifier of the specified length.

◆ nanoId() [3/3]

FAKER_CXX_EXPORT std::string faker::string::nanoId ( int minLength,
int maxLength )

Generates a unique, URL-safe string identifier of random length within a specified range.

This function generates a unique identifier with a length that varies between `minLength` and `maxLength`, inclusive. The identifier is URL-safe and created using a cryptographically secure random number generator.

Parameters
minLengthThe minimum length of the identifier.
maxLengthThe maximum length of the identifier.
Returns
A unique, URL-safe string identifier with a length between `minLength` and `maxLength`.

◆ numeric() [1/2]

FAKER_CXX_EXPORT std::string faker::string::numeric ( GuaranteeMap && guarantee,
unsigned length = 1,
bool allowLeadingZeros = true )

Generates a given length string of digits.

Parameters
guaranteeA map specifying char count constraints if any
lengthThe number of digits to generate. Defaults to `1`.
allowLeadingZerosWhether leading zeros are allowed or not. Defaults to `true`.
Returns
Numeric string.

◆ numeric() [2/2]

FAKER_CXX_EXPORT std::string faker::string::numeric ( unsigned length = 1,
bool allowLeadingZeros = true )

Generates a given length string of digits.

Parameters
lengthThe number of digits to generate. Defaults to `1`.
allowLeadingZerosWhether leading zeros are allowed or not. Defaults to `true`.
Returns
Numeric string.

◆ sample() [1/2]

FAKER_CXX_EXPORT std::string faker::string::sample ( GuaranteeMap && guarantee,
unsigned length = 10 )

Returns a string containing UTF-16 chars between 33 and 125 (`!` to `}`).

Parameters
guaranteeA map specifying char count constraints if any
lengthThe number of characters to generate. Defaults to `10`.
Returns
Sample string.

◆ sample() [2/2]

FAKER_CXX_EXPORT std::string faker::string::sample ( unsigned length = 10)

Returns a string containing UTF-16 chars between 33 and 125 (`!` to `}`).

Parameters
lengthThe number of characters to generate. Defaults to `10`.
Returns
Sample string.

◆ symbol()

FAKER_CXX_EXPORT std::string faker::string::symbol ( unsigned minLength = 1,
unsigned maxLength = 10 )

Returns a string containing "~`!@#$%^&*()_-+={[}]|:;\"'<,>.?/".

Parameters
minLengthThe number of minimum characters to generate. Defaults to `1`.
maxLengthThe number of maximum characters to generate. Defaults to `10`.
Returns
Sample string.

◆ ulid()

FAKER_CXX_EXPORT std::string faker::string::ulid ( time_t refDate = std::time(nullptr))

Generates an Universally Unique Lexicographically Sortable Identifier.

Parameters
refDateA reference date (type time_t)
Returns
ULID UINT128.

◆ uuidV1()

FAKER_CXX_EXPORT std::string faker::string::uuidV1 ( )

Generates an Universally Unique Identifier version 1.

Returns
UUID v1.

◆ uuidV3()

FAKER_CXX_EXPORT std::string faker::string::uuidV3 ( )

Generates an Universally Unique Identifier version 3.

Returns
UUID V3.

◆ uuidV4()

FAKER_CXX_EXPORT std::string faker::string::uuidV4 ( )

Generates an Universally Unique Identifier version 4.

Returns
UUID V4.

◆ uuidV5()

FAKER_CXX_EXPORT std::string faker::string::uuidV5 ( const std::string & input,
const std::string & namespaceUuid = "dbedb1fb-a628-49f3-9e4d-58166108df5f" )

Generates an Universally Unique Identifier version 5.

Returns
UUID V5.

◆ uuidV6()

FAKER_CXX_EXPORT std::string faker::string::uuidV6 ( )

Generates an Universally Unique Identifier version 6.

Returns
UUID V6.

◆ uuidV7()

FAKER_CXX_EXPORT std::string faker::string::uuidV7 ( )

Generates an Universally Unique Identifier version 7.

Returns
UUID V7.