Skip to content

Commit

Permalink
Merge branch 'feature/movie-locale' of github.com:
Browse files Browse the repository at this point in the history
SgtApone117/faker-cxx into feature/movie-locale
  • Loading branch information
SgtApone117 committed Dec 2, 2024
2 parents 1536b21 + ba4f756 commit 28c6cd7
Show file tree
Hide file tree
Showing 14 changed files with 1,311 additions and 170 deletions.
24 changes: 24 additions & 0 deletions LICENSES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,29 @@
# Third Party Licenses

## suyash/ulid:

MIT License

Copyright (c) 2016 Suyash

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

## flexxxxer/Md5Hash:

MIT License
Expand Down
10 changes: 7 additions & 3 deletions include/faker-cxx/medicine.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,37 @@
#include <string_view>

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

namespace faker::medicine
{
/**
* @brief Returns a random medical condition.
* @param locale The locale. Defaults to `Locale::en_US`.
*
* @returns Medical condition.
*
* @code
* faker::medicine::condition() // "AIDS"
* @endcode
*/
FAKER_CXX_EXPORT std::string_view condition();
FAKER_CXX_EXPORT std::string_view condition(Locale locale = Locale::en_US);

/**
* @brief Returns a random medical test
* @param locale The locale. Defaults to `Locale::en_US`.
*
* @returns Medical test.
*
* @code
* faker::medicine::medicalTest() // "pulmonary auscultation"
* @endcode
*/
FAKER_CXX_EXPORT std::string_view medicalTest();
FAKER_CXX_EXPORT std::string_view medicalTest(Locale locale = Locale::en_US);

/**
* @brief Returns a random Medical specialty
* @param locale The locale. Defaults to `Locale::en_US`.
*
* @returns Medical specialty.
*
Expand All @@ -38,5 +42,5 @@ FAKER_CXX_EXPORT std::string_view medicalTest();
* @endcode
*/

FAKER_CXX_EXPORT std::string_view specialty();
FAKER_CXX_EXPORT std::string_view specialty(Locale locale = Locale::en_US);
}
92 changes: 46 additions & 46 deletions include/faker-cxx/string.h
Original file line number Diff line number Diff line change
@@ -1,17 +1,39 @@
#pragma once

#include <algorithm>
#include <array>
#include <chrono>
#include <cstdint>
#include <cstring>
#include <iomanip>
#include <limits>
#include <map>
#include <optional>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <string_view>
#include <time.h>

#include "faker-cxx/export.h"
#include "helpers/ulid/ulid.h"
#include "random_generator.h"

namespace faker::string
{

enum class Uuid
{
V1, // Version 1: UUIDs using a timestamp and monotonic counter.
V3, // Version 3: UUIDs based on the MD5 hash of some data.
V4, // Version 4: UUIDs with random data.
V5, // Version 5: UUIDs based on the SHA1 hash of some data.
V6, // Version 6: UUIDs using a timestamp and monotonic counter (sortable).
V7, // Version 7: UUIDs using a Unix timestamp (sortable).
V8 // Version 8: UUIDs using user-defined data.
};

enum class StringCasing
{
Mixed,
Expand Down Expand Up @@ -63,60 +85,38 @@ FAKER_CXX_EXPORT bool isValidGuarantee(GuaranteeMap& guarantee, std::set<char>&
FAKER_CXX_EXPORT std::string generateAtLeastString(const GuaranteeMap& guarantee);

/**
* @brief Generates an Universally Unique Identifier with version 4.
* @brief Generates an Universally Unique Identifier, defaults to V4.
*
* @param gen A random number generator (type RandomGenerator)
*
* @returns UUID v4.
* @returns UUID.
*
* @code
* faker::string::uuid() // "27666229-cedb-4a45-8018-98b1e1d921e2"
* faker::string::uuid() // "27666229-cedb-4a45-8018-98b1e1d921e2" // V4
* faker::string::uuid(Uuid::V1) // "04f916a0-af32-11ef-9cd2-0242ac120002"
* faker::string::uuid(Uuid::V3) // "a3bb189e-8bf9-3888-9912-ace4e6543002"
* faker::string::uuid(Uuid::V4) // "27666229-cedb-4a45-8018-98b1e1d921e2"
* faker::string::uuid(Uuid::V5) // "27666229-cedb-4a45-8018-98b1e1d921e2"
* faker::string::uuid(Uuid::V6) // "27666229-cedb-4a45-8018-98b1e1d921e2"
* faker::string::uuid(Uuid::V7) // "27666229-cedb-4a45-8018-98b1e1d921e2"
* faker::string::uuid(Uuid::V8) // "27666229-cedb-4a45-8018-98b1e1d921e2"
* @endcode
*/
template <typename T = std::mt19937>
std::string uuid(RandomGenerator<T> gen = RandomGenerator<std::mt19937>{})
{
static std::uniform_int_distribution<> dist(0, 15);
static std::uniform_int_distribution<> dist2(8, 11);
static std::string_view hexCharacters{"0123456789abcdef"};

std::string result;
result.reserve(36);

for (int i = 0; i < 8; i++)
{
result.append(1, hexCharacters[static_cast<size_t>(gen(dist))]);
}
result.append(1, '-');

for (int i = 0; i < 4; i++)
{
result.append(1, hexCharacters[static_cast<size_t>(gen(dist))]);
}
result.append(1, '-');

result.append(1, '4');
for (int i = 0; i < 3; i++)
{
result.append(1, hexCharacters[static_cast<size_t>(gen(dist))]);
}
result.append(1, '-');

result.append(1, hexCharacters[static_cast<size_t>(gen(dist2))]);
FAKER_CXX_EXPORT std::string uuid(Uuid uuid = Uuid::V4);

for (int i = 0; i < 3; i++)
{
result.append(1, hexCharacters[static_cast<size_t>(gen(dist))]);
}
result.append(1, '-');

for (int i = 0; i < 12; i++)
{
result.append(1, hexCharacters[static_cast<size_t>(gen(dist))]);
}

return result;
}
/**
* @brief Generates an Universally Unique Lexicographically Sortable Identifier.
*
* @param refDate A reference date (type time_t)
*
* @returns ULID UINT128.
*
* @code
* faker::string::ulid() // "0001C7STHC0G2081040G208104"
* faker::string::ulid(1484581420) // "0001C7STHC0G2081040G208104"
* @endcode
*/
FAKER_CXX_EXPORT std::string ulid(time_t refDate = std::time(nullptr)); // Based on https://github.com/suyash/ulid

/**
* @brief Returns a string containing UTF-16 chars between 33 and 125 (`!` to `}`).
Expand Down
15 changes: 15 additions & 0 deletions include/helpers/ulid/ulid.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#ifndef ULID_HH
#define ULID_HH

// http://stackoverflow.com/a/23981011
#ifdef __SIZEOF_INT128__
#define ULIDUINT128
#endif

#ifdef ULIDUINT128
#include "ulid_uint128.h"
#else
#include "ulid_struct.h"
#endif // ULIDUINT128

#endif // ULID_HH
Loading

0 comments on commit 28c6cd7

Please sign in to comment.