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

Classes

struct  PasswordOptions
 

Enumerations

enum class  HttpResponseType {
  ClientError , Informational , Redirection , ServerError ,
  Success
}
 
enum class  WebProtocol { Http , Https }
 
enum class  IPv4Class { A , B , C }
 
enum class  EmojiType {
  Activity , Body , Flag , Food ,
  Nature , Object , Person , Smiley ,
  Symbol , Travel
}
 

Functions

FAKER_CXX_EXPORT std::string username (std::optional< std::string > firstName=std::nullopt, std::optional< std::string > lastName=std::nullopt, Locale locale=Locale::en_US)
 Generates a username using the given person's name as base.
 
FAKER_CXX_EXPORT std::string email (std::optional< std::string > firstName=std::nullopt, std::optional< std::string > lastName=std::nullopt, std::optional< std::string > emailHost=std::nullopt, Locale locale=Locale::en_US)
 Generates an email address using the given person's name as base.
 
FAKER_CXX_EXPORT std::string exampleEmail (std::optional< std::string > firstName=std::nullopt, std::optional< std::string > lastName=std::nullopt, Locale locale=Locale::en_US)
 Generates an email address using the given person's name as base with example domain.
 
FAKER_CXX_EXPORT std::string password (int length=16, const PasswordOptions &options={})
 Generates a random password-like string. Do not use this method for generating actual passwords for users. Since the source of the randomness is not cryptographically secure, neither is this generator.
 
FAKER_CXX_EXPORT std::string_view emoji (std::optional< EmojiType > type=std::nullopt)
 Returns a random emoji.
 
FAKER_CXX_EXPORT bool checkIfEmojiIsValid (const std::string &emojiToCheck)
 Verify that a given emoji is valid.
 
FAKER_CXX_EXPORT std::string_view protocol ()
 Returns a random web protocol. Either `http` or `https`.
 
FAKER_CXX_EXPORT std::string_view httpMethod ()
 Generates a random http method name.
 
FAKER_CXX_EXPORT unsigned httpStatusCode (std::optional< HttpResponseType > responseType=std::nullopt)
 Returns a random http status code.
 
FAKER_CXX_EXPORT std::string_view httpRequestHeader (Locale locale=Locale::en_US)
 Generates a random http request header.
 
FAKER_CXX_EXPORT std::string_view httpResponseHeader (Locale locale=Locale::en_US)
 Generates a random http response header.
 
FAKER_CXX_EXPORT std::string_view httpMediaType (Locale locale=Locale::en_US)
 Generates a random http media type.
 
FAKER_CXX_EXPORT std::string ipv4 (const IPv4Class &ipv4class=IPv4Class::C)
 Returns a string containing randomized ipv4 address of the given class.
 
FAKER_CXX_EXPORT std::string ipv4 (const std::array< unsigned int, 4 > &baseIpv4Address, const std::array< unsigned int, 4 > &generationMask)
 Returns a string containing randomized ipv4 address based on given base address and mask.
 
FAKER_CXX_EXPORT std::string ipv6 ()
 Returns a string containing randomized ipv6 address.
 
FAKER_CXX_EXPORT std::string mac (const std::string &sep=":")
 Returns a generated random mac address.
 
FAKER_CXX_EXPORT unsigned port ()
 Generates a random port.
 
FAKER_CXX_EXPORT std::string url (const WebProtocol &webProtocol=WebProtocol::Https, Locale locale=Locale::en_US)
 Generates a random url.
 
FAKER_CXX_EXPORT std::string domainName (Locale locale=Locale::en_US)
 Generates a random domain name.
 
FAKER_CXX_EXPORT std::string domainWord ()
 Generates a random domain word.
 
FAKER_CXX_EXPORT std::string_view domainSuffix (Locale locale=Locale::en_US)
 Generates a random domain suffix.
 
FAKER_CXX_EXPORT std::string anonymousUsername (unsigned maxLength)
 Generates a random username.
 
FAKER_CXX_EXPORT std::string getJWTToken (const std::optional< std::map< std::string, std::string > > &header=std::nullopt, const std::optional< std::map< std::string, std::string > > &payload=std::nullopt, const std::optional< std::string > &refDate=std::nullopt)
 Generates a JSON Web Token (JWT).
 
FAKER_CXX_EXPORT std::string_view getJWTAlgorithm (Locale locale=Locale::en_US)
 Returns the algorithm used for signing the JWT.
 

Enumeration Type Documentation

◆ EmojiType

enum class faker::internet::EmojiType
strong
Enumerator
Activity 
Body 
Flag 
Food 
Nature 
Object 
Person 
Smiley 
Symbol 
Travel 

