Faker C++
Loading...
Searching...
No Matches
string.h
Go to the documentation of this file.
1#pragma once
2
3#include <algorithm>
4#include <array>
5#include <chrono>
6#include <cstdint>
7#include <cstring>
8#include <ctime>
9#include <iomanip>
10#include <limits>
11#include <map>
12#include <optional>
13#include <random>
14#include <set>
15#include <sstream>
16#include <string>
17#include <string_view>
18
19#include "faker-cxx/export.h"
20#include "random_generator.h"
21
23{
24enum class Uuid
25{
26 V1, // Version 1: UUIDs using a timestamp and monotonic counter.
27 V3, // Version 3: UUIDs based on the MD5 hash of some data.
28 V4, // Version 4: UUIDs with random data.
29 V5, // Version 5: UUIDs based on the SHA1 hash of some data.
30 V6, // Version 6: UUIDs using a timestamp and monotonic counter (sortable).
31 V7, // Version 7: UUIDs using a Unix timestamp (sortable).
32 V8 // Version 8: UUIDs using user-defined data.
33};
34
35enum class StringCasing
36{
37 Mixed,
38 Lower,
39 Upper
40};
41
42struct FAKER_CXX_EXPORT CharCount
43{
44 unsigned int atLeastCount{(std::numeric_limits<unsigned>::min)()};
45 unsigned int atMostCount{(std::numeric_limits<unsigned>::max)()};
46};
47
48using GuaranteeMap = std::map<char, CharCount>;
49
66FAKER_CXX_EXPORT bool isValidGuarantee(GuaranteeMap& guarantee, std::set<char>& targetCharacters, unsigned length);
67
80FAKER_CXX_EXPORT std::string generateAtLeastString(const GuaranteeMap& guarantee);
81
100FAKER_CXX_EXPORT std::string uuid(Uuid uuid = Uuid::V4);
101
114FAKER_CXX_EXPORT std::string ulid(time_t refDate = std::time(nullptr));
115
128FAKER_CXX_EXPORT std::string sample(unsigned length = 10);
129
143FAKER_CXX_EXPORT std::string sample(GuaranteeMap&& guarantee, unsigned length = 10);
144
158FAKER_CXX_EXPORT std::string symbol(unsigned minLength = 1, unsigned maxLength = 10);
159
173FAKER_CXX_EXPORT std::string fromCharacters(const std::string& characters, unsigned length = 1);
174
189FAKER_CXX_EXPORT std::string fromCharacters(GuaranteeMap&& guarantee, const std::string& characters,
190 unsigned length = 1);
191
207FAKER_CXX_EXPORT std::string alpha(unsigned length = 1, StringCasing casing = StringCasing::Mixed,
208 const std::string& excludeCharacters = "");
209
225FAKER_CXX_EXPORT std::string alpha(GuaranteeMap&& guarantee, unsigned length = 1,
227
244FAKER_CXX_EXPORT std::string alphanumeric(unsigned length = 1, StringCasing casing = StringCasing::Mixed,
245 const std::string& excludeCharacters = "");
246
262FAKER_CXX_EXPORT std::string alphanumeric(GuaranteeMap&& guarantee, unsigned length = 1,
264
279FAKER_CXX_EXPORT std::string numeric(unsigned length = 1, bool allowLeadingZeros = true);
280
296FAKER_CXX_EXPORT std::string numeric(GuaranteeMap&& guarantee, unsigned length = 1, bool allowLeadingZeros = true);
297
313FAKER_CXX_EXPORT std::string nanoId(int length);
314
328FAKER_CXX_EXPORT std::string nanoId();
329
347FAKER_CXX_EXPORT std::string nanoId(int minLength, int maxLength);
348}
Definition string.h:23
FAKER_CXX_EXPORT std::string nanoId()
Generates a unique, URL-safe string identifier of default length.
FAKER_CXX_EXPORT std::string uuid(Uuid uuid=Uuid::V4)
Generates an Universally Unique Identifier, defaults to V4.
FAKER_CXX_EXPORT std::string symbol(unsigned minLength=1, unsigned maxLength=10)
Returns a string containing "~`!@#$%^&*()_-+={[}]|:;\"'<,>.?/".
FAKER_CXX_EXPORT std::string sample(unsigned length=10)
Returns a string containing UTF-16 chars between 33 and 125 (`!` to `}`).
StringCasing
Definition string.h:36
FAKER_CXX_EXPORT std::string generateAtLeastString(const GuaranteeMap &guarantee)
Generates the least required string for a given guarantee map.
FAKER_CXX_EXPORT std::string ulid(time_t refDate=std::time(nullptr))
Generates an Universally Unique Lexicographically Sortable Identifier.
FAKER_CXX_EXPORT std::string numeric(unsigned length=1, bool allowLeadingZeros=true)
Generates a given length string of digits.
FAKER_CXX_EXPORT std::string alphanumeric(unsigned length=1, StringCasing casing=StringCasing::Mixed, const std::string &excludeCharacters="")
Generates a string consisting of alpha characters and digits.
Uuid
Definition string.h:25
FAKER_CXX_EXPORT bool isValidGuarantee(GuaranteeMap &guarantee, std::set< char > &targetCharacters, unsigned length)
Checks if the given guarantee map is valid for given targetCharacters and length.
FAKER_CXX_EXPORT std::string alpha(unsigned length=1, StringCasing casing=StringCasing::Mixed, const std::string &excludeCharacters="")
Generates a string consisting of letters in the English alphabet.
FAKER_CXX_EXPORT std::string fromCharacters(const std::string &characters, unsigned length=1)
Generates a string consisting of given characters.
std::map< char, CharCount > GuaranteeMap
Definition string.h:48
Definition string.h:43