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

feature: Implemented Helper::shuffleString() in Helper module #284

Merged
merged 1 commit into from
Nov 20, 2023
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
13 changes: 13 additions & 0 deletions include/faker-cxx/Helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,19 @@ class Helper
return data;
}

/*
* @brief Returns shuffled std::string
*
* @param data String to be shuffled
*
* @return std::string with shuffled chars
*
* @code
* Helper::shuffleString("hello") // "eollh"
* @endcode
*/
static std::string shuffleString(std::string data);

// TODO: remove methods below from helper API, move to src/common

/**
Expand Down
7 changes: 7 additions & 0 deletions src/modules/helper/Helper.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "faker-cxx/Helper.h"

#include <algorithm>
#include <chrono>
#include <random>
#include <regex>
Expand All @@ -15,6 +16,12 @@ std::random_device Helper::randomDevice;

std::mt19937 Helper::pseudoRandomGenerator(Helper::randomDevice());

std::string Helper::shuffleString(std::string data)
{
std::shuffle(data.begin(), data.end(), pseudoRandomGenerator);
return data;
}

std::string Helper::replaceSymbolWithNumber(std::string str, const char& symbol)
{
for (char& ch : str)
Expand Down