Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: adding locale to word module #932

Merged
merged 35 commits into from
Oct 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
c2bf42a
generating a new adjetive signature for adding information of locale
gustavobastian Sep 26, 2024
0e5758c
adding more tables
gustavobastian Sep 28, 2024
f84570d
adding new function wordsL
gustavobastian Sep 28, 2024
8dded88
adding more words to data
gustavobastian Sep 28, 2024
39bc77d
change functions names, fixing test not passing
gustavobastian Sep 30, 2024
7982e94
adding check if locale is in map or not
gustavobastian Sep 30, 2024
ef6b2bf
signature for functions
gustavobastian Sep 30, 2024
9377561
generating all test
gustavobastian Sep 30, 2024
134b862
using en_US words structure for general functions
gustavobastian Sep 30, 2024
27377b3
Merge branch 'cieslarmichal:main' into feature/word-locale
gustavobastian Sep 30, 2024
f8ae4f1
using span for main structures of data
gustavobastian Sep 30, 2024
a984912
adding portuguese words
gustavobastian Oct 1, 2024
b638f37
adding french words
gustavobastian Oct 1, 2024
7faea51
adding test
gustavobastian Oct 1, 2024
34b503d
Merge branch 'cieslarmichal:main' into feature/word-locale
gustavobastian Oct 1, 2024
05859a1
Merge branch 'feature/word-locale' of github.com:gustavobastian/faker…
gustavobastian Oct 1, 2024
988cef0
modify changelog
gustavobastian Oct 1, 2024
808f1f4
Merge pull request #1 from gustavobastian/feature/word-locale
gustavobastian Oct 1, 2024
af7f3e3
adding parametrized test
gustavobastian Oct 1, 2024
c6f0618
fixing use fmt and GTest from System
gustavobastian Oct 1, 2024
d3b9a60
spelling
gustavobastian Oct 2, 2024
07ad1ef
reverting modification in internet.cpp
gustavobastian Oct 2, 2024
ae09226
spell correction
gustavobastian Oct 2, 2024
a0782c7
using correct function in test
gustavobastian Oct 2, 2024
df3043f
check if the locale is defined using idiomsMapSpan structure, if not …
gustavobastian Oct 2, 2024
0156b92
Merge pull request #2 from gustavobastian/feature/word-locale
gustavobastian Oct 2, 2024
55469e0
unsing auto in parameterized tests
gustavobastian Oct 2, 2024
de4c2ee
change functions descriptions
gustavobastian Oct 2, 2024
760d1be
removing duplicate functions
gustavobastian Oct 2, 2024
80ea7d0
removing extre newlines in tests
gustavobastian Oct 2, 2024
bee73c2
Merge pull request #3 from gustavobastian/feature/word-locale
gustavobastian Oct 2, 2024
6b918ab
adding const in test values.
gustavobastian Oct 2, 2024
bb7cf04
Merge pull request #4 from gustavobastian/feature/word-locale
gustavobastian Oct 2, 2024
7be658f
removing option in words with (length<=256), and s capture the datase…
gustavobastian Oct 3, 2024
c9c8a76
Merge pull request #5 from gustavobastian/feature/word-locale
gustavobastian Oct 3, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ All notable changes to this project will be documented in this file
* added locale to `weather` module
* added locale to `color` module
* added locale to `vehicle` module
* added locale to `word` module

## v3.0.0 (28.08.2024)

Expand Down
76 changes: 58 additions & 18 deletions include/faker-cxx/word.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,17 @@
#include "faker-cxx/export.h"
#include "faker-cxx/helper.h"

#include "faker-cxx/types/locale.h"

