diff --git a/.clang-format b/.clang-format
index 8411a69b5..b6482ed1e 100644
--- a/.clang-format
+++ b/.clang-format
@@ -33,6 +33,7 @@ SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 1
SpacesInAngles: false
ReferenceAlignment: Left
+SeparateDefinitionBlocks: Always
SpacesInCStyleCastParentheses: false
SpacesInContainerLiterals: false
SpacesInParentheses: false
diff --git a/CHANGELOG.md b/CHANGELOG.md
new file mode 100644
index 000000000..d496c49aa
--- /dev/null
+++ b/CHANGELOG.md
@@ -0,0 +1,40 @@
+# Changelog
+
+All notable changes to this project will be documented in this file
+
+## 2.0.0 (TBD)
+
+### ⚠ BREAKING CHANGES
+
+* removed `structure` module
+* removed `book.translator` method, use `person.fullName` instead
+* removed `book.isbn` method, use `commerce.isbn` instead
+* removed `commerce.price` method, use `finance.amount` instead
+* removed `commerce.productId` method, use `string.alphanumeric` instead
+* removed `commerce.productRating` method, use `number.decimal` instead
+* removed `commerce.discountAmount` method, use `number.decimal` instead
+* removed `commerce.discountPercentage` method, use `number.decimal` instead
+* removed `commerce.orderNumber` method, use `string.numeric` instead
+* removed `commerce.discountCode` method, use `string.alphanumeric` instead
+* removed `git.author` method, use `person.fullName` instead
+* removed `helper.shuffle` method, use standard library shuffle instead
+* removed `person.middleName` method, use `person.firstName` instead
+* removed `weather.temperature` method, use `number.decimal` instead
+* removed `weather.pressure` method, use `number.decimal` instead
+* removed `weather.visibility` method, use `number.decimal` instead
+* removed `weather.windSpeed` method, use `number.decimal` instead
+* removed `weather.uvIndex` method, use `number.integer` instead
+* removed `weather.humidity` method, use `number.integer` instead
+* removed `weather.cloudCover` method, use `number.integer` instead
+
+* changed std::string to std::string_view in where possible
+
+### Features
+
+* added `Plant` module
+
+### Infra
+
+* added Conan package manager support
+* added support for GCC 12
+* changed to link with fmt lib only if compiler does not support std::format
diff --git a/CMakeLists.txt b/CMakeLists.txt
index ffaae7d41..995d24304 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -88,7 +88,6 @@ set(FAKER_SOURCES
src/common/FormatHelper.cpp
src/common/LuhnCheck.cpp
src/common/StringHelper.cpp
- src/common/PrecisionMapper.cpp
)
add_library(${CMAKE_PROJECT_NAME} ${FAKER_SOURCES})
@@ -145,4 +144,4 @@ endif ()
if (BUILD_EXAMPLES)
add_subdirectory(examples)
-endif ()
\ No newline at end of file
+endif ()
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
index 7d7fc518a..c3ef26138 100644
--- a/CONTRIBUTING.md
+++ b/CONTRIBUTING.md
@@ -58,48 +58,32 @@ Please avoid working directly on the ``main`` branch.
Before making changes, make sure you have `clang-format` installed. If you're using Visual Studio Code, you can
install the `clang-format` extension.
- When you make a commit, `pre-commit` will automatically run `clang-format` on your code, ensuring it adheres to the
- project's coding style.
+3**Make commits of logical units:**
-3. **Set up pre-commit hooks:**
+This means that each commit should contain a complete and coherent piece of work that can be understood independently
+of other changes. For example, if you're fixing two different bugs, it's better to make two separate commits (one for
+each bug) rather than one commit that contains fixes for both bugs. This makes it easier to understand the purpose of
+each commit, and allows each change to be reviewed and applied separately.
- This project uses `pre-commit` hooks with `clang-format` to ensure code style consistency. Before making changes, set
- up the pre-commit hooks with the following commands:
+4**Make sure you have added the necessary tests for your changes:**
- ```sh
- pip install pre-commit
- pre-commit install
- ```
-
- Now, `pre-commit` will automatically run `clang-format` on your code whenever you make a commit, ensuring it adheres
- to the project's coding style.
-
-4. **Make commits of logical units:**
-
- This means that each commit should contain a complete and coherent piece of work that can be understood independently
- of other changes. For example, if you're fixing two different bugs, it's better to make two separate commits (one for
- each bug) rather than one commit that contains fixes for both bugs. This makes it easier to understand the purpose of
- each commit, and allows each change to be reviewed and applied separately.
-
-5. **Make sure you have added the necessary tests for your changes:**
-
- If you're adding a new feature or changing existing functionality, it's important to update or add tests that verify
- your changes. This helps to ensure that your changes work as expected and don't introduce new bugs. It also helps
- other developers understand what your code is supposed to do.
+If you're adding a new feature or changing existing functionality, it's important to update or add tests that verify
+your changes. This helps to ensure that your changes work as expected and don't introduce new bugs. It also helps
+other developers understand what your code is supposed to do.
-6. **Run all the tests to assure nothing else was accidentally broken:**
+5**Run all the tests to assure nothing else was accidentally broken:**
- Before you submit your changes, you should run all the project's tests to make sure your changes haven't
- inadvertently broken anything. Even if you think your changes are isolated, there could be unexpected interactions
- with other parts of the codebase.
+Before you submit your changes, you should run all the project's tests to make sure your changes haven't
+inadvertently broken anything. Even if you think your changes are isolated, there could be unexpected interactions
+with other parts of the codebase.
-7. **If you've added a new file to your project with non-Latin characters, ensure that the file encoding is set to
- Unicode (UTF-8 without signature) - Codepage 65001 in Microsoft Visual Studio Code:**
+6**If you've added a new file to your project with non-Latin characters, ensure that the file encoding is set to
+Unicode (UTF-8 without signature) - Codepage 65001 in Microsoft Visual Studio Code:**
- If a file contains non-Latin characters (such as characters from Chinese, Arabic, or many other non-Latin alphabets),
- it's important to save the file with the correct encoding to ensure that the characters are displayed correctly. In
- Visual Studio Code, you can set the encoding for a file by clicking on the "UTF-8" button in the status bar at the
- bottom of the window, and then selecting "Save with Encoding" and choosing "UTF-8 without BOM".
+If a file contains non-Latin characters (such as characters from Chinese, Arabic, or many other non-Latin alphabets),
+it's important to save the file with the correct encoding to ensure that the characters are displayed correctly. In
+Visual Studio Code, you can set the encoding for a file by clicking on the "UTF-8" button in the status bar at the
+bottom of the window, and then selecting "Save with Encoding" and choosing "UTF-8 without BOM".
## Building and Testing the Project
diff --git a/README.md b/README.md
index d37969636..afd3b99a6 100644
--- a/README.md
+++ b/README.md
@@ -13,6 +13,7 @@
## Table of Contents
+
- [🎯 Goal](#-goal)
- [Usage and Documentation](#usage-and-documentation)
- [💎 Modules](#-modules)
@@ -167,17 +168,28 @@ Check our guides on how to build the project locally:
- [G++](./docs/guides/gcc-compilation-guide.md)
- [MSVC](./docs/guides/msvc-compilation-guide.md)
-Before contributing please review
-our [CONTRIBUTING](https://github.com/cieslarmichal/faker-cxx/blob/main/CONTRIBUTING.md) guide.
+Please make sure to read the [Contributing Guide](https://github.com/cieslarmichal/faker-cxx/blob/main/CONTRIBUTING.md)
+before making a pull request.
Additionally, we encourage you to join our [Discord Channel](https://discord.gg/h2ur8H6mK6) for contributors.
+## 📘 Credits
+
+Thanks to all the people who already contributed to Faker!
+
+
+
## Examples
This project offers examples to demonstrate how to use the Faker C++ library.
These examples can be found in the [examples](examples/README.md) folder of the project repository.
-The examples showcase various modules of the library and provide code snippets that illustrate how to generate fake data using Faker C++.
+The examples showcase various modules of the library and provide code snippets that illustrate how to generate fake data
+using Faker C++.
+
+## 📝 Changelog
+
+Detailed changes for each release are documented in the [release notes](CHANGELOG.md).
-## License
+## 🔑 License
This project is under [MIT](LICENSE) license.
diff --git a/include/faker-cxx/Book.h b/include/faker-cxx/Book.h
index ff4535fcf..0bf7eab8f 100644
--- a/include/faker-cxx/Book.h
+++ b/include/faker-cxx/Book.h
@@ -51,28 +51,6 @@ class Book
*/
static std::string_view publisher();
- /**
- * @brief Returns a random book ISBN.
- *
- * @returns Book ISBN.
- *
- * @code
- * Book::isbn() // "978-83-01-00000-1"
- * @endcode
- */
- static std::string isbn();
-
- /**
- * @brief Returns the full name of a translator
- *
- * @returns std::string_view full name
- *
- * @code
- * Book::translator() // "Eric Floyd"
- * @endcode
- */
- static std::string_view translator();
-
/**
* @brief Returns format of book
*
diff --git a/include/faker-cxx/Commerce.h b/include/faker-cxx/Commerce.h
index 2457bce37..741beed40 100644
--- a/include/faker-cxx/Commerce.h
+++ b/include/faker-cxx/Commerce.h
@@ -18,18 +18,6 @@ class Commerce
*/
static std::string_view department();
- /**
- * @brief Generates a random price between the given bounds (inclusive).
-
- * @param min The lower bound for the price. Defaults to `0`.
- * @param max The upper bound for the price. Defaults to `1000`.
- *
- * @code
- * Commerce::price() // "88.62"
- * @endcode
- */
- static std::string price(double min = 0, double max = 1000);
-
/**
* @brief Generates a random sku by default only with digits.
*
@@ -130,17 +118,6 @@ class Commerce
*/
static std::string ISBN10();
- /**
- * @brief Returns a random product ID.
- *
- * @returns productId.
- *
- * @code
- * Commerce::productId() // "ABCD123456"
- * @endcode
- */
- static std::string productId();
-
/**
* @brief Returns a random payment type.
*
@@ -196,17 +173,6 @@ class Commerce
*/
static std::string_view productReview();
- /**
- * @brief Returns a random product rating (0-5).
- *
- * @returns productRating.
- *
- * @code
- * Commerce::productRating() // 4.1
- * @endcode
- */
- static double productRating();
-
/**
* @brief Returns a random discount type.
*
@@ -218,50 +184,6 @@ class Commerce
*/
static std::string_view discountType();
- /**
- * @brief Returns random discount code within the specified range of 6 to 12 characters.
- *
- * @returns discount code consists of uppercase letters and numbers.
- *
- * @code
- * Commerce::discountCode() // "VNM15DEC1"
- * @endcode
- */
- static std::string discountCode();
-
- /**
- * @brief Returns a random discount amount within the specified range of 10 to 1000.
- *
- * @returns discountAmount.
- *
- * @code
- * Commerce::discountAmount() // 57.80
- * @endcode
- */
- static double discountAmount();
-
- /**
- * @brief Returns a random discount percentage within the specified range of 1. to 90.
- *
- * @returns discountPercentage.
- *
- * @code
- * Commerce::discountPercentage() // 35.50
- * @endcode
- */
- static double discountPercentage();
-
- /**
- * @brief Returns a random order number.
- *
- * @returns orderNumber.
- *
- * @code
- * Commerce::orderNumber() // 0123456
- * @endcode
- */
- static std::string orderNumber();
-
/**
* @brief Returns a random order status.
*
diff --git a/include/faker-cxx/Git.h b/include/faker-cxx/Git.h
index f8ff6b2aa..9371073ed 100644
--- a/include/faker-cxx/Git.h
+++ b/include/faker-cxx/Git.h
@@ -84,18 +84,5 @@ class Git
* @endcode
*/
static std::string commitSha(unsigned length = 40);
-
- /**
- * @brief Returns a random author name and email.
- *
- * @param
- *
- * @returns Author.
- *
- * @code
- * Git::author // {Author.name = "Rachel McLaughlin", Author.email = "Rachel_McLaughlin@gmail.com"}
- * @endcode
- */
- static Author author();
};
}
diff --git a/include/faker-cxx/Helper.h b/include/faker-cxx/Helper.h
index ca6b744e9..f9216ce7f 100644
--- a/include/faker-cxx/Helper.h
+++ b/include/faker-cxx/Helper.h
@@ -61,12 +61,14 @@ class Helper
static auto arrayElement(It start, It end) -> decltype(*::std::declval())
{
size_t size = end - start;
+
if (size == 0)
{
throw std::invalid_argument{"Range [start,end) is empty."};
}
- const auto index = Number::integer(size - 1);
+ const std::integral auto index = Number::integer(size - 1);
+
return start[index];
}
@@ -145,7 +147,9 @@ class Helper
}
T item;
+
std::sample(data.begin(), data.end(), &item, 1, pseudoRandomGenerator);
+
return item;
}
@@ -188,41 +192,26 @@ class Helper
}
const std::integral auto targetWeightValue = Number::integer(1, sumOfWeights);
+
unsigned currentSum = 0;
+
size_t currentIdx = 0;
while (currentIdx < data.size())
{
currentSum += data[currentIdx].weight;
+
if (currentSum >= targetWeightValue)
+ {
break;
+ }
+
currentIdx++;
}
return data.at(currentIdx).value;
}
- /**
- * @brief Returns shuffled vector.
- *
- * @tparam T an element type of the vector.
- *
- * @param data The vector.
- *
- * @return Vector with shuffled elements.
- *
- * @code
- * Helper::shuffle(std::vector{{"hello"}, {"world"}}) // {{"world"}, {"hello"}}
- * @endcode
- */
- template
- static std::vector shuffle(std::vector data)
- {
- std::shuffle(std::begin(data), std::end(data), pseudoRandomGenerator);
-
- return data;
- }
-
/**
* @brief Returns shuffled std::string
*
@@ -265,6 +254,7 @@ class Helper
}
std::vector keys;
+
for (const auto& entry : object)
{
keys.push_back(entry.first);
@@ -296,6 +286,7 @@ class Helper
{
return callback();
}
+
return TResult();
}
diff --git a/include/faker-cxx/Person.h b/include/faker-cxx/Person.h
index 1655b0d6b..e1dbd7643 100644
--- a/include/faker-cxx/Person.h
+++ b/include/faker-cxx/Person.h
@@ -47,21 +47,6 @@ class Person
static std::string_view lastName(std::optional country = std::nullopt,
std::optional 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.
- *
- * @code
- * Person::middleName() // "Васильевич"
- * @endcode
- */
- static std::string_view middleName(std::optional country = std::nullopt,
- std::optional sex = std::nullopt);
-
/**
* @brief Returns a random full name.
*
diff --git a/include/faker-cxx/RandomGenerator.h b/include/faker-cxx/RandomGenerator.h
index a1e806fe5..1842495f6 100644
--- a/include/faker-cxx/RandomGenerator.h
+++ b/include/faker-cxx/RandomGenerator.h
@@ -10,6 +10,7 @@ class RandomGenerator
{
public:
RandomGenerator() : generator_{T(std::random_device{}())} {}
+
~RandomGenerator() = default;
RandomGenerator(const RandomGenerator&) = default;
diff --git a/include/faker-cxx/String.h b/include/faker-cxx/String.h
index 9e13cfab4..9940aa542 100644
--- a/include/faker-cxx/String.h
+++ b/include/faker-cxx/String.h
@@ -5,7 +5,6 @@
#include
#include
#include
-#include
#include
#include "RandomGenerator.h"
@@ -86,44 +85,44 @@ class String
{
static std::uniform_int_distribution<> dist(0, 15);
static std::uniform_int_distribution<> dist2(8, 11);
+ static std::string_view hexCharacters{"0123456789abcdef"};
- std::stringstream ss;
- ss << std::hex;
+ std::string result;
+ result.reserve(36);
for (int i = 0; i < 8; i++)
{
- ss << gen(dist);
+ result.append(1, hexCharacters[static_cast(gen(dist))]);
}
+ result.append(1, '-');
- ss << "-";
for (int i = 0; i < 4; i++)
{
- ss << gen(dist);
+ result.append(1, hexCharacters[static_cast(gen(dist))]);
}
+ result.append(1, '-');
- ss << "-4";
+ result.append(1, '4');
for (int i = 0; i < 3; i++)
{
- ss << gen(dist);
+ result.append(1, hexCharacters[static_cast(gen(dist))]);
}
+ result.append(1, '-');
- ss << "-";
-
- ss << gen(dist2);
+ result.append(1, hexCharacters[static_cast(gen(dist2))]);
for (int i = 0; i < 3; i++)
{
- ss << gen(dist);
+ result.append(1, hexCharacters[static_cast(gen(dist))]);
}
-
- ss << "-";
+ result.append(1, '-');
for (int i = 0; i < 12; i++)
{
- ss << gen(dist);
+ result.append(1, hexCharacters[static_cast(gen(dist))]);
}
- return ss.str();
+ return result;
}
/**
diff --git a/include/faker-cxx/System.h b/include/faker-cxx/System.h
index f7c167795..b47d2a93e 100644
--- a/include/faker-cxx/System.h
+++ b/include/faker-cxx/System.h
@@ -8,6 +8,7 @@ namespace faker
struct FileOptions
{
int extensionCount = 1;
+
struct
{
int min = 1;
diff --git a/include/faker-cxx/Weather.h b/include/faker-cxx/Weather.h
index d2ad5efc0..8358c2884 100644
--- a/include/faker-cxx/Weather.h
+++ b/include/faker-cxx/Weather.h
@@ -7,95 +7,6 @@ namespace faker
class Weather
{
public:
- struct Temperature
- {
- double metric, imperial;
- };
-
- /**
- * @brief Generates a random temperature
- *
- * @return Temperature object with metric and imperial temperatures
- *
- * @code
- * Weather::temperature(); // Temperature.metric = 10, Temperature.imperial = 50
- * @endcode
- */
- static Temperature temperature();
-
- struct Pressure
- {
- double metric;
- double imperial;
- };
-
- /**
- * @brief Generated a random pressure
- *
- * @return Pressure object with metric and imperial pressures
- *
- * @code
- * Weather::pressure(); // Pressure.metric = 1000, Pressure.imperial = 14.5
- * @endcode
- */
- static Pressure pressure();
-
- struct Visibility
- {
- double metric;
- double imperial;
- };
-
- /**
- * @brief Generated a random visibility
- *
- * @return Visibility object with metric and imperial visibility
- *
- * @code
- * Weather::visibility(); // Visibility.metric = 10.0, Visibility.imperial = 6.2
- * @endcode
- */
- static Visibility visibility();
-
- struct WindSpeed
- {
- double metric;
- double imperial;
- };
-
- /**
- * @brief Generated a random wind speed
- *
- * @return WindSpeed object with metric and imperial wind speed
- *
- * @code
- * Weather::windSpeed(); // WindSpeed.metric = 10.0, WindSpeed.imperial = 6.2
- * @endcode
- */
- static WindSpeed windSpeed();
-
- /**
- * @brief Generated a random uvIndex
- *
- * @return Int A random uvIndex
- *
- * @code
- * Weather::uvIndex(); // 10
- * @endcode
- */
- static int uvIndex();
-
- /**
- * @brief Generated a random humidity percentage
- *
- * @return Int A random humidity percentage
- *
- * @code
- * Weather::humidity(); // 10
- * @endcode
- */
- static int humidity();
-
/**
* @brief Generated a random weather description
*
@@ -106,16 +17,5 @@ class Weather
* @endcode
*/
static std::string_view weatherDescription();
-
- /**
- * @brief Generated a random cloud cover percentage
- *
- * @return Int A random cloud cover percentage
- *
- * @code
- * Weather::cloudCover(); // 10
- * @endcode
- */
- static int cloudCover();
};
}
diff --git a/src/common/FormatHelper.cpp b/src/common/FormatHelper.cpp
index a407552b7..b9baa7b77 100644
--- a/src/common/FormatHelper.cpp
+++ b/src/common/FormatHelper.cpp
@@ -47,9 +47,9 @@ FormatHelper::fillTokenValues(const std::string& format,
return filledFormat;
}
-std::string
-FormatHelper::fillTokenValues(const std::string& format,
- std::unordered_map> tokenValueGenerators)
+std::string FormatHelper::fillTokenValues(
+ const std::string& format,
+ std::unordered_map> tokenValueGenerators)
{
std::string filledFormat;
@@ -85,4 +85,29 @@ FormatHelper::fillTokenValues(const std::string& format,
return filledFormat;
}
+std::string FormatHelper::precisionFormat(Precision precision, double value)
+{
+ switch (precision)
+ {
+ case Precision::ZeroDp:
+ return FormatHelper::format("{:.0f}", value);
+ case Precision::OneDp:
+ return FormatHelper::format("{:.1f}", value);
+ case Precision::TwoDp:
+ return FormatHelper::format("{:.2f}", value);
+ case Precision::ThreeDp:
+ return FormatHelper::format("{:.3f}", value);
+ case Precision::FourDp:
+ return FormatHelper::format("{:.4f}", value);
+ case Precision::FiveDp:
+ return FormatHelper::format("{:.5f}", value);
+ case Precision::SixDp:
+ return FormatHelper::format("{:.6f}", value);
+ case Precision::SevenDp:
+ return FormatHelper::format("{:.7f}", value);
+ default:
+ throw std::invalid_argument("Invalid precision");
+ }
+}
+
}
diff --git a/src/common/FormatHelper.h b/src/common/FormatHelper.h
index ae343ee55..f81c1209e 100644
--- a/src/common/FormatHelper.h
+++ b/src/common/FormatHelper.h
@@ -4,12 +4,15 @@
#include
#include
#include
-#include
+
+#include "faker-cxx/types/Precision.h"
#if !defined(HAS_STD_FORMAT)
-#include
+#include
+#include
#else
#include
+
#endif
namespace faker
@@ -31,11 +34,14 @@ class FormatHelper
}
#endif
+ static std::string precisionFormat(Precision precision, double value);
+
static std::string
fillTokenValues(const std::string& format,
std::unordered_map> tokenValueGenerators);
- static std::string fillTokenValues(const std::string& format,
+ static std::string
+ fillTokenValues(const std::string& format,
std::unordered_map> tokenValueGenerators);
};
}
diff --git a/src/common/LuhnCheck.h b/src/common/LuhnCheck.h
index e50e4713f..a33065177 100644
--- a/src/common/LuhnCheck.h
+++ b/src/common/LuhnCheck.h
@@ -1,6 +1,5 @@
#pragma once
-#include
#include
namespace faker
diff --git a/src/common/PrecisionMapper.cpp b/src/common/PrecisionMapper.cpp
deleted file mode 100644
index c9e2e33d3..000000000
--- a/src/common/PrecisionMapper.cpp
+++ /dev/null
@@ -1,17 +0,0 @@
-#include "PrecisionMapper.h"
-
-#include
-
-#include "faker-cxx/types/Precision.h"
-
-namespace faker
-{
-const std::unordered_map PrecisionMapper::precisionToDecimalPlacesMapping{
- {Precision::ZeroDp, 0}, {Precision::OneDp, 1}, {Precision::TwoDp, 2}, {Precision::ThreeDp, 3},
- {Precision::FourDp, 4}, {Precision::FiveDp, 5}, {Precision::SixDp, 6}, {Precision::SevenDp, 7}};
-
-unsigned PrecisionMapper::mapToDecimalPlaces(Precision precision)
-{
- return precisionToDecimalPlacesMapping.at(precision);
-}
-}
diff --git a/src/common/PrecisionMapper.h b/src/common/PrecisionMapper.h
deleted file mode 100644
index 53010d8ed..000000000
--- a/src/common/PrecisionMapper.h
+++ /dev/null
@@ -1,17 +0,0 @@
-#pragma once
-
-#include
-
-#include "faker-cxx/types/Precision.h"
-
-namespace faker
-{
-class PrecisionMapper
-{
-public:
- static unsigned mapToDecimalPlaces(Precision precision);
-
-private:
- static const std::unordered_map precisionToDecimalPlacesMapping;
-};
-}
diff --git a/src/common/StringHelper.cpp b/src/common/StringHelper.cpp
index 5455b078e..f8ac83474 100644
--- a/src/common/StringHelper.cpp
+++ b/src/common/StringHelper.cpp
@@ -2,8 +2,6 @@
#include
#include
-#include
-#include
#include
#include
@@ -32,42 +30,56 @@ std::vector StringHelper::split(const std::string& data, const std:
std::string StringHelper::joinString(const std::vector& data, const std::string& separator)
{
- std::ostringstream result;
-
- for (size_t i = 0; i < (data.size() - 1); ++i)
+ switch (data.size())
{
- result << data[i] << separator;
- }
-
- if (!data.empty()) [[likely]]
+ case 0:
+ return "";
+ case 1:
+ return data[0];
+ default:
{
- result << data[data.size() - 1];
- }
+ std::string result{data[0]};
- return result.str();
+ for (auto it = data.begin() + 1; it != data.end(); ++it)
+ {
+ result += separator;
+ result += *it;
+ }
+
+ return result;
+ }
+ }
}
std::string StringHelper::join(const std::vector& data, const std::string& separator)
{
- std::ostringstream result;
-
- for (size_t i = 0; i < (data.size() - 1); ++i)
+ switch (data.size())
{
- result << data[i] << separator;
- }
-
- if (!data.empty()) [[likely]]
+ case 0:
+ return "";
+ case 1:
+ return std::string{data[0]};
+ default:
{
- result << data[data.size() - 1];
- }
+ std::string result{data[0]};
+
+ for (auto it = data.begin() + 1; it != data.end(); ++it)
+ {
+ result += separator;
+ result += *it;
+ }
- return result.str();
+ return result;
+ }
+ }
}
std::string StringHelper::repeat(const std::string& data, int repetition)
{
std::string result;
+ result.reserve(data.size() * static_cast(repetition));
+
for (int i = 0; i < repetition; ++i)
{
result += data;
diff --git a/src/modules/book/Book.cpp b/src/modules/book/Book.cpp
index decd7b75a..470dac808 100644
--- a/src/modules/book/Book.cpp
+++ b/src/modules/book/Book.cpp
@@ -1,12 +1,9 @@
#include "faker-cxx/Book.h"
-#include
#include
-#include "../../common/FormatHelper.h"
#include "BookData.h"
#include "faker-cxx/Helper.h"
-#include "faker-cxx/String.h"
namespace faker
{
@@ -30,17 +27,6 @@ std::string_view Book::publisher()
return Helper::arrayElement(publishers);
}
-std::string Book::isbn()
-{
- return FormatHelper::format("{}-{}-{}-{}-{}", String::numeric(3, false), String::numeric(2), String::numeric(2),
- String::numeric(5), String::numeric(1));
-}
-
-std::string_view Book::translator()
-{
- return Helper::arrayElement(translators);
-}
-
std::string_view Book::format()
{
return Helper::arrayElement(bookFormats);
diff --git a/src/modules/book/BookData.cpp b/src/modules/book/BookData.cpp
index d6ef1fa12..f9c9032de 100644
--- a/src/modules/book/BookData.cpp
+++ b/src/modules/book/BookData.cpp
@@ -5,530 +5,557 @@
namespace faker
{
-const std::array authors = {"Shakespeare, William",
- "Smollett, T. (Tobias)",
- "Dumas, Alexandre",
- "Montgomery, L. M. (Lucy Maud)",
- "Melville, Herman",
- "Alcott, Louisa May",
- "Eliot, George",
- "Forster, E. M. (Edward Morgan)",
- "Austen, Jane",
- "Merrill, Frank T.",
- "Dickens, Charles",
- "Gaskell, Elizabeth Cleghorn",
- "Von Arnim, Elizabeth",
- "Brock, C. E. (Charles Edmund)",
- "Fielding, Henry",
- "Wagner, Richard",
- "Twain, Mark",
- "Doyle, Arthur Conan",
- "Dostoyevsky, Fyodor",
- "Packard, Vance",
- "Adams, Clifford R. (Clifford Rose)",
- "Wilde, Oscar",
- "Garnett, Constance",
- "Carroll, Lewis",
- "Nietzsche, Friedrich Wilhelm",
- "Tolstoy, Leo",
- "Stevenson, Robert Louis",
- "Wells, H. G. (Herbert George)",
- "Shelley, Mary Wollstonecraft",
- "Howard, Robert E. (Robert Ervin)",
- "Baum, L. Frank (Lyman Frank)",
- "Chesterton, G. K. (Gilbert Keith)",
- "Homer",
- "Plato",
- "Rizal, José",
- "Christie, Agatha",
- "Joyce, James",
- "Jowett, Benjamin",
- "Poe, Edgar Allan",
- "Verne, Jules",
- "Thoreau, Henry David",
- "Kafka, Franz",
- "Stoker, Bram",
- "Kipling, Rudyard",
- "Doré, Gustave",
- "Widger, David",
- "Fitzgerald, F. Scott (Francis Scott)",
- "Russell, Bertrand",
- "Swift, Jonathan",
- "Dante Alighieri",
- "Wyllie, David",
- "Hugo, Victor",
- "Lang, Andrew",
- "Maude, Aylmer",
- "Burton, Richard Francis, Sir",
- "Maude, Louise",
- "Hawthorne, Nathaniel",
- "Conrad, Joseph",
- "London, Jack",
- "Goethe, Johann Wolfgang von",
- "James, Henry",
- "Scott, Walter",
- "Chekhov, Anton Pavlovich",
- "Pope, Alexander",
- "Ibsen, Henrik",
- "Cervantes Saavedra, Miguel de",
- "Balzac, Honoré de",
- "Grimm, Jacob",
- "Grimm, Wilhelm",
- "Lovecraft, H. P. (Howard Phillips)",
- "Burroughs, Edgar Rice",
- "Shaw, Bernard",
- "Gilman, Charlotte Perkins",
- "Wodehouse, P. G. (Pelham Grenville)",
- "Hotten, John Camden",
- "Morley, Henry",
- "Machiavelli, Niccolò",
- "Derbyshire, Charles E.",
- "Barrie, J. M. (James Matthew)",
- "Brontë, Charlotte",
- "Defoe, Daniel",
- "Ward, Grady",
- "Levy, Oscar",
- "Burnett, Frances Hodgson",
- "Schopenhauer, Arthur",
- "Buckley, Theodore Alois",
- "Milne, A. A. (Alan Alexander)",
- "Marriott, W. K. (William Kenaz)",
- "Vatsyayana",
- "Potter, Beatrix",
- "Ormsby, John",
- "Bhide, Shivaram Parashuram",
- "Butler, Samuel",
- "Indrajit, Bhagavanlal",
- "Maupassant, Guy de",
- "Hapgood, Isabel Florence",
- "Chambers, Robert W. (Robert William)",
- "Marx, Karl",
- "Eliot, T. S. (Thomas Stearns)",
- "Hardy, Thomas"};
+const std::array authors = {
+ "A. A. Milne",
+ "Agatha Christie",
+ "Alexander Pope",
+ "Alexandre Dumas",
+ "Alice Walker",
+ "Andrew Lang",
+ "Anton Pavlovich Chekhov",
+ "Arthur Conan Doyle",
+ "Arthur Schopenhauer",
+ "Aylmer Maude",
+ "Beatrix Potter",
+ "Benjamin Jowett",
+ "Bernard Shaw",
+ "Bertrand Russell",
+ "Bhagavanlal Indrajit",
+ "Bram Stoker",
+ "Brian Evenson",
+ "C. E. Brock",
+ "Charles Dickens",
+ "Charles E. Derbyshire",
+ "Charlotte Brontë",
+ "Charlotte Perkins Gilman",
+ "Clifford R. Adams",
+ "Constance Garnett",
+ "Dan Brown",
+ "Daniel Defoe",
+ "Dante Alighieri",
+ "David Widger",
+ "David Wyllie",
+ "Dean Koontz",
+ "E. M. Forster",
+ "Edgar Allan Poe",
+ "Edgar Rice Burroughs",
+ "Elizabeth Cleghorn Gaskell",
+ "Elizabeth Von Arnim",
+ "F. Scott Fitzgerald",
+ "Frances Hodgson Burnett",
+ "Frank T. Merrill",
+ "Franz Kafka",
+ "Friedrich Wilhelm Nietzsche",
+ "Fyodor Dostoyevsky",
+ "G. K. Chesterton",
+ "George Eliot",
+ "George R. R. Martin",
+ "George Saunders",
+ "Grady Ward",
+ "Gustave Doré",
+ "Guy de Maupassant",
+ "H. G. Wells",
+ "H. P. Lovecraft",
+ "Haruki Murakami",
+ "Henrik Ibsen",
+ "Henry David Thoreau",
+ "Henry Fielding",
+ "Henry James",
+ "Henry Morley",
+ "Herman Melville",
+ "Homer",
+ "Honoré de Balzac",
+ "Ian McEwan",
+ "Isabel Florence Hapgood",
+ "J. K. Rowling",
+ "J. M. Barrie",
+ "Jack London",
+ "Jacob Grimm",
+ "Jacqueline Crooks",
+ "James Joyce",
+ "James Patterson",
+ "Jane Austen",
+ "Johann Wolfgang von Goethe",
+ "John Camden Hotten",
+ "John Green",
+ "John Grisham",
+ "John Ormsby",
+ "Jonathan Franzen",
+ "Jonathan Swift",
+ "Joseph Conrad",
+ "José Rizal",
+ "Jules Verne",
+ "Karl Marx",
+ "Kazuo Ishiguro",
+ "Khaled Hosseini",
+ "L. Frank Baum",
+ "L. M. Montgomery",
+ "Leo Tolstoy",
+ "Lewis Carroll",
+ "Louisa May Alcott",
+ "Louise Maude",
+ "Margaret Atwood",
+ "Mark Twain",
+ "Mary Wollstonecraft Shelley",
+ "Michael Chabon",
+ "Miguel de Cervantes Saavedra",
+ "Nathaniel Hawthorne",
+ "Neil Gaiman",
+ "Niccolò Machiavelli",
+ "Oscar Levy",
+ "Oscar Wilde",
+ "P. G. Wodehouse",
+ "Plato",
+ "R. L. Stine",
+ "Rachel Kushner",
+ "Richard Wagner",
+ "Robert E. Howard",
+ "Robert Louis Stevenson",
+ "Robert W. Chambers",
+ "Rudyard Kipling",
+ "Samuel Butler",
+ "Shivaram Parashuram Bhide",
+ "Sir Richard Francis Burton",
+ "Stephen King",
+ "Suzanne Collins",
+ "T. S. Eliot",
+ "T. Smollett",
+ "Theodore Alois Buckley",
+ "Thomas Hardy",
+ "Toni Morrison",
+ "Vance Packard",
+ "Vatsyayana",
+ "Victor Hugo",
+ "W. K. Marriott",
+ "Walter Scott",
+ "Wilhelm Grimm",
+ "William Shakespeare",
+ "Zadie Smith",
+};
-const std::array bookFormats{
+const std::array bookFormats{
"Paperback",
"Hardcover",
- "Kindle",
+ "Ebook",
+ "Audiobook",
};
-const std::array 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"};
+const std::array bookGenres = {
+ "Adventure", "Biography", "Business", "Children Literature",
+ "Classic", "Comedy", "Comic", "Detective",
+ "Drama", "Fantasy", "Graphic Novel", "Historical Fiction",
+ "Horror", "Memoir", "Mystery", "Mythology",
+ "Philosophy", "Poetry", "Psychology", "Religion",
+ "Romance", "Science Fiction", "Thriller", "Western",
+ "Young Adult",
+};
-const std::array publishers = {"Academic Press",
- "Ace Books",
- "Addison-Wesley",
- "Adis International",
- "Airiti Press",
- "Andrews McMeel Publishing",
- "Anova Books",
- "Anvil Press Poetry",
- "Applewood Books",
- "Apress",
- "Athabasca University Press",
- "Atheneum Books",
- "Atheneum Publishers",
- "Atlantic Books",
- "Atlas Press",
- "Ballantine Books",
- "Banner of Truth Trust",
- "Bantam Books",
- "Bantam Spectra",
- "Barrie & Jenkins",
- "Basic Books",
- "BBC Books",
- "Harvard University Press",
- "Belknap Press",
- "Bella Books",
- "Bellevue Literary Press",
- "Berg Publishers",
- "Berkley Books",
- "Bison Books",
- "Black Dog Publishing",
- "Black Library",
- "Black Sparrow Books",
- "Blackie and Son Limited",
- "Blackstaff Press",
- "Blackwell Publishing",
- "John Blake Publishing",
- "Bloodaxe Books",
- "Bloomsbury Publishing Plc",
- "Blue Ribbon Books",
- "Book League of America",
- "Book Works",
- "Booktrope",
- "Borgo Press",
- "Bowes & Bowes",
- "Boydell & Brewer",
- "Breslov Research Institute",
- "Brill Publishers",
- "Brimstone Press",
- "Broadview Press",
- "Burns & Oates",
- "Butterworth-Heinemann",
- "Caister Academic Press",
- "Cambridge University Press",
- "Candlewick Press",
- "Canongate Books",
- "Carcanet Press",
- "Carlton Books",
- "Carlton Publishing Group",
- "Carnegie Mellon University Press",
- "Casemate Publishers",
- "Cengage Learning",
- "Central European University Press",
- "Chambers Harrap",
- "Charles Scribner's Sons",
- "Chatto and Windus",
- "Chick Publications",
- "Chronicle Books",
- "Churchill Livingstone",
- "Cisco Press",
- "City Lights Publishers",
- "Cloverdale Corporation",
- "D. Appleton & Company",
- "D. Reidel",
- "Da Capo Press",
- "Daedalus Publishing",
- "Dalkey Archive Press",
- "Darakwon Press",
- "David & Charles",
- "DAW Books",
- "Dedalus Books",
- "Del Rey Books",
- "E. P. Dutton",
- "Earthscan",
- "ECW Press",
- "Eel Pie Publishing",
- "Eerdmans Publishing",
- "Edupedia Publications",
- "Ellora's Cave",
- "Elsevier",
- "Emerald Group Publishing",
- "Etruscan Press",
- "Faber and Faber",
- "FabJob",
- "Fairview Press",
- "Farrar, Straus & Giroux",
- "Fearless Books",
- "Felony & Mayhem Press",
- "Firebrand Books",
- "Flame Tree Publishing",
- "Focal Press",
- "G. P. Putnam's Sons",
- "G-Unit Books",
- "Gaspereau Press",
- "Gay Men's Press",
- "Gefen Publishing House",
- "George H. Doran Company",
- "George Newnes",
- "George Routledge & Sons",
- "Godwit Press",
- "Golden Cockerel Press",
- "Hachette Book Group USA",
- "Hackett Publishing Company",
- "Hamish Hamilton",
- "Happy House",
- "Harcourt Assessment",
- "Harcourt Trade Publishers",
- "Harlequin Enterprises Ltd",
- "Harper & Brothers",
- "Harper & Row",
- "HarperCollins",
- "HarperPrism",
- "HarperTrophy",
- "Harry N. Abrams, Inc.",
- "Harvard University Press",
- "Harvest House",
- "Harvill Press at Random House",
- "Hawthorne Books",
- "Hay House",
- "Haynes Manuals",
- "Heyday Books",
- "HMSO",
- "Hodder & Stoughton",
- "Hodder Headline",
- "Hogarth Press",
- "Holland Park Press",
- "Holt McDougal",
- "Horizon Scientific Press",
- "Ian Allan Publishing",
- "Ignatius Press",
- "Imperial War Museum",
- "Indiana University Press",
- "J. M. Dent",
- "Jaico Publishing House",
- "Jarrolds Publishing",
- "Karadi Tales",
- "Kensington Books",
- "Kessinger Publishing",
- "Kodansha",
- "Kogan Page",
- "Koren Publishers Jerusalem",
- "Ladybird Books",
- "Leaf Books",
- "Leafwood Publishers",
- "Left Book Club",
- "Legend Books",
- "Lethe Press",
- "Libertas Academica",
- "Liberty Fund",
- "Library of America",
- "Lion Hudson",
- "Macmillan Publishers",
- "Mainstream Publishing",
- "Manchester University Press",
- "Mandrake of Oxford",
- "Mandrake Press",
- "Manning Publications",
- "Manor House Publishing",
- "Mapin Publishing",
- "Marion Boyars Publishers",
- "Mark Batty Publisher",
- "Marshall Cavendish",
- "Marshall Pickering",
- "Martinus Nijhoff Publishers",
- "Mascot Books",
- "Matthias Media",
- "McClelland and Stewart",
- "McFarland & Company",
- "McGraw-Hill Education",
- "McGraw Hill Financial",
- "Medknow Publications",
- "Naiad Press",
- "Nauka",
- "NavPress",
- "New Directions Publishing",
- "New English Library",
- "New Holland Publishers",
- "New Village Press",
- "Newnes",
- "No Starch Press",
- "Nonesuch Press",
- "Oberon Books",
- "Open Court Publishing Company",
- "Open University Press",
- "Orchard Books",
- "O'Reilly Media",
- "Orion Books",
- "Packt Publishing",
- "Palgrave Macmillan",
- "Pan Books",
- "Pantheon Books at Random House",
- "Papadakis Publisher",
- "Parachute Publishing",
- "Parragon",
- "Pathfinder Press",
- "Paulist Press",
- "Pavilion Books",
- "Peace Hill Press",
- "Pecan Grove Press",
- "Pen and Sword Books",
- "Penguin Books",
- "Random House",
- "Reed Elsevier",
- "Reed Publishing",
- "SAGE Publications",
- "St. Martin's Press",
- "Salt Publishing",
- "Sams Publishing",
- "Schocken Books",
- "Scholastic Press",
- "Charles Scribner's Sons",
- "Seagull Books",
- "Secker & Warburg",
- "Shambhala Publications",
- "Shire Books",
- "Shoemaker & Hoard Publishers",
- "Shuter & Shooter Publishers",
- "Sidgwick & Jackson",
- "Signet Books",
- "Simon & Schuster",
- "T & T Clark",
- "Tachyon Publications",
- "Tammi",
- "Target Books",
- "Tarpaulin Sky Press",
- "Tartarus Press",
- "Tate Publishing & Enterprises",
- "Taunton Press",
- "Taylor & Francis",
- "Ten Speed Press",
- "UCL Press",
- "Unfinished Monument Press",
- "United States Government Publishing Office",
- "University of Akron Press",
- "University of Alaska Press",
- "University of California Press",
- "University of Chicago Press",
- "University of Michigan Press",
- "University of Minnesota Press",
- "University of Nebraska Press",
- "Velazquez Press",
- "Verso Books",
- "Victor Gollancz Ltd",
- "Viking Press",
- "Vintage Books",
- "Vintage Books at Random House",
- "Virago Press",
- "Virgin Publishing",
- "Voyager Books",
- "Brill",
- "Allen Ltd",
- "Zed Books",
- "Ziff Davis Media",
- "Zondervan"};
+const std::array publishers = {
+ "Academic Press",
+ "Ace Books",
+ "Addison-Wesley",
+ "Adis International",
+ "Airiti Press",
+ "Andrews McMeel Publishing",
+ "Anova Books",
+ "Anvil Press Poetry",
+ "Applewood Books",
+ "Apress",
+ "Athabasca University Press",
+ "Atheneum Books",
+ "Atheneum Publishers",
+ "Atlantic Books",
+ "Atlas Press",
+ "Ballantine Books",
+ "Banner of Truth Trust",
+ "Bantam Books",
+ "Bantam Spectra",
+ "Barrie & Jenkins",
+ "Basic Books",
+ "BBC Books",
+ "Harvard University Press",
+ "Belknap Press",
+ "Bella Books",
+ "Bellevue Literary Press",
+ "Berg Publishers",
+ "Berkley Books",
+ "Bison Books",
+ "Black Dog Publishing",
+ "Black Library",
+ "Black Sparrow Books",
+ "Blackie and Son Limited",
+ "Blackstaff Press",
+ "Blackwell Publishing",
+ "John Blake Publishing",
+ "Bloodaxe Books",
+ "Bloomsbury Publishing Plc",
+ "Blue Ribbon Books",
+ "Book League of America",
+ "Book Works",
+ "Booktrope",
+ "Borgo Press",
+ "Bowes & Bowes",
+ "Boydell & Brewer",
+ "Breslov Research Institute",
+ "Brill Publishers",
+ "Brimstone Press",
+ "Broadview Press",
+ "Burns & Oates",
+ "Butterworth-Heinemann",
+ "Caister Academic Press",
+ "Cambridge University Press",
+ "Candlewick Press",
+ "Canongate Books",
+ "Carcanet Press",
+ "Carlton Books",
+ "Carlton Publishing Group",
+ "Carnegie Mellon University Press",
+ "Casemate Publishers",
+ "Cengage Learning",
+ "Central European University Press",
+ "Chambers Harrap",
+ "Charles Scribner's Sons",
+ "Chatto and Windus",
+ "Chick Publications",
+ "Chronicle Books",
+ "Churchill Livingstone",
+ "Cisco Press",
+ "City Lights Publishers",
+ "Cloverdale Corporation",
+ "D. Appleton & Company",
+ "D. Reidel",
+ "Da Capo Press",
+ "Daedalus Publishing",
+ "Dalkey Archive Press",
+ "Darakwon Press",
+ "David & Charles",
+ "DAW Books",
+ "Dedalus Books",
+ "Del Rey Books",
+ "E. P. Dutton",
+ "Earthscan",
+ "ECW Press",
+ "Eel Pie Publishing",
+ "Eerdmans Publishing",
+ "Edupedia Publications",
+ "Ellora's Cave",
+ "Elsevier",
+ "Emerald Group Publishing",
+ "Etruscan Press",
+ "Faber and Faber",
+ "FabJob",
+ "Fairview Press",
+ "Farrar, Straus & Giroux",
+ "Fearless Books",
+ "Felony & Mayhem Press",
+ "Firebrand Books",
+ "Flame Tree Publishing",
+ "Focal Press",
+ "G. P. Putnam's Sons",
+ "G-Unit Books",
+ "Gaspereau Press",
+ "Gay Men's Press",
+ "Gefen Publishing House",
+ "George H. Doran Company",
+ "George Newnes",
+ "George Routledge & Sons",
+ "Godwit Press",
+ "Golden Cockerel Press",
+ "Hachette Book Group USA",
+ "Hackett Publishing Company",
+ "Hamish Hamilton",
+ "Happy House",
+ "Harcourt Assessment",
+ "Harcourt Trade Publishers",
+ "Harlequin Enterprises Ltd",
+ "Harper & Brothers",
+ "Harper & Row",
+ "HarperCollins",
+ "HarperPrism",
+ "HarperTrophy",
+ "Harry N. Abrams, Inc.",
+ "Harvard University Press",
+ "Harvest House",
+ "Harvill Press at Random House",
+ "Hawthorne Books",
+ "Hay House",
+ "Haynes Manuals",
+ "Heyday Books",
+ "HMSO",
+ "Hodder & Stoughton",
+ "Hodder Headline",
+ "Hogarth Press",
+ "Holland Park Press",
+ "Holt McDougal",
+ "Horizon Scientific Press",
+ "Ian Allan Publishing",
+ "Ignatius Press",
+ "Imperial War Museum",
+ "Indiana University Press",
+ "J. M. Dent",
+ "Jaico Publishing House",
+ "Jarrolds Publishing",
+ "Karadi Tales",
+ "Kensington Books",
+ "Kessinger Publishing",
+ "Kodansha",
+ "Kogan Page",
+ "Koren Publishers Jerusalem",
+ "Ladybird Books",
+ "Leaf Books",
+ "Leafwood Publishers",
+ "Left Book Club",
+ "Legend Books",
+ "Lethe Press",
+ "Libertas Academica",
+ "Liberty Fund",
+ "Library of America",
+ "Lion Hudson",
+ "Macmillan Publishers",
+ "Mainstream Publishing",
+ "Manchester University Press",
+ "Mandrake of Oxford",
+ "Mandrake Press",
+ "Manning Publications",
+ "Manor House Publishing",
+ "Mapin Publishing",
+ "Marion Boyars Publishers",
+ "Mark Batty Publisher",
+ "Marshall Cavendish",
+ "Marshall Pickering",
+ "Martinus Nijhoff Publishers",
+ "Mascot Books",
+ "Matthias Media",
+ "McClelland and Stewart",
+ "McFarland & Company",
+ "McGraw-Hill Education",
+ "McGraw Hill Financial",
+ "Medknow Publications",
+ "Naiad Press",
+ "Nauka",
+ "NavPress",
+ "New Directions Publishing",
+ "New English Library",
+ "New Holland Publishers",
+ "New Village Press",
+ "Newnes",
+ "No Starch Press",
+ "Nonesuch Press",
+ "Oberon Books",
+ "Open Court Publishing Company",
+ "Open University Press",
+ "Orchard Books",
+ "O'Reilly Media",
+ "Orion Books",
+ "Packt Publishing",
+ "Palgrave Macmillan",
+ "Pan Books",
+ "Pantheon Books at Random House",
+ "Papadakis Publisher",
+ "Parachute Publishing",
+ "Parragon",
+ "Pathfinder Press",
+ "Paulist Press",
+ "Pavilion Books",
+ "Peace Hill Press",
+ "Pecan Grove Press",
+ "Pen and Sword Books",
+ "Penguin Books",
+ "Random House",
+ "Reed Elsevier",
+ "Reed Publishing",
+ "SAGE Publications",
+ "St. Martin's Press",
+ "Salt Publishing",
+ "Sams Publishing",
+ "Schocken Books",
+ "Scholastic Press",
+ "Charles Scribner's Sons",
+ "Seagull Books",
+ "Secker & Warburg",
+ "Shambhala Publications",
+ "Shire Books",
+ "Shoemaker & Hoard Publishers",
+ "Shuter & Shooter Publishers",
+ "Sidgwick & Jackson",
+ "Signet Books",
+ "Simon & Schuster",
+ "T & T Clark",
+ "Tachyon Publications",
+ "Tammi",
+ "Target Books",
+ "Tarpaulin Sky Press",
+ "Tartarus Press",
+ "Tate Publishing & Enterprises",
+ "Taunton Press",
+ "Taylor & Francis",
+ "Ten Speed Press",
+ "UCL Press",
+ "Unfinished Monument Press",
+ "United States Government Publishing Office",
+ "University of Akron Press",
+ "University of Alaska Press",
+ "University of California Press",
+ "University of Chicago Press",
+ "University of Michigan Press",
+ "University of Minnesota Press",
+ "University of Nebraska Press",
+ "Velazquez Press",
+ "Verso Books",
+ "Victor Gollancz Ltd",
+ "Viking Press",
+ "Vintage Books",
+ "Vintage Books at Random House",
+ "Virago Press",
+ "Virgin Publishing",
+ "Voyager Books",
+ "Brill",
+ "Allen Ltd",
+ "Zed Books",
+ "Ziff Davis Media",
+ "Zondervan",
+};
-const std::array bookSeries = {
+const std::array bookSeries = {
+ "A Song of Ice and Fire",
+ "Anna Karenina",
+ "Colonel Race",
+ "Discworld",
+ "Dune",
"Harry Potter",
- "The Lord of the Rings",
- "Game of Thrones",
- "Sherlock Holmes",
+ "Hercule Poirot",
+ "His Dark Materials",
+ "Jane Austen Murder Mysteries",
+ "Little Women",
+ "Outlander",
"Percy Jackson",
- "The Hunger Games",
+ "Sherlock Holmes",
+ "The Arc of a Scythe",
+ "The Bartimaeus Trilogy",
+ "The Border Trilogy",
"The Chronicles of Narnia",
- "Dune",
- "The Maze Runner",
- "The Wheel of Time",
- "A Song of Ice and Fire",
- "Discworld",
"The Dark Tower",
- "The Hitchhiker's Guide to the Galaxy",
+ "The Dresden Files",
+ "The Eighth Life",
"The Foundation Series",
- "His Dark Materials",
- "Outlander",
+ "The Hitchhiker's Guide to the Galaxy",
+ "The Hunger Games",
+ "The Infinity Cycle",
"The Inheritance Cycle",
- "The Dresden Files",
+ "The Lord of the Rings",
+ "The Maze Runner",
+ "The Prison Healer",
+ "The Red Rising Saga",
+ "The Southern Reach",
+ "The Wheel of Time",
+ "Thursday Next Series",
+ "Twilight",
+ "War and Peace",
};
-const std::array titles = {
- "Romeo and Juliet",
- "Moby Dick",
+const std::array titles = {
+ "A Brief History of Time",
+ "A Clockwork Orange",
+ "A Doll's House",
+ "A Modest Proposal",
"A Room with a View",
- "Middlemarch",
- "Little Women",
- "The Complete Works of William Shakespeare",
- "The Blue Castle",
- "The Enchanted April",
- "The Adventures of Ferdinand Count Fathom",
- "Cranford",
- "The Expedition of Humphry Clinker",
- "The Adventures of Roderick Random",
- "History of Tom Jones, a Foundling",
- "Twenty Years After",
- "My Life",
- "Pride and Prejudice",
- "The grisly horror",
- "Alice's Adventures in Wonderland",
- "Frankenstein; Or, The Modern Prometheus",
- "Dracula",
- "The Picture of Dorian Gray",
+ "A Study in Scarlet",
"A Tale of Two Cities",
- "The Adventures of Sherlock Holmes",
- "Metamorphosis",
- "The Great Gatsby",
- "Dora",
- "Ulysses",
- "The Count of Monte Cristo, Illustrated",
- "The Brothers Karamazov",
- "War and Peace",
- "Hitting the line",
- "The Yellow Wallpaper",
- "The slang dictionary",
+ "Adventures of Huckleberry Finn",
+ "Alice's Adventures in Wonderland",
+ "Anna Karenina",
+ "Anne of Green Gables",
+ "Beloved",
+ "Beyond Good and Evil",
+ "Bible",
+ "Brave New World",
+ "Carmilla",
+ "Catch-22",
+ "Cranford",
"Crime and Punishment",
- "The book of antelopes",
- "Travels in Kordofan",
- "Bunny Brown and his sister Sue on the rolling ocean",
- "The Iliad",
- "The Prince",
- "Grimms' Fairy Tales",
+ "Dao De Jing: A Minimalist Translation",
+ "David Copperfield",
+ "Don Quixote",
+ "Dora",
+ "Dracula",
+ "Emma",
+ "Faust",
+ "For Whom the Bell Tolls",
+ "Frankenstein",
+ "Freakonomics",
"Great Expectations",
- "The Romance of Lust",
- "The Wonderful Wizard of Oz",
- "Moby Multiple Language Lists of Common Words",
- "The Kama Sutra of Vatsyayana",
- "The trial of Sacco and Vanzetti",
- "A Modest Proposal",
- "Beyond Good and Evil",
- "Tractatus Logico-Philosophicus",
- "Anna Karenina",
- "Thus Spake Zarathustra",
+ "Grimms' Fairy Tales",
+ "Hamlet",
+ "Heart of Darkness",
+ "Hitting the line",
+ "In Search of Lost Time",
+ "Invisible Man",
"Jane Eyre",
- "Don Quixote",
- "Anne of Green Gables",
- "On the Duty of Civil Disobedience",
- "Treasure Island",
- "A Doll's House",
- "The nugget finders",
+ "Josefine Mutzenbacher",
+ "Les Misérables",
+ "Life of Pi",
+ "Little Women",
+ "Lolita",
+ "Long Walk to Freedom",
+ "Madame Bovary",
"Meditations",
- "The Works of Edgar Allan Poe",
- "Demonology and Devil-lore",
- "A Study in Scarlet",
- "Winnie-the-Pooh",
+ "Metamorphosis",
+ "Middlemarch",
+ "Moby Dick",
+ "Mrs. Dalloway",
+ "My Bondage and My Freedom",
+ "My Life",
+ "Nineteen Eighty Four",
+ "Notes from the Underground ",
+ "On the Duty of Civil Disobedience",
+ "On the Road",
+ "One Hundred Years of Solitude",
+ "Peter Pan",
+ "Pride and Prejudice",
+ "Robinson Crusoe",
+ "Romeo and Juliet",
+ "Ruth Fielding in Alaska",
"Second Treatise of Government",
- "Adventures of Huckleberry Finn",
+ "The Adventures of Sherlock Holmes",
"The Adventures of Tom Sawyer",
- "The Importance of Being Earnest: A Trivial Comedy for Serious People",
- "Walden, and On The Duty Of Civil Disobedience",
- "The Strange Case of Dr. Jekyll and Mr. Hyde",
- "Wuthering Heights",
- "The War of the Worlds",
- "The Philippines a Century Hence",
- "The Prophet",
- "The Republic",
- "Calculus Made Easy",
- "Little Women",
- "Ruth Fielding in Alaska",
- "The Rámáyan of Válmíki",
- "The adventures of Uncle Wiggily the bunny rabbit gentleman with the twinkling pink nose",
- "The divine comedy",
- "Peter Pan",
+ "The Art of War",
+ "The Blue Castle",
+ "The Brothers Karamazov",
+ "The Catcher in the Rye",
+ "The Count of Monte Cristo",
+ "The Diary of a Young Girl",
+ "The Divine Comedy",
+ "The Enchanted April",
+ "The Grapes of Wrath",
+ "The Great Gatsby",
+ "The Handmaid’s Tale",
+ "The Iliad",
"The King in Yellow",
+ "The Kite Runner",
+ "The Little Prince",
+ "The Magic Mountain",
"The Odyssey",
- "Les Misérables",
+ "The Old Man and the Sea",
+ "The Picture of Dorian Gray",
+ "The Prince",
+ "The Problems of Philosophy",
+ "The Prophet",
+ "The Republic",
"The Scarlet Letter",
+ "The Sound and the Fury",
+ "The Stranger",
+ "The Sun Also Rises",
"The Time Machine",
- "Emma",
- "A reference hand-book for nurses",
- "The Problems of Philosophy",
- "Carmilla",
- "Dao De Jing: A Minimalist Translation",
- "Notes from the Underground ",
- "Through the Looking-Glass",
- "My Bondage and My Freedom",
- "Essays of Michel de Montaigne",
- "The Magazine of History",
- "Josefine Mutzenbacher",
- "Heart of Darkness",
- "David Copperfield",
- "Three Men in a Boat (To Say Nothing of the Dog)"};
-
-const std::array translators = {
- "Gregory Rabassa", "Edith Grossman", "Charlotte Mandell", "David Bellos", "Ann Goldstein",
- "C.K. Scott Moncrieff", "Lydia Davis", "Richard Howard", "Elliott Colla", "Katherine Silver",
- "Ros Schwartz", "Jennifer Croft", "Michael Hofmann", "Maureen Freely", "Natasha Wimmer",
+ "The Trial",
+ "The War of the Worlds",
+ "The Wonderful Wizard of Oz",
+ "The Works of Edgar Allan Poe",
+ "The Yellow Wallpaper",
+ "To Kill a Mockingbird",
+ "Ulysses",
+ "War and Peace",
+ "Winnie-the-Pooh",
+ "Wuthering Heights",
};
+
}
diff --git a/src/modules/book/BookData.h b/src/modules/book/BookData.h
index 4982ee268..7aff3c8b6 100644
--- a/src/modules/book/BookData.h
+++ b/src/modules/book/BookData.h
@@ -5,11 +5,10 @@
namespace faker
{
-extern const std::array authors;
-extern const std::array bookFormats;
+extern const std::array authors;
+extern const std::array bookFormats;
extern const std::array bookGenres;
extern const std::array publishers;
-extern const std::array bookSeries;
-extern const std::array titles;
-extern const std::array translators;
+extern const std::array bookSeries;
+extern const std::array titles;
}
diff --git a/src/modules/commerce/Commerce.cpp b/src/modules/commerce/Commerce.cpp
index c650e856d..cea2e7f82 100644
--- a/src/modules/commerce/Commerce.cpp
+++ b/src/modules/commerce/Commerce.cpp
@@ -1,15 +1,11 @@
#include "faker-cxx/Commerce.h"
-#include
-#include
#include
#include
#include "../../common/FormatHelper.h"
#include "CommerceData.h"
-#include "faker-cxx/Finance.h"
#include "faker-cxx/Helper.h"
-#include "faker-cxx/Number.h"
#include "faker-cxx/String.h"
namespace faker
@@ -19,11 +15,6 @@ std::string_view Commerce::department()
return Helper::arrayElement(departments);
}
-std::string Commerce::price(double min, double max)
-{
- return Finance::amount(min, max);
-}
-
std::string Commerce::sku(unsigned int length)
{
return String::numeric(length, false);
@@ -160,11 +151,6 @@ std::string Commerce::ISBN10()
return isbn10 + std::to_string(checkDigit);
}
-std::string Commerce::productId()
-{
- return String::alphanumeric(10, StringCasing::Upper, "");
-}
-
std::string_view Commerce::paymentType()
{
return Helper::arrayElement(paymentTypes);
@@ -190,44 +176,11 @@ std::string_view Commerce::productReview()
return Helper::arrayElement(productReviews);
}
-double Commerce::productRating()
-{
- const std::floating_point auto ratingValue = Number::decimal(5.);
- return std::ceil(ratingValue * 100) / 100;
-}
-
std::string_view Commerce::discountType()
{
return Helper::arrayElement(discountTypes);
}
-std::string Commerce::discountCode()
-{
- const std::integral auto codeLength = Number::integer(minDiscountCodeLength, maxDiscountCodeLength);
-
- return String::alphanumeric(codeLength, StringCasing::Upper);
-}
-
-double Commerce::discountAmount()
-{
- const std::floating_point auto amountValue = Number::decimal(minDiscountAmount, maxDiscountAmount);
-
- return std::ceil(amountValue * 100) / 100;
-}
-
-double Commerce::discountPercentage()
-{
- const std::floating_point auto percentageValue =
- Number::decimal(minDiscountPercentage, maxDiscountPercentage);
-
- return std::ceil(percentageValue * 100) / 100;
-}
-
-std::string Commerce::orderNumber()
-{
- return String::numeric(7, true);
-}
-
std::string_view Commerce::orderStatus()
{
return Helper::arrayElement(orderStatuses);
diff --git a/src/modules/crypto/Crypto.cpp b/src/modules/crypto/Crypto.cpp
index ccc05b68f..e1e293017 100644
--- a/src/modules/crypto/Crypto.cpp
+++ b/src/modules/crypto/Crypto.cpp
@@ -3,11 +3,8 @@
#include
#include
#include
-#include
-#include
-#include
-#include
-#include
+#include
+#include
#include "faker-cxx/Word.h"
@@ -15,16 +12,35 @@ namespace faker
{
namespace
{
-class SHA256
+template
+inline std::string toHex(const std::array& data)
{
+ static std::string_view hexDigits{"0123456789abcdef"};
+
+ std::string result;
+ result.reserve(N * 2);
+
+ for (uint8_t byte : data)
+ {
+ result.push_back(hexDigits[byte >> 4]);
+ result.push_back(hexDigits[byte & 0x0f]);
+ }
+ return result;
+}
+
+class SHA256
+{
public:
SHA256();
void update(const uint8_t* data, size_t length);
void update(const std::string& data);
std::array digest();
- static std::string toString(const std::array& digest);
+ static std::string toString(const std::array& digest)
+ {
+ return toHex(digest);
+ }
private:
uint8_t m_data[64]{};
@@ -116,17 +132,8 @@ std::string Crypto::md5(std::optional data)
{
orgData = data.value();
}
- std::array md5Stream = md5_hash::compute(orgData);
- std::ostringstream md5String;
- for (uint8_t byte : md5Stream)
- {
- // Append each byte to the stringstream in hexadecimal format
- md5String << std::hex << std::setw(2) << std::setfill('0') << static_cast(byte);
- }
- // Convert the stringstream to a string
- std::string result = md5String.str();
- return result;
+ return toHex(md5_hash::compute(orgData));
}
namespace
@@ -435,17 +442,5 @@ void SHA256::revert(std::array& hash)
}
}
-std::string SHA256::toString(const std::array& digest)
-{
- std::stringstream s;
- s << std::setfill('0') << std::hex;
-
- for (uint8_t i = 0; i < 32; i++)
- {
- s << std::setw(2) << (unsigned int)digest[i];
- }
-
- return s.str();
-}
}
}
diff --git a/src/modules/finance/Finance.cpp b/src/modules/finance/Finance.cpp
index ea6583e46..d93bf7654 100644
--- a/src/modules/finance/Finance.cpp
+++ b/src/modules/finance/Finance.cpp
@@ -1,15 +1,11 @@
#include "faker-cxx/Finance.h"
-#include
-#include
#include
-#include
#include
#include
#include
#include "../../common/FormatHelper.h"
-#include "../../common/PrecisionMapper.h"
#include "faker-cxx/Date.h"
#include "faker-cxx/Helper.h"
#include "faker-cxx/Number.h"
@@ -50,15 +46,11 @@ std::string Finance::amount(double min, double max, Precision precision, const s
{
const std::floating_point auto generatedNumber = Number::decimal(min, max);
- std::stringstream ss;
+ std::string result{symbol};
- ss << std::fixed;
+ result += FormatHelper::precisionFormat(precision, generatedNumber);
- ss.precision(PrecisionMapper::mapToDecimalPlaces(precision));
-
- ss << generatedNumber;
-
- return FormatHelper::format("{}{}", symbol, ss.str());
+ return result;
}
std::string Finance::iban(std::optional country)
diff --git a/src/modules/git/Git.cpp b/src/modules/git/Git.cpp
index 0b7fbe10d..e997ad6b2 100644
--- a/src/modules/git/Git.cpp
+++ b/src/modules/git/Git.cpp
@@ -129,15 +129,4 @@ std::string Git::commitSha(unsigned length)
return faker::String::hexadecimal(length, HexCasing::Lower, HexPrefix::None);
}
-Git::Author Git::author()
-{
- const auto firstName = static_cast(Person::firstName());
- const auto lastName = static_cast(Person::lastName());
-
- const auto name = firstName + " " + lastName;
- const auto email = Internet::email(firstName, lastName);
-
- return {name, email};
-}
-
}
diff --git a/src/modules/internet/Internet.cpp b/src/modules/internet/Internet.cpp
index 89a02cf0f..015f29622 100644
--- a/src/modules/internet/Internet.cpp
+++ b/src/modules/internet/Internet.cpp
@@ -5,7 +5,6 @@
#include
#include