Skip to content

Commit

Permalink
refactor: Stringhelper module
Browse files Browse the repository at this point in the history
- stringhelper module namespace changed from "common::stringhelper" to
  "common"

Signed-off-by: Guru Mehar Rachaputi <[email protected]>
  • Loading branch information
00thirdeye00 committed Jul 1, 2024
1 parent 3ce3bbf commit 15096f6
Show file tree
Hide file tree
Showing 21 changed files with 100 additions and 100 deletions.
2 changes: 1 addition & 1 deletion src/common/StringHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include <string>
#include <vector>

namespace faker::common::StringHelper
namespace faker::common
{
std::vector<std::string> split(const std::string& data, const std::string& separator)
{
Expand Down
2 changes: 1 addition & 1 deletion src/common/StringHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include <vector>
#include "faker-cxx/Export.h"

namespace faker::common::StringHelper
namespace faker::common
{
FAKER_CXX_EXPORT std::vector<std::string> split(const std::string& data, const std::string& separator = " ");
FAKER_CXX_EXPORT std::string joinString(const std::vector<std::string>& data, const std::string& separator = " ");
Expand Down
6 changes: 3 additions & 3 deletions src/modules/git/Git.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,17 @@ std::string commitDate(unsigned years)
{
const auto date = faker::date::pastDate(int(years));

const auto dateSplit = common::StringHelper::split(date, "-");
const auto dateSplit = common::split(date, "-");

const auto& year = dateSplit[0];
const auto& month = dateSplit[1];
const auto& rest = dateSplit[2];

const auto restSplit = common::StringHelper::split(rest, "T");
const auto restSplit = common::split(rest, "T");

const auto& day = restSplit[0];

const auto time = common::StringHelper::split(restSplit[1], "Z")[0];
const auto time = common::split(restSplit[1], "Z")[0];

int timeZone = number::integer(0, 12);

Expand Down
4 changes: 2 additions & 2 deletions src/modules/hacker/Hacker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ std::string_view ingverb()

std::string phrase()
{
const auto splitRandomPhrase = common::StringHelper::split(static_cast<std::string>(helper::arrayElement(phrases)));
const auto splitRandomPhrase = common::split(static_cast<std::string>(helper::arrayElement(phrases)));

std::string phrase;

for (const auto& word : splitRandomPhrase)
{
const auto normalizedWord = common::StringHelper::removePunctuation(word);
const auto normalizedWord = common::removePunctuation(word);

if (normalizedWord == "{abbreviation}")
{
Expand Down
4 changes: 2 additions & 2 deletions src/modules/helper/Helper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ std::string regexpStyleStringParse(const std::string& input)

int repetitions = number::integer(min, max);
data = data.substr(0, static_cast<unsigned long>(token.position())) +
common::StringHelper::repeat(token[1], repetitions) +
common::repeat(token[1], repetitions) +
data.substr(static_cast<unsigned long>(token.position() + token.length()));
}

Expand All @@ -93,7 +93,7 @@ std::string regexpStyleStringParse(const std::string& input)
{
int repetitions = std::stoi(token[2]);
data = data.substr(0, static_cast<unsigned long>(token.position())) +
common::StringHelper::repeat(token[1], repetitions) +
common::repeat(token[1], repetitions) +
data.substr(static_cast<unsigned long>(token.position() + token.length()));
}

Expand Down
4 changes: 2 additions & 2 deletions src/modules/internet/Internet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ std::string ipv6()
ipv6Parts.push_back(string::hexadecimal(4, HexCasing::Lower, HexPrefix::None));
}

return common::StringHelper::joinString(ipv6Parts, ":");
return common::joinString(ipv6Parts, ":");
}

std::string mac(const std::string& sep)
Expand Down Expand Up @@ -321,7 +321,7 @@ std::string domainName()

std::string domainWord()
{
return common::StringHelper::toLower(FormatHelper::format("{}-{}", word::adjective(), word::noun()));
return common::toLower(FormatHelper::format("{}-{}", word::adjective(), word::noun()));
}

std::string_view domainSuffix()
Expand Down
8 changes: 4 additions & 4 deletions src/modules/lorem/Lorem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ std::string words(unsigned numberOfWords)
words.push_back(word());
}

return common::StringHelper::join(words, " ");
return common::join(words, " ");
}

std::string sentence(unsigned minNumberOfWords, unsigned maxNumberOfWords)
Expand All @@ -52,7 +52,7 @@ std::string sentences(unsigned minNumberOfSentences, unsigned maxNumberOfSentenc
sentences.push_back(sentence());
}

return common::StringHelper::joinString(sentences, " ");
return common::joinString(sentences, " ");
}

std::string slug(unsigned int numberOfWords)
Expand All @@ -65,7 +65,7 @@ std::string slug(unsigned int numberOfWords)
words.push_back(std::string(word()));
}

