Skip to content

Commit

Permalink
refactor person module data (#627)
Browse files Browse the repository at this point in the history
* refactor person module data

* reformat code
  • Loading branch information
cieslarmichal authored Jun 2, 2024
1 parent e599ef4 commit 63471ee
Show file tree
Hide file tree
Showing 285 changed files with 15,579 additions and 34,389 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ set(FAKER_SOURCES
src/modules/music/MusicData.cpp
src/modules/number/Number.cpp
src/modules/person/Person.cpp
src/modules/person/PersonData.cpp
src/modules/phone/Phone.cpp
src/modules/phone/PhoneData.cpp
src/modules/science/Science.cpp
Expand Down
7 changes: 4 additions & 3 deletions include/faker-cxx/Helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

#include <algorithm>
#include <functional>
#include <initializer_list>
#include <numeric>
#include <set>
#include <span>
#include <string>
#include <vector>
#include <initializer_list>

#include "Datatype.h"
#include "Number.h"
Expand Down Expand Up @@ -300,8 +300,9 @@ class Helper
* Helper::toVector(std::array<int, 3>{1, 2, 3}) // {1, 2, 3}
* @endcode
*/
template<typename T, std::size_t N>
static std::vector<T> toVector(const std::array<T, N>& arr) {
template <typename T, std::size_t N>
static std::vector<T> toVector(const std::array<T, N>& arr)
{
std::vector<T> vec;
vec.reserve(N);
vec.insert(vec.end(), arr.begin(), arr.end());
Expand Down
42 changes: 24 additions & 18 deletions include/faker-cxx/Person.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#pragma once

#include <optional>
#include <string>
#include <string_view>

#include "types/Country.h"

Expand Down Expand Up @@ -29,7 +29,8 @@ class Person
* Person::firstName(Country::England, Sex::Male) // "Arthur"
* @endcode
*/
static std::string firstName(std::optional<Country> country = std::nullopt, std::optional<Sex> sex = std::nullopt);
static std::string_view firstName(std::optional<Country> country = std::nullopt,
std::optional<Sex> sex = std::nullopt);

/**
* @brief Returns a random last name.
Expand All @@ -43,11 +44,13 @@ class Person
* Person::lastName() // "Peterson"
* @endcode
*/
static std::string lastName(std::optional<Country> country = std::nullopt, std::optional<Sex> sex = std::nullopt);
static std::string_view lastName(std::optional<Country> country = std::nullopt,
std::optional<Sex> sex = std::nullopt);

/**
* @brief Returns a random middle name.
*
* @param country The local country. Defaults to `Country::England`.
* @param sex The optional sex to use.
*
* @returns Middle name starting with a capital letter.
Expand All @@ -56,7 +59,8 @@ class Person
* Person::middleName() // "Васильевич"
* @endcode
*/
static std::string middleName(std::optional<Sex> sex = std::nullopt);
static std::string_view middleName(std::optional<Country> country = std::nullopt,
std::optional<Sex> sex = std::nullopt);

/**
* @brief Returns a random full name.
Expand Down Expand Up @@ -87,7 +91,8 @@ class Person
* Person::prefix(Sex::Male) // "Mr."
* @endcode
*/
static std::string prefix(std::optional<Sex> sex = std::nullopt);
static std::string_view prefix(std::optional<Country> countryOpt = std::nullopt,
std::optional<Sex> sex = std::nullopt);

/**
* @brief Returns a random name suffix.
Expand All @@ -98,7 +103,8 @@ class Person
* Person::suffix() // "Jr."
* @endcode
*/
static std::string suffix();
static std::string_view suffix(std::optional<Country> countryOpt = std::nullopt,
std::optional<Sex> sex = std::nullopt);

/**
* @brief Returns a random bio.
Expand All @@ -120,7 +126,7 @@ class Person
* Person::sex() // "Male"
* @endcode
*/
static std::string sex(std::optional<Language> language = std::nullopt);
static std::string_view sex(std::optional<Language> language = std::nullopt);

/**
* @brief Returns a random gender.
Expand All @@ -131,7 +137,7 @@ class Person
* Person::gender() // "Transexual woman"
* @endcode
*/
static std::string gender();
static std::string_view gender();

/**
* @brief Returns a random job title.
Expand All @@ -153,7 +159,7 @@ class Person
* Person::jobDescriptor() // "Senior"
* @endcode
*/
static std::string jobDescriptor();
static std::string_view jobDescriptor();

/**
* @brief Returns a random job area.
Expand All @@ -164,7 +170,7 @@ class Person
* Person::jobArea() // "Software"
* @endcode
*/
static std::string jobArea();
static std::string_view jobArea();

/**
* @brief Returns a random job type.
Expand All @@ -175,7 +181,7 @@ class Person
* Person::jobType() // "Engineer"
* @endcode
*/
static std::string jobType();
static std::string_view jobType();

/**
* @brief Returns a random hobby.
Expand All @@ -186,7 +192,7 @@ class Person
* Person::hobby() // "Gaming"
* @endcode
*/
static std::string hobby();
static std::string_view hobby();

/**
* @brief Returns a random language.
Expand All @@ -197,7 +203,7 @@ class Person
* Person::language() // "Polish"
* @endcode
*/
static std::string language();
static std::string_view language();

/**
* @brief Returns a random nationality.
Expand All @@ -208,7 +214,7 @@ class Person
* Person::nationality() // "Romanian"
* @endcode
*/
static std::string nationality();
static std::string_view nationality();

/**
* @brief Returns a random SSN.
Expand All @@ -233,7 +239,7 @@ class Person
* Person::westernZodiac() // "Virgo"
* @endcode
*/
static std::string westernZodiac();
static std::string_view westernZodiac();

/**
* @brief Returns a random Chinese Zodiac
Expand All @@ -244,7 +250,7 @@ class Person
* Person::chineseZodiac() // "Dragon"
* @endcode
*/
static std::string chineseZodiac();
static std::string_view chineseZodiac();

/**
* @brief Returns a random passport number from a given country
Expand Down Expand Up @@ -275,8 +281,8 @@ enum class Sex
enum class SsnCountry
{
Poland,
UnitedStates,
UnitedKingdom,
Usa,
England,
Germany,
France,
Italy,
Expand Down
2 changes: 1 addition & 1 deletion include/faker-cxx/Phone.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#pragma once

#include <optional>
#include <string_view>
#include <string>
#include <string_view>
#include <unordered_map>

namespace faker
Expand Down
2 changes: 1 addition & 1 deletion include/faker-cxx/String.h
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#pragma once

#include <limits>
#include <map>
#include <optional>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <map>

#include "RandomGenerator.h"
#include "types/Hex.h"
Expand Down
1 change: 0 additions & 1 deletion include/faker-cxx/types/Country.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,5 @@ enum class Country
Ghana,
Kazakhstan,
Maldives,
Liechtenstein,
};
}
2 changes: 1 addition & 1 deletion src/modules/animal/Animal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ std::string_view Animal::cow()

std::string_view Animal::crocodile()
{
return Helper::arrayElement(faker::crocodiles);
return Helper::arrayElement(crocodiles);
}

std::string_view Animal::dog()
Expand Down
48 changes: 24 additions & 24 deletions src/modules/book/BookData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,30 +113,30 @@ const std::array<std::string_view, 3> bookFormats{
};

const std::array<std::string_view, 25> bookGenres = {"Adventure stories",
"Classics",
"Crime",
"Fairy tales, fables, and folk tales",
"Fantasy",
"Historical fiction",
"Horror",
"Humour and satire",
"Literary fiction",
"Mystery",
"Poetry",
"Plays",
"Romance",
"Science fiction",
"Short stories",
"Thrillers",
"War",
"Women’s fiction",
"Young adult",
"Non-fiction",
"Autobiography and memoir",
"Biography",
"Essays",
"Non-fiction novel",
"Self-help"};
"Classics",
"Crime",
"Fairy tales, fables, and folk tales",
"Fantasy",
"Historical fiction",
"Horror",
"Humour and satire",
"Literary fiction",
"Mystery",
"Poetry",
"Plays",
"Romance",
"Science fiction",
"Short stories",
"Thrillers",
"War",
"Women’s fiction",
"Young adult",
"Non-fiction",
"Autobiography and memoir",
"Biography",
"Essays",
"Non-fiction novel",
"Self-help"};

const std::array<std::string_view, 263> publishers = {"Academic Press",
"Ace Books",
Expand Down
13 changes: 6 additions & 7 deletions src/modules/git/Git.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#include "faker-cxx/Git.h"

#include <cstddef>
#include <optional>
#include <string>

Expand Down Expand Up @@ -91,8 +90,8 @@ std::string Git::commitEntry(std::optional<unsigned> dateYears, std::optional<un
entry += commitSha();
}

const auto firstName = Person::firstName(country);
const auto lastName = Person::lastName(country);
const auto firstName = static_cast<std::string>(Person::firstName(country));
const auto lastName = static_cast<std::string>(Person::lastName(country));

entry += "\nAuthor: " + firstName + " " + lastName + " " + Internet::email(firstName, lastName) + "\nDate: ";

Expand Down Expand Up @@ -132,11 +131,11 @@ std::string Git::commitSha(unsigned length)

Git::Author Git::author()
{
const std::string firstName = Person::firstName();
const std::string lastName = Person::lastName();
const auto firstName = static_cast<std::string>(Person::firstName());
const auto lastName = static_cast<std::string>(Person::lastName());

const std::string name = firstName + " " + lastName;
const std::string email = Internet::email(firstName, lastName);
const auto name = firstName + " " + lastName;
const auto email = Internet::email(firstName, lastName);

return {name, email};
}
Expand Down
Loading

0 comments on commit 63471ee

Please sign in to comment.