◆ HttpResponseType

Enumerator
ClientError 
Informational 
Redirection 
ServerError 
Success 

◆ IPv4Class

enum class faker::internet::IPv4Class
strong
Enumerator

◆ WebProtocol

enum class faker::internet::WebProtocol
strong
Enumerator
Http 
Https 

Function Documentation

◆ anonymousUsername()

FAKER_CXX_EXPORT std::string faker::internet::anonymousUsername ( unsigned maxLength)

Generates a random username.

Parameters
maxLengthmaxLength of the generated username.
Returns
Username.
faker::internet::anonymousUsername() // "profusebrother", "richad", "powerfuldifferential"
FAKER_CXX_EXPORT std::string anonymousUsername(unsigned maxLength)
Generates a random username.

◆ checkIfEmojiIsValid()

FAKER_CXX_EXPORT bool faker::internet::checkIfEmojiIsValid ( const std::string & emojiToCheck)

Verify that a given emoji is valid.

Parameters
emojiToCheckthe emoji to check.
Returns
true if emojiToCheck is found in one of the vectors, false otherwise.
FAKER_CXX_EXPORT bool checkIfEmojiIsValid(const std::string &emojiToCheck)
Verify that a given emoji is valid.

◆ domainName()

FAKER_CXX_EXPORT std::string faker::internet::domainName ( Locale locale = Locale::en_US)

Generates a random domain name.

Returns
Domain name.
faker::internet::domainName() // "slow-timer.info"
FAKER_CXX_EXPORT std::string domainName(Locale locale=Locale::en_US)
Generates a random domain name.

◆ domainSuffix()

FAKER_CXX_EXPORT std::string_view faker::internet::domainSuffix ( Locale locale = Locale::en_US)

Generates a random domain suffix.

Returns
Domain suffix.
FAKER_CXX_EXPORT std::string_view domainSuffix(Locale locale=Locale::en_US)
Generates a random domain suffix.

◆ domainWord()

FAKER_CXX_EXPORT std::string faker::internet::domainWord ( )

Generates a random domain word.

Returns
Domain word.
faker::internet::domainWord() // "close-reality"
FAKER_CXX_EXPORT std::string domainWord()
Generates a random domain word.

◆ email()

FAKER_CXX_EXPORT std::string faker::internet::email ( std::optional< std::string > firstName = std::nullopt,
std::optional< std::string > lastName = std::nullopt,
std::optional< std::string > emailHost = std::nullopt,
Locale locale = Locale::en_US )

Generates an email address using the given person's name as base.

Parameters
firstNameThe optional first name to use. If not specified, a random one will be chosen.
lastNameThe optional last name to use. If not specified, a random one will be chosen.
emailHostThe optional email host name to use. If not specified, a random one will be chosen.
Returns
Email including neither, one or both of the provided names, with random/provided email host.
faker::internet::email() // "Jimenez.Clyde@gmail.com"
faker::internet::email("Tom") // "TomRichardson79@outlook.com"
faker::internet::email(std::nullopt, "Howard") // "FreddieHoward@hotmail.com"
faker::internet::email("Cindy", "Young") // "Young_Cindy@gmail.com"
faker::internet::email(std::nullopt, std::nullopt, "example.com") // "Wright.Edna1973@code.com"
FAKER_CXX_EXPORT std::string email(std::optional< std::string > firstName=std::nullopt, std::optional< std::string > lastName=std::nullopt, std::optional< std::string > emailHost=std::nullopt, Locale locale=Locale::en_US)
Generates an email address using the given person's name as base.
Definition airline.h:9

◆ emoji()

FAKER_CXX_EXPORT std::string_view faker::internet::emoji ( std::optional< EmojiType > type = std::nullopt)

Returns a random emoji.

Parameters
typeThe optional type of them emoji to be generated.
Returns
Emoji.
faker::internet::emoji(EmojiType::Food) // "🍕"
FAKER_CXX_EXPORT std::string_view emoji(std::optional< EmojiType > type=std::nullopt)
Returns a random emoji.
EmojiType
Definition internet.h:120

◆ exampleEmail()

FAKER_CXX_EXPORT std::string faker::internet::exampleEmail ( std::optional< std::string > firstName = std::nullopt,
std::optional< std::string > lastName = std::nullopt,
Locale locale = Locale::en_US )

Generates an email address using the given person's name as base with example domain.

Parameters
firstNameThe optional first name to use. If not specified, a random one will be chosen.
lastNameThe optional last name to use. If not specified, a random one will be chosen.
Returns
Email including neither, one or both of the provided names, with example email host.
faker::internet::exampleEmail() // "Jimenez.Clyde@example.com"
FAKER_CXX_EXPORT std::string exampleEmail(std::optional< std::string > firstName=std::nullopt, std::optional< std::string > lastName=std::nullopt, Locale locale=Locale::en_US)
Generates an email address using the given person's name as base with example domain.

