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

Classes

struct  CharCount
 

Typedefs

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

Enumerations

enum class  Uuid {
  V1 , V3 , V4 , V5 ,
  V6 , V7 , V8
}
 
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 uuid (Uuid uuid=Uuid::V4)
 Generates an Universally Unique Identifier, defaults to V4.
 
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 

◆ Uuid

enum class faker::string::Uuid
strong
Enumerator
V1 
V3 
V4 
V5 
V6 
V7 
V8 

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.
faker::string::alpha({{'A',{2,2}}, 5, StringCasing::Upper) // "DACAC"
faker::string::alpha({{'a',{0,0}},{'b',{3,3}},{'c', {0,2}}}, 10, StringCasing::Lower) // "bicnmmkbbp"
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.

◆ 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.
faker::string::alpha(5, StringCasing::Upper) // "DTCIC"
faker::string::alpha(4, StringCasing::Lower) // "brpt"
StringCasing
Definition string.h:36
Definition airline.h:9

◆ 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.
faker::string::alphanumeric({{'A', {3,6}},{'1', {1,1}}, 5, StringCasing::Upper) // "1EAAA"
faker::string::alphanumeric({{'a',{0,2}},{'2',{0,3}},{'z',{3,5}}}, 10, StringCasing::Lower) // "z1naazrqz0"
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.

◆ 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.
faker::string::alphanumeric(5, StringCasing::Upper) // "3e5V7"
faker::string::alphanumeric(4, StringCasing::Lower) // "1nrq"

◆ 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.
faker::string::fromCharacters("qwerty", 5) // "qrwqt"
FAKER_CXX_EXPORT std::string fromCharacters(const std::string &characters, unsigned length=1)
Generates a string consisting of given 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.
faker::string::fromCharacters({{'q',{2,2}},{'e',{1,5}}}, "qwerty", 8) // "yqreqety"

◆ 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.
GuaranteeMap guarantee { {'0',{3,10}},{'a',{6,8}} }; // "000aaaaaa"
FAKER_CXX_EXPORT std::string generateAtLeastString(const GuaranteeMap &guarantee)
Generates the least required string for a given guarantee map.
std::map< char, CharCount > GuaranteeMap
Definition string.h:48

◆ 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.
GuaranteeMap guarantee = {{'0',{5,10}},{'1',{6,10}}};
std::string targetCharacters = "01";
unsigned int length = 10;
faker::string::isValidGuarantee(guarantee,targetCharacters,length) // false
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.

◆ 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(); // Possible output: "Hf5lN8L2wQ"
FAKER_CXX_EXPORT std::string nanoId()
Generates a unique, URL-safe string identifier of default length.

◆ 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(10); // Possible output: "F8aXz1Q4wB"
nanoId(21); // Possible output: "V2JlO7GZ1kPl9FxErRqzS"

◆ 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`.
nanoId(10, 15); // Possible output: "Vb2Ej8G9wPcQ2"
nanoId(5, 8); // Possible output: "P1zZ3x"

◆ 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.
faker::string::numeric({'5',{3,6}}, 6) // "055542"
faker::string::numeric({'0',{0,0}}, {'4',{1,1}}, 6, false) // "854829"
FAKER_CXX_EXPORT std::string numeric(unsigned length=1, bool allowLeadingZeros=true)
Generates a given length string of digits.

◆ 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.
faker::string::numeric(6) // "035742"
faker::string::numeric(6, false) // "254429"

◆ 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.
faker::string::sample({}) // "Zo!.:*e>wR"
faker::string::sample({{'|' ,{2,2}},{'^',{0,0}},{':',{1,8}}}, 8) // "|6Bye8:|"
FAKER_CXX_EXPORT std::string sample(unsigned length=10)
Returns a string containing UTF-16 chars between 33 and 125 (`!` to `}`).

◆ 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.
faker::string::sample() // "Zo!.:*e>wR"
faker::string::sample(5) // "6Bye8"

◆ 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.
faker::string::sample() // "#$%^&#$%^&"
faker::string::sample(1,5) // "#$%^&"

◆ 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.
faker::string::ulid() // "0001C7STHC0G2081040G208104"
faker::string::ulid(1484581420) // "0001C7STHC0G2081040G208104"
FAKER_CXX_EXPORT std::string ulid(time_t refDate=std::time(nullptr))
Generates an Universally Unique Lexicographically Sortable Identifier.

◆ uuid()

FAKER_CXX_EXPORT std::string faker::string::uuid ( Uuid uuid = Uuid::V4)

Generates an Universally Unique Identifier, defaults to V4.

Parameters
genA random number generator (type RandomGenerator)
Returns
UUID.
faker::string::uuid() // "27666229-cedb-4a45-8018-98b1e1d921e2" // V4
faker::string::uuid(Uuid::V1) // "04f916a0-af32-11ef-9cd2-0242ac120002"
faker::string::uuid(Uuid::V3) // "a3bb189e-8bf9-3888-9912-ace4e6543002"
faker::string::uuid(Uuid::V4) // "27666229-cedb-4a45-8018-98b1e1d921e2"
faker::string::uuid(Uuid::V5) // "27666229-cedb-4a45-8018-98b1e1d921e2"
faker::string::uuid(Uuid::V6) // "27666229-cedb-4a45-8018-98b1e1d921e2"
faker::string::uuid(Uuid::V7) // "27666229-cedb-4a45-8018-98b1e1d921e2"
faker::string::uuid(Uuid::V8) // "27666229-cedb-4a45-8018-98b1e1d921e2"
FAKER_CXX_EXPORT std::string uuid(Uuid uuid=Uuid::V4)
Generates an Universally Unique Identifier, defaults to V4.
Uuid
Definition string.h:25