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 int 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.
 
template<typename T = std::mt19937>
std::string uuid (RandomGenerator< T > gen=RandomGenerator< std::mt19937 >{})
 Generates an Universally Unique Identifier with version 4.
 
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 length=10)
 Returns a string containing "~`!@#$%^&*()_-+={[}]|:;\"'<,>.?/".
 
FAKER_CXX_EXPORT std::string symbol (unsigned int minLength, unsigned int maxLength)
 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.
 

Typedef Documentation

◆ GuaranteeMap

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

A std::map where user can specify the count required for specific chars

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.
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:16
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.

Returns
least required std::string
Parameters
guaranteeA std::map<char,CharCount> which stores the guarantee specified by the user
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:31

◆ isValidGuarantee()

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

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

Returns
a bool.
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.
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 int length)
Checks if the given guarantee map is valid for given targetCharacters and length.

◆ 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() [1/2]

FAKER_CXX_EXPORT std::string faker::string::symbol ( unsigned int minLength,
unsigned int maxLength )

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) // "#$%^&"

◆ symbol() [2/2]

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

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

Parameters
lengthThe number of characters to generate. Defaults to `10`.
Returns
Sample string.
faker::string::sample() // "#$%^&#$%^&"
faker::string::sample(5) // "#$%^&"

◆ uuid()

template<typename T = std::mt19937>
std::string faker::string::uuid ( RandomGenerator< T > gen = RandomGenerator<std::mt19937>{})

Generates an Universally Unique Identifier with version 4.

Returns
UUIDv4.
Parameters
genA random number generator (type RandomGenerator)
faker::string::uuid() // "27666229-cedb-4a45-8018-98b1e1d921e2"
std::string uuid(RandomGenerator< T > gen=RandomGenerator< std::mt19937 >{})
Generates an Universally Unique Identifier with version 4.
Definition string.h:77