Skip to content

Commit

Permalink
Merge branch 'main' into sex_function_locale
Browse files Browse the repository at this point in the history
  • Loading branch information
cieslarmichal authored Aug 28, 2024
2 parents 08d88c5 + 9977bf3 commit 8997401
Show file tree
Hide file tree
Showing 9 changed files with 193 additions and 366 deletions.
39 changes: 27 additions & 12 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@ 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.
If you want to format all files in project manually, you can run the following script:
```sh
./scripts/format_code.sh
```
3. **Make commits of logical units:**
This means that each commit should contain a complete and coherent piece of work that can be understood independently
Expand All @@ -78,7 +84,7 @@ inadvertently broken anything. Even if you think your changes are isolated, ther
with other parts of the codebase.

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:**
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
Expand Down Expand Up @@ -121,8 +127,10 @@ Follow the steps below to build the project:
"windows-msvc-release-shared" - Windows MSVC Release Shared library
```

For instance, if you are in Ubuntu and want to build using GCC in Debug mode and static library (faker-cxx.a), you should use the
preset `unixlike-gcc-debug=static`. The `unixlike-clang-` preset should work for both Linux and macOS when using the CLang
For instance, if you are in Ubuntu and want to build using GCC in Debug mode and static library (faker-cxx.a), you
should use the
preset `unixlike-gcc-debug=static`. The `unixlike-clang-` preset should work for both Linux and macOS when using the
CLang
compiler.

The `-S .` option in the following command specifies the source directory:
Expand Down Expand Up @@ -164,22 +172,26 @@ The faker-cxx project uses formated string feature, which can be solved by:
- [fmt](https://github.com/fmtlib/fmt) library
- [std::format](https://en.cppreference.com/w/cpp/utility/format/format)

The `std::format` requires C++20 standard support from the compiler. The feature is checked via CMake when building the project.
The `std::format` requires C++20 standard support from the compiler. The feature is checked via CMake when building the
project.
In case available, the option `USE_STD_FORMAT` will be available:

```sh
cmake -S . --preset unixlike-gcc-debug-static -DUSE_STD_FORMAT=ON
```

In case `std::format` is not available, faker-cxx will use `fmt` library instead. It can be used as external dependency via
git submodules, or consumed from your system (installed by Conan or system package manager). In order to manage the way to
In case `std::format` is not available, faker-cxx will use `fmt` library instead. It can be used as external dependency
via
git submodules, or consumed from your system (installed by Conan or system package manager). In order to manage the way
to
acquire `fmt`, the CMake option `USE_SYSTEM_DEPENDENCIES` manages if should be used from system, or from git submodule:

```sh
cmake -S . --preset unixlike-gcc-debug-static -DUSE_SYSTEM_DEPENDENCIES=OFF // Install from submodule
```

In case passing `USE_STD_FORMAT=ON` and `std::format` is not available, CMake will try to use `fmt` library automatically.
In case passing `USE_STD_FORMAT=ON` and `std::format` is not available, CMake will try to use `fmt` library
automatically.
Then, in case not finding `fmt`, it will fail.

### Testing the Project with CMake/CTest
Expand Down Expand Up @@ -211,23 +223,26 @@ As alternative, tests and be built and validated using Bazel as well. Follow the

### Installing the Project

When wanting to install those generated artifacts like headers files and library, you can use CMake to operate as installer as well:
When wanting to install those generated artifacts like headers files and library, you can use CMake to operate as
installer as well:

```sh
cmake --build --preset unixlike-gcc-debug-static --target install
```

By default, CMake will install in the subfolder `install` in the source folder.

In order to change the installation folder, you can use [CMAKE_INSTALL_PREFIX](https://cmake.org/cmake/help/latest/variable/CMAKE_INSTALL_PREFIX.html) to configure the destination folder:
In order to change the installation folder, you can
use [CMAKE_INSTALL_PREFIX](https://cmake.org/cmake/help/latest/variable/CMAKE_INSTALL_PREFIX.html) to configure the
destination folder:

```sh
cmake -S . --preset unixlike-gcc-debug-static -DCMAKE_INSTALL_PREFIX=/opt/faker-cxx
cmake --build --preset unixlike-gcc-debug-static --target install
```

This configuration will install all artifacts in `/opt/faker-cxx`. The permission to write in the folder should be granted before executing the installation command.

This configuration will install all artifacts in `/opt/faker-cxx`. The permission to write in the folder should be
granted before executing the installation command.

## Submitting Changes

Expand Down Expand Up @@ -275,7 +290,7 @@ PR titles are written in following convention: `type: subject`
Allowed types are:

| type | description |
| -------- | ------------------------------------------------------------------------- |
|----------|---------------------------------------------------------------------------|
| feat | A new feature is introduced |
| fix | A bug was fixed |
| chore | No user affected code changes were made |
Expand Down
64 changes: 23 additions & 41 deletions include/faker-cxx/location.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,11 @@
#include <string_view>

#include "faker-cxx/export.h"
#include "types/precision.h"
#include "faker-cxx/types/locale.h"
#include "faker-cxx/types/precision.h"

namespace faker::location
{
enum class AddressCountry
{
Australia,
Brazil,
Czech,
Denmark,
Estonia,
Finland,
France,
Germany,
India,
Italy,
Poland,
Russia,
Spain,
Ukraine,
Usa,
};

/**
* @brief Returns a random country name.
*
Expand All @@ -50,35 +32,35 @@ FAKER_CXX_EXPORT std::string_view country();
FAKER_CXX_EXPORT std::string_view countryCode();

/**
* @brief Returns a random state for a given country.
* @brief Returns a random state for a given locale.
*
* @param country The country to generate state from. Defaults to `Country::Usa`.
* @param locale The locale. Defaults to `Locale::en_US`.
*
* @returns State.
*
* @code
* faker::location::state() // "Arizona"
* @endcode
*/
FAKER_CXX_EXPORT std::string_view state(AddressCountry country = AddressCountry::Usa);
FAKER_CXX_EXPORT std::string_view state(Locale locale = Locale::en_US);

/**
* @brief Returns a random city for given country.
* @brief Returns a random city for given locale.
*
* @param country The country to generate city from. Defaults to `Country::Usa`.
* @param locale The locale. Defaults to `Locale::en_US`.
*
* @returns City.
*
* @code
* faker::location::city() // "Boston"
* @endcode
*/
FAKER_CXX_EXPORT std::string city(AddressCountry country = AddressCountry::Usa);
FAKER_CXX_EXPORT std::string city(Locale locale = Locale::en_US);

/**
* @brief Returns a random zip code for given country.
* @brief Returns a random zip code for given locale.
*
* @param country The country to generate zip code from. Defaults to `Country::Usa`.
* @param locale The locale. Defaults to `Locale::en_US`.
*
* @returns Zip code.
*
Expand All @@ -87,60 +69,60 @@ FAKER_CXX_EXPORT std::string city(AddressCountry country = AddressCountry::Usa);
* faker::location::zipCode(Country::Poland) // "31-881"
* @endcode
*/
FAKER_CXX_EXPORT std::string zipCode(AddressCountry country = AddressCountry::Usa);
FAKER_CXX_EXPORT std::string zipCode(Locale locale = Locale::en_US);

/**
* @brief Returns a random street address for given country.
* @brief Returns a random street address for given locale.
*
* @param country The country to generate street address from. Defaults to `Country::Usa`.
* @param locale The locale. Defaults to `Locale::en_US`.
*
* @returns Street address including building number and street name.
*
* @code
* faker::location::streetAddress() // "34830 Erdman Hollow"
* @endcode
*/
FAKER_CXX_EXPORT std::string streetAddress(AddressCountry country = AddressCountry::Usa);
FAKER_CXX_EXPORT std::string streetAddress(Locale locale = Locale::en_US);

/**
* @brief Returns a random street for given country.
* @brief Returns a random street for given locale.
*
* @param country The country to generate street from. Defaults to `Country::Usa`.
* @param locale The locale. Defaults to `Locale::en_US`.
*
* @returns Street name.
*
* @code
* faker::location::street() // "Schroeder Isle"
* @endcode
*/
FAKER_CXX_EXPORT std::string street(AddressCountry country = AddressCountry::Usa);
FAKER_CXX_EXPORT std::string street(Locale locale = Locale::en_US);

/**
* @brief Returns a random building number for given country.
* @brief Returns a random building number for given locale.
*
* @param country The country to generate building number from. Defaults to `Country::Usa`.
* @param locale The locale. Defaults to `Locale::en_US`.
*
* @returns Building number.
*
* @code
* faker::location::buildingNumber() // "505"
* @endcode
*/
FAKER_CXX_EXPORT std::string buildingNumber(AddressCountry country = AddressCountry::Usa);
FAKER_CXX_EXPORT std::string buildingNumber(Locale locale = Locale::en_US);

/**
* @brief Returns a random secondary address number for given country.
* @brief Returns a random secondary address number for given locale.
* This refers to a specific location at a given address such as an apartment or room number
*
* @param country The country to generate building number from. Defaults to `Country::Usa`.
* @param locale The locale. Defaults to `Locale::en_US`.
*
* @returns Secondary address.
*
* @code
* faker::location::secondaryAddress() // "Apt. 861"
* @endcode
*/
FAKER_CXX_EXPORT std::string secondaryAddress(AddressCountry country = AddressCountry::Usa);
FAKER_CXX_EXPORT std::string secondaryAddress(Locale locale = Locale::en_US);

/**
* @brief Generates a random latitude.
Expand Down
1 change: 0 additions & 1 deletion include/faker-cxx/person.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
#include <string_view>

#include "faker-cxx/export.h"
#include "types/country.h"
#include "types/locale.h"

namespace faker::person
Expand Down
69 changes: 0 additions & 69 deletions include/faker-cxx/types/country.h

This file was deleted.

1 change: 1 addition & 0 deletions scripts/format_code.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
clang-format src/**/*.cpp src/**/*.h include/**/*.h -i -style=file
Loading

0 comments on commit 8997401

Please sign in to comment.