◆ getJWTAlgorithm()

FAKER_CXX_EXPORT std::string_view faker::internet::getJWTAlgorithm ( Locale locale = Locale::en_US)

Returns the algorithm used for signing the JWT.

This function provides the algorithm that is used to sign the JSON Web Token (JWT).

Returns
A string view representing the JWT signing algorithm.
FAKER_CXX_EXPORT std::string_view getJWTAlgorithm(Locale locale=Locale::en_US)
Returns the algorithm used for signing the JWT.

◆ getJWTToken()

FAKER_CXX_EXPORT std::string faker::internet::getJWTToken ( const std::optional< std::map< std::string, std::string > > & header = std::nullopt,
const std::optional< std::map< std::string, std::string > > & payload = std::nullopt,
const std::optional< std::string > & refDate = std::nullopt )

Generates a JSON Web Token (JWT).

This function generates a JWT using the provided header, payload, and reference date. If no header or payload is provided, default values will be used. The reference date is optional and can be used to set the "iat" (issued at) claim in the payload.

Parameters
headerThe optional header map to include in the JWT. Defaults to a standard header.
payloadThe optional payload map to include in the JWT. Defaults to a standard payload.
refDateThe optional reference date to set the "iat" claim. Defaults to the current date and time.
Returns
A string representing the generated JWT.
std::map<std::string, std::string> header = {{"alg", "HS256"}, {"typ", "JWT"}};
std::map<std::string, std::string> payload = {{"sub", "1234567890"}, {"name", "John Doe"}, {"admin", "true"}};
faker::internet::getJWTToken(header, payload); // "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."
FAKER_CXX_EXPORT std::string getJWTToken(const std::optional< std::map< std::string, std::string > > &header=std::nullopt, const std::optional< std::map< std::string, std::string > > &payload=std::nullopt, const std::optional< std::string > &refDate=std::nullopt)
Generates a JSON Web Token (JWT).

◆ httpMediaType()

FAKER_CXX_EXPORT std::string_view faker::internet::httpMediaType ( Locale locale = Locale::en_US)

Generates a random http media type.

Returns
Http media type.
faker::internet::httpMediaType() // "application/json"
FAKER_CXX_EXPORT std::string_view httpMediaType(Locale locale=Locale::en_US)
Generates a random http media type.

◆ httpMethod()

FAKER_CXX_EXPORT std::string_view faker::internet::httpMethod ( )

Generates a random http method name.

Returns
Http method name.
FAKER_CXX_EXPORT std::string_view httpMethod()
Generates a random http method name.

◆ httpRequestHeader()

FAKER_CXX_EXPORT std::string_view faker::internet::httpRequestHeader ( Locale locale = Locale::en_US)

Generates a random http request header.

Returns
Http request header.
FAKER_CXX_EXPORT std::string_view httpRequestHeader(Locale locale=Locale::en_US)
Generates a random http request header.

◆ httpResponseHeader()

FAKER_CXX_EXPORT std::string_view faker::internet::httpResponseHeader ( Locale locale = Locale::en_US)

Generates a random http response header.

Returns
Http response header.
FAKER_CXX_EXPORT std::string_view httpResponseHeader(Locale locale=Locale::en_US)
Generates a random http response header.

◆ httpStatusCode()

FAKER_CXX_EXPORT unsigned faker::internet::httpStatusCode ( std::optional< HttpResponseType > responseType = std::nullopt)

Returns a random http status code.

Parameters
responseTypeThe type of the http response.
Returns
Http status code.
faker::internet::httpStatusCode(HttpStatusCodeType::success) // 201
FAKER_CXX_EXPORT unsigned httpStatusCode(std::optional< HttpResponseType > responseType=std::nullopt)
Returns a random http status code.

◆ ipv4() [1/2]

FAKER_CXX_EXPORT std::string faker::internet::ipv4 ( const IPv4Class & ipv4class = IPv4Class::C)

Returns a string containing randomized ipv4 address of the given class.

Parameters
ipv4classAddress class to be generated.
Returns
String representation of the ipv4 address.
faker::internet::ipv4() // "192.168.0.1"
faker::internet::ipv4(IPv4Class::classA) // "10.0.0.1"
IPv4Class
Definition internet.h:31
FAKER_CXX_EXPORT std::string ipv4(const IPv4Class &ipv4class=IPv4Class::C)
Returns a string containing randomized ipv4 address of the given class.

