Skip to content

Commit

Permalink
refactor lorem Data
Browse files Browse the repository at this point in the history
  • Loading branch information
krupalbhat committed Jun 1, 2024
1 parent 0a07883 commit 76f5f90
Show file tree
Hide file tree
Showing 7 changed files with 211 additions and 199 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ set(FAKER_SOURCES
src/modules/location/Location.cpp
src/modules/location/LocationData.cpp
src/modules/lorem/Lorem.cpp
src/modules/lorem/LoremData.cpp
src/modules/medicine/Medicine.cpp
src/modules/medicine/MedicineData.cpp
src/modules/movie/Movie.cpp
Expand Down
2 changes: 1 addition & 1 deletion include/faker-cxx/Lorem.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class Lorem
* Lorem::word() // "temporibus"
* @endcode
*/
static std::string word();
static std::string_view word();

/**
* @brief Returns a random lorem words.
Expand Down
14 changes: 9 additions & 5 deletions src/modules/lorem/Lorem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,24 @@

#include "../../common/FormatHelper.h"
#include "../../common/StringHelper.h"
#include "data/LoremWords.h"
#include "LoremData.h"
#include "faker-cxx/Helper.h"

namespace faker
{
std::string Lorem::word()
std::string_view Lorem::word()
{
return Helper::arrayElement<std::string>(loremWords);
return Helper::arrayElement(loremWords);
}

std::string Lorem::words(unsigned numberOfWords)
{
std::vector<std::string> words;
words.reserve(numberOfWords);

for (unsigned i = 0; i < numberOfWords; i++)
{
words.push_back(word());
words.push_back(std::string(word()));
}

return StringHelper::join(words, " ");
Expand All @@ -38,6 +39,7 @@ std::string Lorem::sentences(unsigned minNumberOfSentences, unsigned maxNumberOf
const std::integral auto numberOfSentences = Number::integer(minNumberOfSentences, maxNumberOfSentences);

std::vector<std::string> sentences;
sentences.reserve(numberOfSentences);

for (unsigned i = 0; i < numberOfSentences; i++)
{
Expand All @@ -50,10 +52,11 @@ std::string Lorem::sentences(unsigned minNumberOfSentences, unsigned maxNumberOf
std::string Lorem::slug(unsigned int numberOfWords)
{
std::vector<std::string> words;
words.reserve(numberOfWords);

for (unsigned i = 0; i < numberOfWords; i++)
{
words.push_back(word());
words.push_back(std::string(word()));
}

return StringHelper::join(words, "-");
Expand All @@ -69,6 +72,7 @@ std::string Lorem::paragraphs(unsigned int minNumberOfParagraphs, unsigned int m
const std::integral auto numberOfParagraphs = Number::integer(minNumberOfParagraphs, maxNumberOfParagraphs);

std::vector<std::string> paragraphs;
paragraphs.reserve(numberOfParagraphs);

for (unsigned i = 0; i < numberOfParagraphs; i++)
{
Expand Down
190 changes: 190 additions & 0 deletions src/modules/lorem/LoremData.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,190 @@
#include "LoremData.h"

namespace faker
{

const std::array<std::string_view,182> loremWords = {
"alias",
"consequatur",
"aut",
"perferendis",
"sit",
"voluptatem",
"accusantium",
"doloremque",
"aperiam",
"eaque",
"ipsa",
"quae",
"ab",
"illo",
"inventore",
"veritatis",
"et",
"quasi",
"architecto",
"beatae",
"vitae",
"dicta",
"sunt",
"explicabo",
"aspernatur",
"odit",
"fugit",
"sed",
"quia",
"consequuntur",
"magni",
"dolores",
"eos",
"qui",
"ratione",
"sequi",
"nesciunt",
"neque",
"dolorem",
"ipsum",
"dolor",
"amet",
"consectetur",
"adipisci",
"velit",
"non",
"numquam",
"eius",
"modi",
"tempora",
"incidunt",
"ut",
"labore",
"dolore",
"magnam",
"aliquam",
"quaerat",
"enim",
"ad",
"minima",
"veniam",
"quis",
"nostrum",
"exercitationem",
"ullam",
"corporis",
"nemo",
"ipsam",
"voluptas",
"suscipit",
"laboriosam",
"nisi",
"aliquid",
"ex",
"ea",
"commodi",
"autem",
"vel",
"eum",
"iure",
"reprehenderit",
"in",
"voluptate",
"esse",
"quam",
"nihil",
"molestiae",
"iusto",
"odio",
"dignissimos",
"ducimus",
"blanditiis",
"praesentium",
"laudantium",
"totam",
"rem",
"voluptatum",
"deleniti",
"atque",
"corrupti",
"quos",
"quas",
"molestias",
"excepturi",
"sint",
"occaecati",
"cupiditate",
"provident",
"perspiciatis",
"unde",
"omnis",
"iste",
"natus",
"error",
"similique",
"culpa",
"officia",
"deserunt",
"mollitia",
"animi",
"id",
"est",
"laborum",
"dolorum",
"fuga",
"harum",
"quidem",
"rerum",
"facilis",
"expedita",
"distinctio",
"nam",
"libero",
"tempore",
"cum",
"soluta",
"nobis",
"eligendi",
"optio",
"cumque",
"impedit",
"quo",
"porro",
"quisquam",
"minus",
"quod",
"maxime",
"placeat",
"facere",
"possimus",
"assumenda",
"repellendus",
"temporibus",
"quibusdam",
"illum",
"fugiat",
"nulla",
"pariatur",
"at",
"vero",
"accusamus",
"officiis",
"debitis",
"necessitatibus",
"saepe",
"eveniet",
"voluptates",
"repudiandae",
"recusandae",
"itaque",
"earum",
"hic",
"tenetur",
"a",
"sapiente",
"delectus",
"reiciendis",
"voluptatibus",
"maiores",
"doloribus",
"asperiores",
"repellat",
};
}
9 changes: 9 additions & 0 deletions src/modules/lorem/LoremData.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#pragma once
#include <array>
#include <string_view>

namespace faker
{
extern const std::array<std::string_view,182> loremWords;
}

Loading

0 comments on commit 76f5f90

Please sign in to comment.