-
-
Notifications
You must be signed in to change notification settings - Fork 165
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
Refactor word module #610
Closed
Closed
Refactor word module #610
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,11 +2,25 @@ | |
|
||
#include <optional> | ||
#include <string> | ||
#include <vector> | ||
|
||
namespace faker | ||
{ | ||
class Word | ||
{ | ||
namespace faker { | ||
class Word { | ||
/** | ||
* @brief Creates a vector of all words. | ||
* | ||
* @returns Vector of all words. | ||
* | ||
* @code | ||
* Word::createAllWords() // ["aboard", "about", "above", "absent", "absorbed", "and" ...] | ||
* ^^^ all words (adjectives, adverbs, conjunctions ect.) ^^^ | ||
* @endcode | ||
* | ||
* @note This function is used internally, as a helper | ||
* and it is not intended to be used by the user. | ||
*/ | ||
static std::vector<std::string_view> createAllWords(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. move to cpp file, it is implementation detail - should not be in API file |
||
|
||
public: | ||
/** | ||
* @brief Returns a random word. | ||
|
@@ -21,7 +35,7 @@ class Word | |
* Word::sample(5) // "spell" | ||
* @endcode | ||
*/ | ||
static std::string sample(std::optional<unsigned> length = std::nullopt); | ||
static std::string_view sample(std::optional<unsigned> length = std::nullopt); | ||
|
||
/** | ||
* @brief Returns a string containing a number of space separated random words. | ||
|
@@ -35,7 +49,7 @@ class Word | |
* Word::words(5) // "before hourly patiently dribble equal" | ||
* @endcode | ||
*/ | ||
static std::string words(unsigned numberOfWords = 1); | ||
static std::string_view words(unsigned numberOfWords = 1); | ||
|
||
/** | ||
* @brief Returns a random adjective. | ||
|
@@ -50,7 +64,7 @@ class Word | |
* Word::adjective(3) // "bad" | ||
* @endcode | ||
*/ | ||
static std::string adjective(std::optional<unsigned> length = std::nullopt); | ||
static std::string_view adjective(std::optional<unsigned> length = std::nullopt); | ||
|
||
/** | ||
* @brief Returns a random adverb. | ||
|
@@ -65,7 +79,7 @@ class Word | |
* Word::adverb(5) // "almost" | ||
* @endcode | ||
*/ | ||
static std::string adverb(std::optional<unsigned> length = std::nullopt); | ||
static std::string_view adverb(std::optional<unsigned> length = std::nullopt); | ||
|
||
/** | ||
* @brief Returns a random conjunction. | ||
|
@@ -80,7 +94,7 @@ class Word | |
* Word::conjunction(6) // "indeed" | ||
* @endcode | ||
*/ | ||
static std::string conjunction(std::optional<unsigned> length = std::nullopt); | ||
static std::string_view conjunction(std::optional<unsigned> length = std::nullopt); | ||
|
||
/** | ||
* @brief Returns a random interjection. | ||
|
@@ -95,7 +109,7 @@ class Word | |
* Word::interjection(4) // "yuck" | ||
* @endcode | ||
*/ | ||
static std::string interjection(std::optional<unsigned> length = std::nullopt); | ||
static std::string_view interjection(std::optional<unsigned> length = std::nullopt); | ||
|
||
/** | ||
* @brief Returns a random noun. | ||
|
@@ -110,7 +124,7 @@ class Word | |
* Word::noun(8) // "distance" | ||
* @endcode | ||
*/ | ||
static std::string noun(std::optional<unsigned> length = std::nullopt); | ||
static std::string_view noun(std::optional<unsigned> length = std::nullopt); | ||
|
||
/** | ||
* @brief Returns a random preposition. | ||
|
@@ -125,7 +139,7 @@ class Word | |
* Word::preposition(4) // "from" | ||
* @endcode | ||
*/ | ||
static std::string preposition(std::optional<unsigned> length = std::nullopt); | ||
static std::string_view preposition(std::optional<unsigned> length = std::nullopt); | ||
|
||
/** | ||
* @brief Returns a random verb. | ||
|
@@ -140,6 +154,6 @@ class Word | |
* Word::verb(9) // "stabilise" | ||
* @endcode | ||
*/ | ||
static std::string verb(std::optional<unsigned> length = std::nullopt); | ||
static std::string_view verb(std::optional<unsigned> length = std::nullopt); | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,7 +42,7 @@ std::string extension(const std::string& mimeType) | |
|
||
std::string System::fileName(const FileOptions& options) | ||
{ | ||
std::string baseName = Word::words(); | ||
std::string baseName = std::string(Word::words()); // Konwersja std::string_view na std::string | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remove comment |
||
std::string extensionsStr; | ||
|
||
if (options.extensionCount > 0) | ||
|
@@ -75,6 +75,7 @@ std::string System::fileName(const FileOptions& options) | |
return baseName + extensionsStr; | ||
} | ||
|
||
|
||
std::string System::fileExtension(const std::optional<FileType>& mimeType) | ||
{ | ||
if (mimeType.has_value()) | ||
|
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
source file name should start with upper case - WordData.cpp