namespace faker::word
{

/**
* @brief Returns a random .
*
* @param length The expected length of the .
* If no with given length will be found, it will return a random .
* If no word with given length will be found or length is 0, it will return a random size word.
* @param locale The locale. Defaults to `Locale::en_US`.
*
* @returns Random sample word.
*
Expand All @@ -23,12 +27,13 @@ namespace faker::word
* faker::word::sample(5) // "spell"
* @endcode
*/
FAKER_CXX_EXPORT std::string_view sample(std::optional<unsigned> length = std::nullopt);
FAKER_CXX_EXPORT std::string_view sample(std::optional<unsigned> length = std::nullopt,const Locale locale = Locale::en_US);

/**
* @brief Returns a string containing a number of space separated random words.
*
* @param numberOfWords The number of words to generate.
* @param locale The locale. Defaults to `Locale::en_US`.
*
* @returns Random words separated with spaces.
*
Expand All @@ -37,13 +42,16 @@ FAKER_CXX_EXPORT std::string_view sample(std::optional<unsigned> length = std::n
* faker::word::words(5) // "before hourly patiently dribble equal"
* @endcode
*/
FAKER_CXX_EXPORT std::string words(unsigned numberOfWords = 1);
FAKER_CXX_EXPORT std::string words(unsigned numberOfWords = 1,const Locale locale = Locale::en_US);



/**
* @brief Returns a random adjective.
*
* @param length The expected length of the word.
* If no word with given length will be found, it will return a random word.
* If no adjective with given length will be found or length is 0, it will return a random size adjective.
* @param locale The locale. Defaults to `Locale::en_US`.
*
* @returns Adjective.
*
Expand All @@ -52,13 +60,31 @@ FAKER_CXX_EXPORT std::string words(unsigned numberOfWords = 1);
* faker::word::adjective(3) // "bad"
* @endcode
*/
FAKER_CXX_EXPORT std::string_view adjective(std::optional<unsigned> length = std::nullopt);
FAKER_CXX_EXPORT std::string_view adjective(std::optional<unsigned> length = std::nullopt,const Locale locale = Locale::en_US);


/**
* @brief Returns a random adjective, using locale.
*
* @param length The expected length of the word.
* If no adjective with given length will be found or length is 0, it will return a random size adjective.
* @param locale The locale. Defaults to `Locale::en_US`.
*
* @returns Adjective.
*
* @code
* faker::word::adjective() // "complete"
* faker::word::adjective(3) // "bad"
* @endcode
*/
FAKER_CXX_EXPORT std::string_view adjectiveLocale(unsigned length = 0,const Locale locale = Locale::en_US);

/**
* @brief Returns a random adverb.
*
* @param length The expected length of the word.
* If no word with given length will be found, it will return a random word.
* If no adverb with given length will be found or length is 0, it will return a random size adverb.
* @param locale The locale. Defaults to `Locale::en_US`.
*
* @returns Adverb.
*
Expand All @@ -67,13 +93,15 @@ FAKER_CXX_EXPORT std::string_view adjective(std::optional<unsigned> length = std
* faker::word::adverb(5) // "almost"
* @endcode
*/
FAKER_CXX_EXPORT std::string_view adverb(std::optional<unsigned> length = std::nullopt);
FAKER_CXX_EXPORT std::string_view adverb(std::optional<unsigned> length = std::nullopt,const Locale locale = Locale::en_US);


/**
* @brief Returns a random conjunction.
*
* @param length The expected length of the word.
* If no word with given length will be found, it will return a random word.
* @param length The expected length of the word.
* If no conjunction with given length will be found or length is 0, it will return a random size conjunction.
* @param locale The locale. Defaults to `Locale::en_US`.
*
* @returns Conjunction.
*
Expand All @@ -82,13 +110,16 @@ FAKER_CXX_EXPORT std::string_view adverb(std::optional<unsigned> length = std::n
* faker::word::conjunction(6) // "indeed"
* @endcode
*/
FAKER_CXX_EXPORT std::string_view conjunction(std::optional<unsigned> length = std::nullopt);
FAKER_CXX_EXPORT std::string_view conjunction(std::optional<unsigned> length = std::nullopt,const Locale locale = Locale::en_US);



/**
* @brief Returns a random interjection.
*
* @param length The expected length of the word.
* If no word with given length will be found, it will return a random word.
* If no interjection with given length is found or length is 0, it will return a random size interjection.
* @param locale The locale. Defaults to `Locale::en_US`.
*
* @returns Interjection.
*
Expand All @@ -97,13 +128,16 @@ FAKER_CXX_EXPORT std::string_view conjunction(std::optional<unsigned> length = s
* faker::word::interjection(4) // "yuck"
* @endcode
*/
FAKER_CXX_EXPORT std::string_view interjection(std::optional<unsigned> length = std::nullopt);
FAKER_CXX_EXPORT std::string_view interjection(std::optional<unsigned> length = std::nullopt,const Locale locale = Locale::en_US);



/**
* @brief Returns a random noun.
*
* @param length The expected length of the word.
* If no word with given length will be found, it will return a random word.
* If no noun with given length is found or length is 0, it will return a random size noun.
* @param locale The locale. Defaults to `Locale::en_US`.
*
* @returns Noun.
*
Expand All @@ -112,13 +146,15 @@ FAKER_CXX_EXPORT std::string_view interjection(std::optional<unsigned> length =
* faker::word::noun(8) // "distance"
* @endcode
*/
FAKER_CXX_EXPORT std::string_view noun(std::optional<unsigned> length = std::nullopt);
FAKER_CXX_EXPORT std::string_view noun(std::optional<unsigned> length = std::nullopt,const Locale locale = Locale::en_US);


/**
* @brief Returns a random preposition.
*
* @param length The expected length of the word.
* If no word with given length will be found, it will return a random word.
* If no preposition with given length is found or length is 0, it will return a random size preposition.
* @param locale The locale. Defaults to `Locale::en_US`.
*
* @returns Preposition.
*
Expand All @@ -127,13 +163,15 @@ FAKER_CXX_EXPORT std::string_view noun(std::optional<unsigned> length = std::nul
* faker::word::preposition(4) // "from"
* @endcode
*/
FAKER_CXX_EXPORT std::string_view preposition(std::optional<unsigned> length = std::nullopt);
FAKER_CXX_EXPORT std::string_view preposition(std::optional<unsigned> length = std::nullopt,const Locale locale = Locale::en_US);


/**
* @brief Returns a random verb.
*
* @param length The expected length of the word.
* If no word with given length will be found, it will return a random word.
* If no verb with given length is found or length is 0, it will return a random size verb.
* @param locale The locale. Defaults to `Locale::en_US`.
*
* @returns Verb.
*
Expand All @@ -142,12 +180,14 @@ FAKER_CXX_EXPORT std::string_view preposition(std::optional<unsigned> length = s
* faker::word::verb(9) // "stabilise"
* @endcode
*/
FAKER_CXX_EXPORT std::string_view verb(std::optional<unsigned> length = std::nullopt);
FAKER_CXX_EXPORT std::string_view verb(std::optional<unsigned> length = std::nullopt,const Locale locale = Locale::en_US);


/**
* @brief Returns random element of length
*
* @param length The length of the elements to be picked from
* @param locale The locale. Defaults to `Locale::en_US`.
*
* @ range The range of elements
*
Expand Down
Loading
Loading