Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor hacker module data #613

Merged
merged 2 commits into from
May 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ set(FAKER_SOURCES
src/modules/food/FoodData.cpp
src/modules/git/Git.cpp
src/modules/hacker/Hacker.cpp
src/modules/hacker/HackerData.cpp
src/modules/helper/Helper.cpp
src/modules/image/Image.cpp
src/modules/internet/Internet.cpp
Expand Down
12 changes: 6 additions & 6 deletions include/faker-cxx/Hacker.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once

#include <string>
#include <string_view>

namespace faker
{
Expand All @@ -16,7 +16,7 @@ class Hacker
* Hacker::abbreviation() // "TCP"
* @endcode
*/
static std::string abbreviation();
static std::string_view abbreviation();

/**
* @brief Returns a random adjective.
Expand All @@ -27,7 +27,7 @@ class Hacker
* Hacker::adjective() // "open-source"
* @endcode
*/
static std::string adjective();
static std::string_view adjective();

/**
* @brief Returns a random noun.
Expand All @@ -38,7 +38,7 @@ class Hacker
* Hacker::noun() // "coder"
* @endcode
*/
static std::string noun();
static std::string_view noun();

/**
* @brief Returns a random verb.
Expand All @@ -49,7 +49,7 @@ class Hacker
* Hacker::verb() // "run"
* @endcode
*/
static std::string verb();
static std::string_view verb();

/**
* @brief Returns a random ingverb.
Expand All @@ -60,7 +60,7 @@ class Hacker
* Hacker::ingverb() // "backing up"
* @endcode
*/
static std::string ingverb();
static std::string_view ingverb();

/**
* @brief Returns a random phrase.
Expand Down
6 changes: 3 additions & 3 deletions include/faker-cxx/Image.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#pragma once

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

namespace faker
{
Expand All @@ -23,7 +23,7 @@ class Image
Technics,
Transport
};

/**
* @brief Generates a real image url with `https://loremflickr.com/`.
*
Expand Down Expand Up @@ -72,6 +72,6 @@ class Image
* @code
* Image::type() // "png"
*/
static std::string type();
static std::string_view type();
};
}
68 changes: 34 additions & 34 deletions src/modules/hacker/Hacker.cpp
Original file line number Diff line number Diff line change
@@ -1,74 +1,74 @@
#include "faker-cxx/Hacker.h"

#include <string>

#include "../../common/StringHelper.h"
#include "data/Abbreviations.h"
#include "data/Adjectives.h"
#include "data/Ingverbs.h"
#include "data/Nouns.h"
#include "data/Phrases.h"
#include "data/Verbs.h"
#include "faker-cxx/Helper.h"
#include "HackerData.h"

namespace faker
{
std::string Hacker::abbreviation()
std::string_view Hacker::abbreviation()
{
return faker::Helper::arrayElement<std::string>(faker::abbreviations);
return Helper::arrayElement(abbreviations);
}

std::string Hacker::adjective()
std::string_view Hacker::adjective()
{
return faker::Helper::arrayElement<std::string>(faker::adjectives);
return Helper::arrayElement(adjectives);
}

std::string Hacker::noun()
std::string_view Hacker::noun()
{
return faker::Helper::arrayElement<std::string>(faker::nouns);
return Helper::arrayElement(nouns);
}

std::string Hacker::verb()
std::string_view Hacker::verb()
{
return faker::Helper::arrayElement<std::string>(faker::verbs);
return Helper::arrayElement(verbs);
}

std::string Hacker::ingverb()
std::string_view Hacker::ingverb()
{
return faker::Helper::arrayElement<std::string>(faker::ingverbs);
return Helper::arrayElement(ingverbs);
}

std::string Hacker::phrase()
{
auto splitRandomPhrase = StringHelper::split(faker::Helper::arrayElement<std::string>(faker::phrases));
std::string ret;
const auto splitRandomPhrase = StringHelper::split(static_cast<std::string>(Helper::arrayElement(phrases)));

std::string phrase;

for (auto& word : splitRandomPhrase)
for (const auto& word : splitRandomPhrase)
{
word = StringHelper::removePunctuation(word);
if (word == "{abbreviation}")
const auto normalizedWord = StringHelper::removePunctuation(word);

if (normalizedWord == "{abbreviation}")
{
phrase += abbreviation();
}
else if (normalizedWord == "{adjective}")
{
word = abbreviation();
phrase += adjective();
}
else if (word == "{adjective}")
else if (normalizedWord == "{noun}")
{
word = adjective();
phrase += noun();
}
else if (word == "{noun}")
else if (normalizedWord == "{verb}")
{
word = noun();
phrase += verb();
}
else if (word == "{verb}")
else if (normalizedWord == "{ingverb}")
{
word = verb();
phrase += ingverb();
}
else if (word == "{ingverb}")
else
{
word = ingverb();
phrase += normalizedWord;
}

ret += word + " ";
phrase += " ";
}

return ret;
return phrase;
}
}
44 changes: 44 additions & 0 deletions src/modules/hacker/HackerData.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#include "HackerData.h"