◆ ipv4() [2/2]

FAKER_CXX_EXPORT std::string faker::internet::ipv4 ( const std::array< unsigned int, 4 > & baseIpv4Address,
const std::array< unsigned int, 4 > & generationMask )

Returns a string containing randomized ipv4 address based on given base address and mask.

Generated result is compliant with the ipv4 classes. Bits of the baseIpv4Address not covered by the generationMask will be ignored and replaced during generation. Bits covered by the mask will be kept in the result. Mask should be provided in the same format as regular ipv4 mask.

Parameters
generationMaskMask deciding which bits of the base address should be kept during randomization.
baseIpv4AddressAddress to randomize from.
Returns
std::string representation of the ipv4 address.
faker::internet::ipv4({255.0.0.0}, {10.100.100.100}) // "10.128.17.1"
faker::internet::ipv4({255.255.128.0}, {129.168.255.0}) // "192.168.128.10"

◆ ipv6()

FAKER_CXX_EXPORT std::string faker::internet::ipv6 ( )

Returns a string containing randomized ipv6 address.

Returns
String representation of the ipv6 address.
faker::internet::ipv6() // "269f:1230:73e3:318d:842b:daab:326d:897b"
FAKER_CXX_EXPORT std::string ipv6()
Returns a string containing randomized ipv6 address.

◆ mac()

FAKER_CXX_EXPORT std::string faker::internet::mac ( const std::string & sep = ":")

Returns a generated random mac address.

Parameters
sepSeparator to use. Defaults to ":". Also can be "-" or "".
Returns
A generated random mac address.
faker::internet::mac() // "2d:10:34:2f:ac:ac"
FAKER_CXX_EXPORT std::string mac(const std::string &sep=":")
Returns a generated random mac address.

◆ password()

FAKER_CXX_EXPORT std::string faker::internet::password ( int length = 16,
const PasswordOptions & options = {} )

Generates a random password-like string. Do not use this method for generating actual passwords for users. Since the source of the randomness is not cryptographically secure, neither is this generator.

Parameters
lengthThe length of the password to generate. Defaults to `16`.
optionsThe optional password options to use. Options include whether to include upperLetters, lowerLetters, numbers and symbols in password generation. Defaults to include all.
Returns
Random password-like string.
faker::internet::password() // "gXGpe9pKfFcKy9R"
faker::internet::password(25) // "xv8vDu*wM!Rg0$zd0kH%8p!WY"
FAKER_CXX_EXPORT std::string password(int length=16, const PasswordOptions &options={})
Generates a random password-like string. Do not use this method for generating actual passwords for u...

◆ port()

FAKER_CXX_EXPORT unsigned faker::internet::port ( )

Generates a random port.

Returns
Port.
FAKER_CXX_EXPORT unsigned port()
Generates a random port.

◆ protocol()

FAKER_CXX_EXPORT std::string_view faker::internet::protocol ( )

Returns a random web protocol. Either `http` or `https`.

Returns
Web protocol.
FAKER_CXX_EXPORT std::string_view protocol()
Returns a random web protocol. Either `http` or `https`.

◆ url()

FAKER_CXX_EXPORT std::string faker::internet::url ( const WebProtocol & webProtocol = WebProtocol::Https,
Locale locale = Locale::en_US )

Generates a random url.

Parameters
webProtocolWeb protocol to generate url with. Defaults to `WebProtocolHttps`.
Returns
Http(s) url.
faker::internet::url() // "https://slow-timer.info"
FAKER_CXX_EXPORT std::string url(const WebProtocol &webProtocol=WebProtocol::Https, Locale locale=Locale::en_US)
Generates a random url.

◆ username()

FAKER_CXX_EXPORT std::string faker::internet::username ( std::optional< std::string > firstName = std::nullopt,
std::optional< std::string > lastName = std::nullopt,
Locale locale = Locale::en_US )

Generates a username using the given person's name as base.

Parameters
firstNameThe optional first name to include in username.
lastNameThe optional last name to include in username.
localeThe locale. Defaults to `Locale::en_US`.
Returns
Username including neither, one or both of the provided names.
faker::internet::username() // "Richardson.Jeffrey1997"
faker::internet::username("Michael") // "Michael_Allen29"
faker::internet::username(std::nullopt, "Cieslar") // "Phillip_Cieslar20"
faker::internet::username("Andrew", "Cieslar") // "Andrew.Cieslar"
FAKER_CXX_EXPORT std::string username(std::optional< std::string > firstName=std::nullopt, std::optional< std::string > lastName=std::nullopt, Locale locale=Locale::en_US)
Generates a username using the given person's name as base.