Skip to content

Commit

Permalink
Refactored word (#692)
Browse files Browse the repository at this point in the history
* Refactored word

* made namespace lowercase
  • Loading branch information
eric-bodhi authored Jun 17, 2024
1 parent df8b5d8 commit 9ed1453
Show file tree
Hide file tree
Showing 19 changed files with 195 additions and 197 deletions.
2 changes: 1 addition & 1 deletion include/faker-cxx/Crypto.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class Crypto
*
* @code
* Crypto::sha256("hello world") // "b94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9"
* Crypto::sha256() // Random hash of random word
* Crypto::sha256() // Random hash of random
* @endcode
*/
static std::string sha256(std::optional<std::string> = std::nullopt);
Expand Down
256 changes: 126 additions & 130 deletions include/faker-cxx/Word.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,143 +4,139 @@
#include <string>
#include <string_view>

namespace faker
namespace faker::word
{
class Word
{
public:
/**
* @brief Returns a random word.
*
* @param length The expected length of the word.
* If no word with given length will be found, it will return a random word.
*
* @returns Random sample word.
*
* @code
* Word::sample() // "protection"
* Word::sample(5) // "spell"
* @endcode
*/
static std::string_view sample(std::optional<unsigned> length = std::nullopt);
/**
* @brief Returns a random .
*
* @param length The expected length of the .
* If no with given length will be found, it will return a random .
*
* @returns Random sample word.
*
* @code
* word::sample() // "protection"
* word::sample(5) // "spell"
* @endcode
*/
std::string_view sample(std::optional<unsigned> length = std::nullopt);

/**
* @brief Returns a string containing a number of space separated random words.
*
* @param numberOfWords The number of words to generate.
*
* @returns Random words separated with spaces.
*
* @code
* Word::words() // "protection"
* Word::words(5) // "before hourly patiently dribble equal"
* @endcode
*/
static std::string words(unsigned numberOfWords = 1);
/**
* @brief Returns a string containing a number of space separated random words.
*
* @param numberOfWords The number of words to generate.
*
* @returns Random words separated with spaces.
*
* @code
* word::words() // "protection"
* word::words(5) // "before hourly patiently dribble equal"
* @endcode
*/
std::string words(unsigned numberOfWords = 1);

/**
* @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.
*
* @returns Adjective.
*
* @code
* Word::adjective() // "complete"
* Word::adjective(3) // "bad"
* @endcode
*/
static std::string_view adjective(std::optional<unsigned> length = std::nullopt);
/**
* @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.
*
* @returns Adjective.
*
* @code
* word::adjective() // "complete"
* word::adjective(3) // "bad"
* @endcode
*/
std::string_view adjective(std::optional<unsigned> length = std::nullopt);

/**
* @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.
*
* @returns Adverb.
*
* @code
* Word::adverb() // "deliberately"
* Word::adverb(5) // "almost"
* @endcode
*/
static std::string_view adverb(std::optional<unsigned> length = std::nullopt);
/**
* @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.
*
* @returns Adverb.
*
* @code
* word::adverb() // "deliberately"
* word::adverb(5) // "almost"
* @endcode
*/
std::string_view adverb(std::optional<unsigned> length = std::nullopt);

/**
* @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.
*
* @returns Conjunction.
*
* @code
* Word::conjunction() // "because"
* Word::conjunction(6) // "indeed"
* @endcode
*/
static std::string_view conjunction(std::optional<unsigned> length = std::nullopt);
/**
* @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.
*
* @returns Conjunction.
*
* @code
* word::conjunction() // "because"
* word::conjunction(6) // "indeed"
* @endcode
*/
std::string_view conjunction(std::optional<unsigned> length = std::nullopt);

/**
* @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.
*
* @returns Interjection.
*
* @code
* Word::interjection() // "psst"
* Word::interjection(4) // "yuck"
* @endcode
*/
static std::string_view interjection(std::optional<unsigned> length = std::nullopt);
/**
* @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.
*
* @returns Interjection.
*
* @code
* word::interjection() // "psst"
* word::interjection(4) // "yuck"
* @endcode
*/
std::string_view interjection(std::optional<unsigned> length = std::nullopt);

/**
* @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.
*
* @returns Noun.
*
* @code
* Word::noun() // "pudding"
* Word::noun(8) // "distance"
* @endcode
*/
static std::string_view noun(std::optional<unsigned> length = std::nullopt);
/**
* @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.
*
* @returns Noun.
*
* @code
* word::noun() // "pudding"
* word::noun(8) // "distance"
* @endcode
*/
std::string_view noun(std::optional<unsigned> length = std::nullopt);

/**
* @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.
*
* @returns Preposition.
*
* @code
* Word::preposition() // "besides"
* Word::preposition(4) // "from"
* @endcode
*/
static std::string_view preposition(std::optional<unsigned> length = std::nullopt);
/**
* @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.
*
* @returns Preposition.
*
* @code
* word::preposition() // "besides"
* word::preposition(4) // "from"
* @endcode
*/
std::string_view preposition(std::optional<unsigned> length = std::nullopt);

/**
* @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.
*
* @returns Verb.
*
* @code
* Word::verb() // "override"
* Word::verb(9) // "stabilise"
* @endcode
*/
static std::string_view verb(std::optional<unsigned> length = std::nullopt);
};
/**
* @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.
*
* @returns Verb.
*
* @code
* word::verb() // "override"
* word::verb(9) // "stabilise"
* @endcode
*/
std::string_view verb(std::optional<unsigned> length = std::nullopt);
}
4 changes: 2 additions & 2 deletions src/modules/crypto/Crypto.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ std::string Crypto::sha256(std::optional<std::string> data)
std::string orgData;
if (!data.has_value() || data->empty())
{
orgData = Word::sample();
orgData = word::sample();
}
else
{
Expand All @@ -126,7 +126,7 @@ std::string Crypto::md5(std::optional<std::string> data)
std::string orgData;
if (!data.has_value() || data->empty())
{
orgData = Word::sample();
orgData = word::sample();
}
else
{
Expand Down
16 changes: 8 additions & 8 deletions src/modules/git/Git.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ std::string Git::branch(unsigned maxIssueNum)
switch (Number::integer(1, 3))
{
case 1:
return FormatHelper::format("{}-{}", Word::verb(), Word::noun());
return FormatHelper::format("{}-{}", word::verb(), word::noun());
case 2:
return FormatHelper::format("{}-{}-{}", Word::verb(), Word::adjective(), Word::noun());
return FormatHelper::format("{}-{}-{}", word::verb(), word::adjective(), word::noun());
default:
return FormatHelper::format("{}-{}-{}-{}", Number::integer(unsigned(1), maxIssueNum), Word::verb(),
Word::adjective(), Word::noun());
return FormatHelper::format("{}-{}-{}-{}", Number::integer(unsigned(1), maxIssueNum), word::verb(),
word::adjective(), word::noun());
}
}

Expand Down Expand Up @@ -114,13 +114,13 @@ std::string Git::commitMessage()
switch (Number::integer(1, 4))
{
case 1:
return FormatHelper::format("{} {}", Word::verb(), Word::noun());
return FormatHelper::format("{} {}", word::verb(), word::noun());
case 2:
return FormatHelper::format("{} {} {}", Word::verb(), Word::adjective(), Word::noun());
return FormatHelper::format("{} {} {}", word::verb(), word::adjective(), word::noun());
case 3:
return FormatHelper::format("{} {} {}", Word::verb(), Word::noun(), Word::adverb());
return FormatHelper::format("{} {} {}", word::verb(), word::noun(), word::adverb());
default:
return FormatHelper::format("{} {} {} {}", Word::verb(), Word::adjective(), Word::noun(), Word::adverb());
return FormatHelper::format("{} {} {} {}", word::verb(), word::adjective(), word::noun(), word::adverb());
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/modules/internet/Internet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ std::string Internet::domainName()

std::string Internet::domainWord()
{
return StringHelper::toLower(FormatHelper::format("{}-{}", Word::adjective(), Word::noun()));
return StringHelper::toLower(FormatHelper::format("{}-{}", word::adjective(), word::noun()));
}

std::string_view Internet::domainSuffix()
Expand All @@ -350,7 +350,7 @@ std::string Internet::anonymousUsername(unsigned maxLength)

const auto nounLength = maxLength - adjectiveLength;

return FormatHelper::format("{}{}", Word::adjective(adjectiveLength), Word::noun(nounLength));
return FormatHelper::format("{}{}", word::adjective(adjectiveLength), word::noun(nounLength));
}

}
2 changes: 1 addition & 1 deletion src/modules/person/Person.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ std::string Person::bio()
const std::unordered_map<std::string_view, std::function<std::string_view()>> dataGeneratorsMapping{
{"bio_part", []() { return Helper::arrayElement(bioParts); }},
{"bio_supporter", []() { return Helper::arrayElement(bioSupporters); }},
{"noun", []() { return Word::noun(); }},
{"noun", []() { return word::noun(); }},
{"emoji", []() { return Internet::emoji(); }}};

return FormatHelper::fillTokenValues(randomBioFormat, dataGeneratorsMapping);
Expand Down
2 changes: 1 addition & 1 deletion src/modules/system/System.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ std::string_view extension(std::string_view mimeType)

std::string System::fileName(const FileOptions& options)
{
std::string baseName = Word::words();
std::string baseName = word::words();
std::string extensionsStr;

if (options.extensionCount > 0)
Expand Down
Loading

0 comments on commit 9ed1453

Please sign in to comment.