return common::StringHelper::joinString(words, "-");
return common::joinString(words, "-");
}

std::string paragraph(unsigned int minNumberOfSentences, unsigned int maxNumberOfSentences)
Expand All @@ -85,7 +85,7 @@ std::string paragraphs(unsigned int minNumberOfParagraphs, unsigned int maxNumbe
paragraphs.push_back(paragraph());
}

return common::StringHelper::joinString(paragraphs, "\n");
return common::joinString(paragraphs, "\n");
}

}
4 changes: 2 additions & 2 deletions src/modules/system/System.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ std::string fileName(const FileOptions& options)
randomExtensions.push_back(fileExtension());
}

extensionsStr = "." + common::StringHelper::joinString(randomExtensions, ".");
extensionsStr = "." + common::joinString(randomExtensions, ".");
}
else
{
Expand All @@ -72,7 +72,7 @@ std::string fileName(const FileOptions& options)
randomExtensions.push_back(fileExtension());
}

extensionsStr = "." + common::StringHelper::joinString(randomExtensions, ".");
extensionsStr = "." + common::joinString(randomExtensions, ".");
}
}

Expand Down
22 changes: 11 additions & 11 deletions tests/common/StringHelperTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class StringHelperTest : public Test

TEST_F(StringHelperTest, splitStringBySpace)
{
const auto result = common::StringHelper::split("faker cxx open source");
const auto result = common::split("faker cxx open source");

ASSERT_EQ(result.size(), 4);
ASSERT_EQ(result[0], "faker");
Expand All @@ -25,7 +25,7 @@ TEST_F(StringHelperTest, splitStringBySpace)

TEST_F(StringHelperTest, splitStringByNewLine)
{
const auto result = common::StringHelper::split("faker\ncxx\nopen\nsource", "\n");
const auto result = common::split("faker\ncxx\nopen\nsource", "\n");

ASSERT_EQ(result.size(), 4);
ASSERT_EQ(result[0], "faker");
Expand All @@ -38,7 +38,7 @@ TEST_F(StringHelperTest, joinStringViewsIntoVectorBySpace)
{
const std::vector<std::string_view> input{"Join", "faker", "development!"};

const auto result = common::StringHelper::join(input);
const auto result = common::join(input);

ASSERT_EQ(result, "Join faker development!");
}
Expand All @@ -47,7 +47,7 @@ TEST_F(StringHelperTest, joinStringViewsIntoVectorByNewLine)
{
const std::vector<std::string_view> input{"Join", "faker", "development!"};

const auto result = common::StringHelper::join(input, "\n");
const auto result = common::join(input, "\n");

ASSERT_EQ(result, "Join\nfaker\ndevelopment!");
}
Expand All @@ -56,7 +56,7 @@ TEST_F(StringHelperTest, joinStringsIntoVectorBySpace)
{
const std::vector<std::string> input{"Join", "faker", "development!"};

const auto result = common::StringHelper::joinString(input);
const auto result = common::joinString(input);

ASSERT_EQ(result, "Join faker development!");
}
Expand All @@ -65,7 +65,7 @@ TEST_F(StringHelperTest, joinStringsIntoVectorByNewLine)
{
const std::vector<std::string> input{"Join", "faker", "development!"};

const auto result = common::StringHelper::joinString(input, "\n");
const auto result = common::joinString(input, "\n");

ASSERT_EQ(result, "Join\nfaker\ndevelopment!");
}
Expand All @@ -75,7 +75,7 @@ TEST_F(StringHelperTest, repeatString)
const std::string data = "hello ";
const int repetition = 3;

const std::string result = common::StringHelper::repeat(data, repetition);
const std::string result = common::repeat(data, repetition);

ASSERT_EQ(result, "hello hello hello ");
}
Expand All @@ -84,7 +84,7 @@ TEST_F(StringHelperTest, toLower)
{
const std::string data = "HeLlo!";

const std::string result = common::StringHelper::toLower(data);
const std::string result = common::toLower(data);

ASSERT_EQ(result, "hello!");
}
Expand All @@ -94,19 +94,19 @@ TEST_F(StringHelperTest, IsPunctuation)
std::string punctuation = ".,;:!?";
for (char c : punctuation)
{
EXPECT_TRUE(common::StringHelper::isPunctuation(c));
EXPECT_TRUE(common::isPunctuation(c));
}

std::string notPunctuation = "abc123";
for (char c : notPunctuation)
{
EXPECT_FALSE(common::StringHelper::isPunctuation(c));
EXPECT_FALSE(common::isPunctuation(c));
}
}