namespace faker
{
const std::array<std::string_view, 16> abbreviations = {
"e.g.", "i.e.", "etc.", "Mr.", "Mrs.", "Ms.", "Dr.", "Prof.",
"Ave.", "St.", "A.M.", "P.M.", "USA", "UK", "CEO", "CFO",
};

const std::array<std::string_view, 16> adjectives = {
"auxiliary", "primary", "back-end", "digital", "open-source", "virtual", "cross-platform", "redundant",
"online", "haptic", "multi-byte", "bluetooth", "wireless", "1080p", "neural", "optical",
};

const std::array<std::string_view, 16> ingverbs = {
"backing up", "bypassing", "hacking", "overriding", "compressing", "copying", "navigating", "indexing",
"connecting", "generating", "quantifying", "calculating", "synthesizing", "transmitting", "programming", "parsing",
};

const std::array<std::string_view, 16> nouns = {
"driver", "protocol", "bandwidth", "panel", "microchip", "program", "port", "card",
"array", "interface", "system", "sensor", "firewall", "hard drive", "pixel", "alarm",
};

const std::array<std::string_view, 8> phrases = {
"If we {verb} the {noun}, we can get to the {abbreviation} {noun} through the {adjective} "
"{abbreviation} {noun}!",
"We need to {verb} the {adjective} {abbreviation} {noun}!",
"Try to {verb} the {abbreviation} {noun}, maybe it will {verb} the {adjective} {noun}!",
"You can't {verb} the {noun} without {ingverb} the {adjective} {abbreviation} {noun}!",
"Use the {adjective} {abbreviation} {noun}, then you can {verb} the {adjective} {noun}!",
"The {abbreviation} {noun} is down, {verb} the {adjective} {noun} so we can {verb} the "
"{abbreviation} {noun}!",
"{ingverb} the {noun} won't do anything, we need to {verb} the {adjective} {abbreviation} "
"{noun}!",
"I'll {verb} the {adjective} {abbreviation} {noun}, that should {noun} the {abbreviation} "
"{noun}!",
};

const std::array<std::string_view, 16> verbs = {
"back up", "bypass", "hack", "override", "compress", "copy", "navigate", "index",
"connect", "generate", "quantify", "calculate", "synthesize", "transmit", "program", "parse",
};
}
14 changes: 14 additions & 0 deletions src/modules/hacker/HackerData.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#pragma once

#include <array>
#include <string_view>

namespace faker
{
extern const std::array<std::string_view, 16> abbreviations;
extern const std::array<std::string_view, 16> adjectives;
extern const std::array<std::string_view, 16> ingverbs;
extern const std::array<std::string_view, 16> nouns;
extern const std::array<std::string_view, 8> phrases;
extern const std::array<std::string_view, 16> verbs;
}
12 changes: 0 additions & 12 deletions src/modules/hacker/data/Abbreviations.h

This file was deleted.

12 changes: 0 additions & 12 deletions src/modules/hacker/data/Adjectives.h

This file was deleted.

12 changes: 0 additions & 12 deletions src/modules/hacker/data/Ingverbs.h

This file was deleted.

12 changes: 0 additions & 12 deletions src/modules/hacker/data/Nouns.h

This file was deleted.

25 changes: 0 additions & 25 deletions src/modules/hacker/data/Phrases.h

This file was deleted.

12 changes: 0 additions & 12 deletions src/modules/hacker/data/Verbs.h

This file was deleted.

7 changes: 5 additions & 2 deletions src/modules/image/Image.cpp
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
#include "faker-cxx/Image.h"

#include <array>
#include <unordered_map>

#include "../../common/FormatHelper.h"
#include "data/Type.h"
#include "faker-cxx/Helper.h"
#include "faker-cxx/Number.h"

namespace faker
{
namespace
{
const std::array<std::string_view, 15> imageTypes = {"ai", "bmp", "eps", "gif", "heif", "indd", "jpeg", "jpg",
"pdf", "png", "psd", "raw", "svg", "tiff", "webp"};

std::unordered_map<Image::ImageCategory, std::string> imageCategoryToLoremFlickrStringMapping = {
{Image::ImageCategory::Animals, "animals"}, {Image::ImageCategory::Business, "business"},
{Image::ImageCategory::Cats, "cats"}, {Image::ImageCategory::City, "city"},
Expand Down Expand Up @@ -41,7 +44,7 @@ std::string Image::dimensions()
return FormatHelper::format("{}x{}", Number::integer<int>(1, 32720), Number::integer<int>(1, 17280));
}

std::string Image::type()
std::string_view Image::type()
{
return Helper::arrayElement(imageTypes);
}
Expand Down
10 changes: 0 additions & 10 deletions src/modules/image/data/Type.h

This file was deleted.

Loading
Loading