-
-
Notifications
You must be signed in to change notification settings - Fork 165
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Bio function to Person Module (#373)
* Add bioPart std::vector * Adjust bio vector * Add bio() method to the Person class * Add bioSupporter and bioFormats vector * Add bio() method implementation * Add test for the Person bio * Add BioHelper to check if the bio generated is valid * Add method to the Internet class to check if an emoji is valid * Implement BioHelper::checkTokenFormat() * Add missing includes * Adjust regex expressions * Add comment to checkIfEmojiIsValid() method * Adjust regex matching * Delete useless std::cout * Format code
- Loading branch information
1 parent
99171ea
commit 1003827
Showing
13 changed files
with
279 additions
and
25 deletions.
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
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
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 |
---|---|---|
@@ -0,0 +1,102 @@ | ||
#include "BioHelper.h" | ||
|
||
#include "../../include/faker-cxx/Internet.h" | ||
#include "../../src/modules/person/data/Bio.h" | ||
#include "../../src/modules/word/data/Nouns.h" | ||
|
||
namespace faker | ||
{ | ||
bool BioHelper::checkTokenFormat(const std::string& bio) | ||
{ | ||
|
||
const std::regex firstRegex{R"(^[a-zA-Z0-9_]+$)"}; | ||
const std::regex secondRegex{R"(^(\w+\s?\w+), (\w+\s?\w+)$)"}; | ||
const std::regex thirdRegex{R"(^(\w+\s?\w+), (\w+\s?\w+), (\w+\s?\w+)$)"}; | ||
const std::regex fourthRegex{R"(^(\w+\s?\w+), (\w+\s?\w+), (\w+\s?\w+), (\S+)$)"}; | ||
const std::regex fifthRegex{R"(^(\w+) (\w+)$)"}; | ||
const std::regex sixthRegex{R"(^(\w+) (\w+) (\S+)$)"}; | ||
const std::regex seventhRegex{R"(^(\w+) (\w+), (\w+\s?\w+)$)"}; | ||
const std::regex eigthRegex{R"(^(\w+) (\w+), (\w+\s?\w+) (\S+)$)"}; | ||
|
||
std::smatch matches; | ||
// | ||
if (std::regex_match(bio, matches, firstRegex)) | ||
{ | ||
// In this case the bio is in the format {bio_part} so check that the value is present in the bio_part vector. | ||
if (std::find(bioPart.begin(), bioPart.end(), matches[0]) != bioPart.end()) | ||
return true; | ||
} | ||
|
||
if (std::regex_match(bio, matches, secondRegex)) | ||
{ | ||
// In this case the bio is in the format {bio_part}, {bio_part} so check that the value is present in the | ||
// bio_part vector. | ||
if (std::find(bioPart.begin(), bioPart.end(), matches[1]) != bioPart.end() && | ||
std::find(bioPart.begin(), bioPart.end(), matches[2]) != bioPart.end()) | ||
return true; | ||
} | ||
|
||
if (std::regex_match(bio, matches, thirdRegex)) | ||
{ | ||
// In this case the bio is in the format {bio_part}, {bio_part}, {bio_part} so check that the value is present | ||
// in the bio_part vector. | ||
if (std::find(bioPart.begin(), bioPart.end(), matches[1]) != bioPart.end() && | ||
std::find(bioPart.begin(), bioPart.end(), matches[2]) != bioPart.end() && | ||
std::find(bioPart.begin(), bioPart.end(), matches[3]) != bioPart.end()) | ||
return true; | ||
} | ||
|
||
if (std::regex_match(bio, matches, fourthRegex)) | ||
{ | ||
// In this case the bio is in the format {bio_part}, {bio_part}, {bio_part}, {emoji} so check that the value is | ||
// present in the bio_part vector. | ||
if (std::find(bioPart.begin(), bioPart.end(), matches[1]) != bioPart.end() && | ||
std::find(bioPart.begin(), bioPart.end(), matches[2]) != bioPart.end() && | ||
std::find(bioPart.begin(), bioPart.end(), matches[3]) != bioPart.end() && | ||
Internet::checkIfEmojiIsValid(matches[4])) | ||
return true; | ||
} | ||
|
||
if (std::regex_match(bio, matches, fifthRegex)) | ||
{ | ||
// In this case the bio is in the format {noun} {bio_supporter} so check that the value is present | ||
// in the bio_part vector. | ||
if (std::find(nouns.begin(), nouns.end(), matches[1]) != nouns.end() && | ||
std::find(bioSupporter.begin(), bioSupporter.end(), matches[2]) != bioSupporter.end()) | ||
return true; | ||
} | ||
|
||
if (std::regex_match(bio, matches, sixthRegex)) | ||
{ | ||
// In this case the bio is in the format {noun} {bio_supporter} {emoji} so check that the value is present | ||
// in the bio_part vector. | ||
if (std::find(nouns.begin(), nouns.end(), matches[1]) != nouns.end() && | ||
std::find(bioSupporter.begin(), bioSupporter.end(), matches[2]) != bioSupporter.end() && | ||
Internet::checkIfEmojiIsValid(matches[3])) | ||
return true; | ||
} | ||
|
||
if (std::regex_match(bio, matches, seventhRegex)) | ||
{ | ||
// In this case the bio is in the format {noun} {bio_supporter}, {bio_part} so check that the value is present | ||
// in the bio_part vector. | ||
if (std::find(nouns.begin(), nouns.end(), matches[1]) != nouns.end() && | ||
std::find(bioSupporter.begin(), bioSupporter.end(), matches[2]) != bioSupporter.end() && | ||
std::find(bioPart.begin(), bioPart.end(), matches[3]) != bioPart.end()) | ||
return true; | ||
} | ||
|
||
if (std::regex_match(bio, matches, eigthRegex)) | ||
{ | ||
// In this case the bio is in the format {noun} {bio_supporter}, {bio_part} {emoji} so check that the value is | ||
// present in the bio_part vector. | ||
if (std::find(nouns.begin(), nouns.end(), matches[1]) != nouns.end() && | ||
std::find(bioSupporter.begin(), bioSupporter.end(), matches[2]) != bioSupporter.end() && | ||
std::find(bioPart.begin(), bioPart.end(), matches[3]) != bioPart.end() && | ||
Internet::checkIfEmojiIsValid(matches[4])) | ||
return true; | ||
} | ||
|
||
return false; | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#pragma once | ||
|
||
#include <functional> | ||
#include <map> | ||
#include <regex> | ||
#include <string> | ||
#include <vector> | ||
|
||
namespace faker | ||
{ | ||
class BioHelper | ||
{ | ||
public: | ||
static bool checkTokenFormat(const std::string& bio); | ||
}; | ||
} |
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
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
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
Oops, something went wrong.