TEST_F(StringHelperTest, RemovePunctuation)
{
std::string input = "Hello, World!";
std::string result = common::StringHelper::removePunctuation(input);
std::string result = common::removePunctuation(input);
EXPECT_EQ(result, "Hello World");
}
22 changes: 11 additions & 11 deletions tests/modules/color/ColorTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ TEST_F(ColorTest, shouldGenerateRgbColorWithoutAlpha)
{
const auto generatedRgbColor = rgb();

const auto rgbNumbers = common::StringHelper::split(generatedRgbColor.substr(4, generatedRgbColor.size() - 1), " ");
const auto rgbNumbers = common::split(generatedRgbColor.substr(4, generatedRgbColor.size() - 1), " ");

int red, green, blue;
std::from_chars(rgbNumbers[0].data(), rgbNumbers[0].data() + rgbNumbers[0].size(), red);
Expand All @@ -51,7 +51,7 @@ TEST_F(ColorTest, shouldGenerateRgbColorWithAlpha)
{
const auto generatedRgbaColor = rgb(true);

const auto rgbaNumbers = common::StringHelper::split(generatedRgbaColor.substr(5, generatedRgbaColor.size() - 1), " ");
const auto rgbaNumbers = common::split(generatedRgbaColor.substr(5, generatedRgbaColor.size() - 1), " ");

int red, green, blue, alpha;
std::from_chars(rgbaNumbers[0].data(), rgbaNumbers[0].data() + rgbaNumbers[0].size(), red);
Expand Down Expand Up @@ -98,7 +98,7 @@ TEST_F(ColorTest, shouldGenerateHexColorWithAlpha)
TEST_F(ColorTest, shouldGenerateHslWithoutAlpha)
{
const auto generatedHslColor = hsl();
const auto hslValues = common::StringHelper::split(generatedHslColor.substr(4, generatedHslColor.size() - 1), " ");
const auto hslValues = common::split(generatedHslColor.substr(4, generatedHslColor.size() - 1), " ");

int hue, staturation, lightness;

Expand All @@ -116,7 +116,7 @@ TEST_F(ColorTest, shouldGenerateHslWithoutAlpha)
TEST_F(ColorTest, shouldGenerateHslWithAlpha)
{
const auto generatedHslaColor = hsl(true);
const auto hslValues = common::StringHelper::split(generatedHslaColor.substr(5, generatedHslaColor.size() - 1), " ");
const auto hslValues = common::split(generatedHslaColor.substr(5, generatedHslaColor.size() - 1), " ");

int hue, saturation, lightness;

Expand All @@ -138,7 +138,7 @@ TEST_F(ColorTest, shouldGenerateHslWithAlpha)
TEST_F(ColorTest, shouldGenerateLchWithoutAlpha)
{
const auto generatedLchColor = lch();
const auto lchValues = common::StringHelper::split(generatedLchColor.substr(4, generatedLchColor.size() - 1), " ");
const auto lchValues = common::split(generatedLchColor.substr(4, generatedLchColor.size() - 1), " ");

int luminance, chroma, hue;

Expand All @@ -156,7 +156,7 @@ TEST_F(ColorTest, shouldGenerateLchWithoutAlpha)
TEST_F(ColorTest, shouldGenerateLchWithAlpha)
{
const auto generatedLchaColor = lch(true);
const auto lchValues = common::StringHelper::split(generatedLchaColor.substr(5, generatedLchaColor.size() - 1), " ");
const auto lchValues = common::split(generatedLchaColor.substr(5, generatedLchaColor.size() - 1), " ");

int luminance, chroma, hue;

Expand All @@ -178,7 +178,7 @@ TEST_F(ColorTest, shouldGenerateLchWithAlpha)
TEST_F(ColorTest, shouldGenerateCmykColor)
{
const auto generatedCmykColor = cmyk();
const auto cmykValues = common::StringHelper::split(generatedCmykColor.substr(5, generatedCmykColor.size() - 1), " ");
const auto cmykValues = common::split(generatedCmykColor.substr(5, generatedCmykColor.size() - 1), " ");

auto offset = cmykValues[0].size();
const auto cyan = std::stod(cmykValues[0], &offset);
Expand All @@ -200,7 +200,7 @@ TEST_F(ColorTest, shouldGenerateCmykColor)
TEST_F(ColorTest, shouldGenerateLabColor)
{
const auto generatedLabColor = lab();
const auto labValues = common::StringHelper::split(generatedLabColor.substr(4, generatedLabColor.size() - 1), " ");
const auto labValues = common::split(generatedLabColor.substr(4, generatedLabColor.size() - 1), " ");

auto offset = labValues[0].size();
const auto lightness = std::stod(labValues[0], &offset);
Expand All @@ -219,7 +219,7 @@ TEST_F(ColorTest, shouldGenerateLabColor)
TEST_F(ColorTest, shouldGenerateHsb)
{
const auto generatedHsbColor = hsb();
const auto hsbValues = common::StringHelper::split(generatedHsbColor.substr(4, generatedHsbColor.size() - 1), " ");
const auto hsbValues = common::split(generatedHsbColor.substr(4, generatedHsbColor.size() - 1), " ");

int hue, saturation, brightness;

Expand All @@ -237,7 +237,7 @@ TEST_F(ColorTest, shouldGenerateHsb)
TEST_F(ColorTest, shouldGenerateHsv)
{
const auto generatedHsvColor = hsv();
const auto hsvValues = common::StringHelper::split(generatedHsvColor.substr(4, generatedHsvColor.size() - 1), " ");
const auto hsvValues = common::split(generatedHsvColor.substr(4, generatedHsvColor.size() - 1), " ");

int hue, saturation, brightness;

Expand All @@ -255,7 +255,7 @@ TEST_F(ColorTest, shouldGenerateHsv)
TEST_F(ColorTest, shouldGenerateYuv)
{
const auto generatedYuvColor = yuv();
const auto yuvValues = common::StringHelper::split(generatedYuvColor.substr(4, generatedYuvColor.size() - 1), " ");
const auto yuvValues = common::split(generatedYuvColor.substr(4, generatedYuvColor.size() - 1), " ");

int luminance, chrominanceBlueColor, chrominanceRedColor;

Expand Down
2 changes: 1 addition & 1 deletion tests/modules/commerce/CommerceTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ TEST_F(CommerceTest, shouldGenerateProductFullName)
{
const auto generatedProductFullName = productFullName();

const auto productFullNameElements = common::StringHelper::split(generatedProductFullName, " ");
const auto productFullNameElements = common::split(generatedProductFullName, " ");

const auto& generatedProductAdjective = productFullNameElements[0];
const auto& generatedProductMaterial = productFullNameElements[1];
Expand Down
2 changes: 1 addition & 1 deletion tests/modules/company/CompanyTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ TEST_F(CompanyTest, shouldGenerateCompanyName)
{
const auto companyName = name();

const auto companyNameElements = common::StringHelper::split(companyName, " ");
const auto companyNameElements = common::split(companyName, " ");

std::vector<std::string_view> expectedFirstNames(person::englishMaleFirstNames.begin(),
person::englishMaleFirstNames.end());
Expand Down
2 changes: 1 addition & 1 deletion tests/modules/date/DateTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ TEST_F(DateTest, shouldGenerateRandomTimezone)
TEST_F(DateTest, shouldGenerateRandomTime)
{
const auto generatedTime = time();
const auto generatedTimeParts = common::StringHelper::split(generatedTime, ":");
const auto generatedTimeParts = common::split(generatedTime, ":");

ASSERT_EQ(generatedTimeParts.size(), 2);

Expand Down
4 changes: 2 additions & 2 deletions tests/modules/finance/FinanceTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ TEST_F(FinanceTest, shouldGenerateAmount)
auto offset = generatedAmount.size();
const auto amountAsFloat = std::stof(generatedAmount, &offset);

const auto generatedAmountParts = common::StringHelper::split(generatedAmount, ".");
const auto generatedAmountParts = common::split(generatedAmount, ".");

ASSERT_EQ(generatedAmountParts.size(), 2);
ASSERT_EQ(generatedAmountParts[1].size(), 2);
Expand Down Expand Up @@ -217,7 +217,7 @@ TEST_F(FinanceTest, shouldGenerateAmountWithSymbol)

const auto amountAsFloat = std::stof(generatedAmount.substr(currencySymbol.size()));

const auto generatedAmountParts = common::StringHelper::split(generatedAmount, ".");
const auto generatedAmountParts = common::split(generatedAmount, ".");

ASSERT_TRUE(generatedAmount.starts_with(currencySymbol));
ASSERT_EQ(generatedAmountParts.size(), 2);
Expand Down
Loading

0 comments on commit 15096f6

Please sign in to comment.