Skip to content

Commit

Permalink
Merge pull request #2 from gustavobastian/feature/word-locale
Browse files Browse the repository at this point in the history
Feature/word locale
  • Loading branch information
gustavobastian authored Oct 2, 2024
2 parents 808f1f4 + df3043f commit 0156b92
Show file tree
Hide file tree
Showing 8 changed files with 314 additions and 196 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ project(faker-cxx
include(cmake/CompilerWarnings.cmake)
include(CMakeDependentOption)

option(USE_SYSTEM_DEPENDENCIES "Use fmt and GTest from system" ON)
option(USE_SYSTEM_DEPENDENCIES "Use fmt and GTest from system" OFF)
option(BUILD_EXAMPLES "Build examples" OFF)
option(BUILD_TESTING "Build tests" ON)
option(CODE_COVERAGE "Build faker-cxx with coverage support" OFF)
Expand Down
37 changes: 19 additions & 18 deletions include/faker-cxx/word.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ namespace faker::word
* faker::word::sample(5) // "spell"
* @endcode
*/
FAKER_CXX_EXPORT std::string_view sample(std::optional<unsigned> length = std::nullopt,const faker::Locale locale = Locale::en_US);
FAKER_CXX_EXPORT std::string_view sample(std::optional<unsigned> length = std::nullopt,const Locale locale = Locale::en_US);


/**
Expand All @@ -44,7 +44,7 @@ FAKER_CXX_EXPORT std::string_view sample(std::optional<unsigned> length = std::n
* @endcode
*/

FAKER_CXX_EXPORT std::string_view sampleLocale(unsigned length = 0,const faker::Locale locale = Locale::en_US);
FAKER_CXX_EXPORT std::string_view sampleLocale(unsigned length = 0,const Locale locale = Locale::en_US);

/**
* @brief Returns a string containing a number of space separated random words.
Expand All @@ -59,7 +59,7 @@ FAKER_CXX_EXPORT std::string_view sampleLocale(unsigned length = 0,const faker::
* faker::word::words(5) // "before hourly patiently dribble equal"
* @endcode
*/
FAKER_CXX_EXPORT std::string words(unsigned numberOfWords = 1,const faker::Locale locale = Locale::en_US);
FAKER_CXX_EXPORT std::string words(unsigned numberOfWords = 1,const Locale locale = Locale::en_US);


/**
Expand All @@ -75,7 +75,7 @@ FAKER_CXX_EXPORT std::string words(unsigned numberOfWords = 1,const faker::Local
* faker::word::wordsLocale(5,faker::locale::en_US) // "before hourly patiently dribble equal"
* @endcode
*/
FAKER_CXX_EXPORT std::string wordsLocale(unsigned numberOfWords = 1,const faker::Locale locale = Locale::en_US);
FAKER_CXX_EXPORT std::string wordsLocale(unsigned numberOfWords = 1,const Locale locale = Locale::en_US);

/**
* @brief Returns a random adjective.
Expand All @@ -91,7 +91,7 @@ FAKER_CXX_EXPORT std::string wordsLocale(unsigned numberOfWords = 1,const faker:
* faker::word::adjective(3) // "bad"
* @endcode
*/
FAKER_CXX_EXPORT std::string_view adjective(std::optional<unsigned> length = std::nullopt,const faker::Locale locale = Locale::en_US);
FAKER_CXX_EXPORT std::string_view adjective(std::optional<unsigned> length = std::nullopt,const Locale locale = Locale::en_US);


/**
Expand All @@ -107,7 +107,7 @@ FAKER_CXX_EXPORT std::string_view adjective(std::optional<unsigned> length = std
* faker::word::adjective(3) // "bad"
* @endcode
*/
FAKER_CXX_EXPORT std::string_view adjectiveLocale(unsigned length = 0,const faker::Locale locale = Locale::en_US);
FAKER_CXX_EXPORT std::string_view adjectiveLocale(unsigned length = 0,const Locale locale = Locale::en_US);

/**
* @brief Returns a random adverb.
Expand All @@ -123,7 +123,8 @@ FAKER_CXX_EXPORT std::string_view adjectiveLocale(unsigned length = 0,const fake
* faker::word::adverb(5) // "almost"
* @endcode
*/
FAKER_CXX_EXPORT std::string_view adverb(std::optional<unsigned> length = std::nullopt,const faker::Locale locale = Locale::en_US);
FAKER_CXX_EXPORT std::string_view adverb(std::optional<unsigned> length = std::nullopt,const Locale locale = Locale::en_US);



/**
Expand All @@ -140,7 +141,7 @@ FAKER_CXX_EXPORT std::string_view adverb(std::optional<unsigned> length = std::n
* faker::word::adverbLocale(5) // "almost"
* @endcode
*/
FAKER_CXX_EXPORT std::string_view adverbLocale(unsigned length = 0,const faker::Locale locale = Locale::en_US);
FAKER_CXX_EXPORT std::string_view adverbLocale(unsigned length = 0,const Locale locale = Locale::en_US);

/**
* @brief Returns a random conjunction.
Expand All @@ -156,7 +157,7 @@ FAKER_CXX_EXPORT std::string_view adverbLocale(unsigned length = 0,const faker::
* faker::word::conjunction(6) // "indeed"
* @endcode
*/
FAKER_CXX_EXPORT std::string_view conjunction(std::optional<unsigned> length = std::nullopt,const faker::Locale locale = Locale::en_US);
FAKER_CXX_EXPORT std::string_view conjunction(std::optional<unsigned> length = std::nullopt,const Locale locale = Locale::en_US);



Expand All @@ -174,7 +175,7 @@ FAKER_CXX_EXPORT std::string_view conjunction(std::optional<unsigned> length = s
* faker::word::conjunctionLocale(6) // "indeed"
* @endcode
*/
FAKER_CXX_EXPORT std::string_view conjunctionLocale(unsigned int length=0, const faker::Locale locale = Locale::en_US);
FAKER_CXX_EXPORT std::string_view conjunctionLocale(unsigned int length=0, const Locale locale = Locale::en_US);


/**
Expand All @@ -191,7 +192,7 @@ FAKER_CXX_EXPORT std::string_view conjunctionLocale(unsigned int length=0, const
* faker::word::interjection(4) // "yuck"
* @endcode
*/
FAKER_CXX_EXPORT std::string_view interjection(std::optional<unsigned> length = std::nullopt,const faker::Locale locale = Locale::en_US);
FAKER_CXX_EXPORT std::string_view interjection(std::optional<unsigned> length = std::nullopt,const Locale locale = Locale::en_US);

/**
* @brief Returns a random interjection.
Expand All @@ -207,7 +208,7 @@ FAKER_CXX_EXPORT std::string_view interjection(std::optional<unsigned> length =
* faker::word::interjectionLocale(4) // "yuck"
* @endcode
*/
FAKER_CXX_EXPORT std::string_view interjectionLocale(unsigned int length=0, const faker::Locale locale = Locale::en_US) ;
FAKER_CXX_EXPORT std::string_view interjectionLocale(unsigned int length=0, const Locale locale = Locale::en_US) ;

/**
* @brief Returns a random noun.
Expand All @@ -223,7 +224,7 @@ FAKER_CXX_EXPORT std::string_view interjectionLocale(unsigned int length=0, con
* faker::word::noun(8) // "distance"
* @endcode
*/
FAKER_CXX_EXPORT std::string_view noun(std::optional<unsigned> length = std::nullopt,const faker::Locale locale = Locale::en_US);
FAKER_CXX_EXPORT std::string_view noun(std::optional<unsigned> length = std::nullopt,const Locale locale = Locale::en_US);


/**
Expand All @@ -240,7 +241,7 @@ FAKER_CXX_EXPORT std::string_view noun(std::optional<unsigned> length = std::nul
* faker::word::nounLocale(8) // "distance"
* @endcode
*/
FAKER_CXX_EXPORT std::string_view nounLocale(unsigned int length=0, const faker::Locale locale = Locale::en_US);
FAKER_CXX_EXPORT std::string_view nounLocale(unsigned int length=0, const Locale locale = Locale::en_US);

/**
* @brief Returns a random preposition.
Expand All @@ -256,7 +257,7 @@ FAKER_CXX_EXPORT std::string_view nounLocale(unsigned int length=0, const faker:
* faker::word::preposition(4) // "from"
* @endcode
*/
FAKER_CXX_EXPORT std::string_view preposition(std::optional<unsigned> length = std::nullopt,const faker::Locale locale = Locale::en_US);
FAKER_CXX_EXPORT std::string_view preposition(std::optional<unsigned> length = std::nullopt,const Locale locale = Locale::en_US);

/**
* @brief Returns a random preposition.
Expand All @@ -272,7 +273,7 @@ FAKER_CXX_EXPORT std::string_view preposition(std::optional<unsigned> length = s
* faker::word::prepositionLocale(4) // "from"
* @endcode
*/
FAKER_CXX_EXPORT std::string_view prepositionLocale(unsigned int length=0, const faker::Locale locale = Locale::en_US);
FAKER_CXX_EXPORT std::string_view prepositionLocale(unsigned int length=0, const Locale locale = Locale::en_US);

/**
* @brief Returns a random verb.
Expand All @@ -288,7 +289,7 @@ FAKER_CXX_EXPORT std::string_view prepositionLocale(unsigned int length=0, const
* faker::word::verb(9) // "stabilise"
* @endcode
*/
FAKER_CXX_EXPORT std::string_view verb(std::optional<unsigned> length = std::nullopt,const faker::Locale locale = Locale::en_US);
FAKER_CXX_EXPORT std::string_view verb(std::optional<unsigned> length = std::nullopt,const Locale locale = Locale::en_US);


/**
Expand All @@ -305,7 +306,7 @@ FAKER_CXX_EXPORT std::string_view verb(std::optional<unsigned> length = std::nul
* faker::word::verbLocale(9) // "stabilise"
* @endcode
*/
FAKER_CXX_EXPORT std::string_view verbLocale(unsigned int length=0, const faker::Locale locale = Locale::en_US);
FAKER_CXX_EXPORT std::string_view verbLocale(unsigned int length=0, const Locale locale = Locale::en_US);

/**
* @brief Returns random element of length
Expand Down
6 changes: 3 additions & 3 deletions src/modules/internet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -341,11 +341,11 @@ std::string anonymousUsername(unsigned maxLength)
else if (maxLength > defaultMax)
maxLength = defaultMax;

const std::integral auto adjectiveLocaleength = number::integer<unsigned>(3, 1 + maxLength / 2);
const std::integral auto adjectiveLength = number::integer<unsigned>(3, 1 + maxLength / 2);

const auto nounLocaleength = maxLength - adjectiveLocaleength;
const auto nounLength = maxLength - adjectiveLength;

return common::format("{}{}", word::adjective(adjectiveLocaleength), word::noun(nounLocaleength));
return common::format("{}{}", word::adjective(adjectiveLength), word::noun(nounLength));
}

}
Loading

0 comments on commit 0156b92

Please sign in to comment.