mirror of
https://github.com/microsoft/PowerToys.git
synced 2025-12-16 11:48:06 +01:00
* Add randomizer cheat sheet texts to UI tooltip * Add randomizer icon (shuffle) + hint to main window * Add randomizer logic + helpers, regex parsing * Fix: remove unnecessary throw * Fix: remove todo comment * Fix: iffing logic * Fix: add offset to randomizer onchange * Update: guid generating to single function, handle bracket removing there * Update: toggle off enum feat when random values are selected * Update: main window UI tooltip texts to be more descriptive * Update: remove unnecessary sstream include * Fix: return empty string if chars has no value to avoid memory access violation * Add unit tests * Add PowerRename random string generating keywords * Update: generating value names to be in line with POSIX conventions * Allow to used with Enumerate at the same time * Fix spellcheck * Fix tests to take into account we no longer eat up empty expressions with randomizer --------- Co-authored-by: Jaime Bernardo <jaime@janeasystems.com>
56 lines
1.7 KiB
C++
56 lines
1.7 KiB
C++
#include "pch.h"
|
|
|
|
#include "Randomizer.h"
|
|
|
|
std::vector<RandomizerOptions> parseRandomizerOptions(const std::wstring& replaceWith)
|
|
{
|
|
static const std::wregex randAlnumRegex(LR"(rstringalnum=(\d+))");
|
|
static const std::wregex randAlphaRegex(LR"(rstringalpha=(-?\d+))");
|
|
static const std::wregex randDigitRegex(LR"(rstringdigit=(\d+))");
|
|
static const std::wregex randUuidRegex(LR"(ruuidv4)");
|
|
|
|
std::string buf;
|
|
std::vector<RandomizerOptions> options;
|
|
std::wregex randGroupRegex(LR"(\$\{.*?\})");
|
|
|
|
for (std::wsregex_iterator i{ begin(replaceWith), end(replaceWith), randGroupRegex }, end; i != end; ++i)
|
|
{
|
|
std::wsmatch match = *i;
|
|
std::wstring matchString = match.str();
|
|
|
|
RandomizerOptions option;
|
|
option.replaceStrSpan.offset = match.position();
|
|
option.replaceStrSpan.length = match.length();
|
|
|
|
std::wsmatch subMatch;
|
|
if (std::regex_search(matchString, subMatch, randAlnumRegex))
|
|
{
|
|
int length = std::stoi(subMatch.str(1));
|
|
option.alnum = true;
|
|
option.length = length;
|
|
}
|
|
if (std::regex_search(matchString, subMatch, randAlphaRegex))
|
|
{
|
|
int length = std::stoi(subMatch.str(1));
|
|
option.alpha = true;
|
|
option.length = length;
|
|
}
|
|
if (std::regex_search(matchString, subMatch, randDigitRegex))
|
|
{
|
|
int length = std::stoi(subMatch.str(1));
|
|
option.digit = true;
|
|
option.length = length;
|
|
}
|
|
if (std::regex_search(matchString, subMatch, randUuidRegex))
|
|
{
|
|
option.uuid = true;
|
|
}
|
|
if (option.isValid())
|
|
{
|
|
options.push_back(option);
|
|
}
|
|
}
|
|
|
|
return options;
|
|
}
|