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

Configurable quote sym #12

Merged
merged 9 commits into from
Nov 16, 2023
29 changes: 17 additions & 12 deletions src/Expander.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
using namespace std;
using namespace PatternExpander;

Expander::Expander(wchar_t esc, wchar_t range, wchar_t grpBegin, wchar_t grpEnd) :
Expander::Expander(wchar_t esc, wchar_t range, wchar_t grpBegin, wchar_t grpEnd, wchar_t quote) :
escapeSymbol(esc), rangeSymbol(range), groupBegin(grpBegin), groupEnd(
grpEnd)
grpEnd), quote(quote)
{
loadConfig();
}
Expand Down Expand Up @@ -105,11 +105,11 @@ void Expander::generate(const wstring &pattern)
load--;
continue;
}
else if (expandedPattern[i] == DOUBLE_QUOTE && !escSeqReached)
else if (expandedPattern[i] == quote && !escSeqReached)
{
//Just skip everything thats in quotes
uint startIndex = ++i;
while (expandedPattern[i] != DOUBLE_QUOTE && i < pLength)
while (expandedPattern[i] != quote && i < pLength)
{
i++;
}
Expand Down Expand Up @@ -166,13 +166,13 @@ uint Expander::getBlockElements(const wstring &pattern, uint &start,
if (isEscSeq(pattern, currentIndx, true))
itemCount--;
//Starting a constant block - multiple character are counted as one item
else if (pattern[currentIndx] == '"')
else if (pattern[currentIndx] == quote)
{
currentIndx++; //move inside the quote
while (currentIndx <= start)
{
itemCount--;
if (pattern[currentIndx] == '"')
if (pattern[currentIndx] == quote)
break;
currentIndx++;
}
Expand All @@ -187,12 +187,12 @@ uint Expander::getBlockElements(const wstring &pattern, uint &start,
for (currentIndx = endIndx + 1; currentIndx <= start; currentIndx++) //now we move left to right
{

if (pattern[currentIndx] == '"')
if (pattern[currentIndx] == quote)
{
uint strt = ++currentIndx; //move inside the quote
while (currentIndx < start)
{
if (pattern[currentIndx] == '"')
if (pattern[currentIndx] == quote)
break;
currentIndx++;
}
Expand Down Expand Up @@ -237,7 +237,7 @@ inline bool Expander::isEscSeq(const std::wstring &pattern, uint position, bool

}

if (second == escapeSymbol || second == groupBegin || second == groupEnd || second == DOUBLE_QUOTE)
if (second == escapeSymbol || second == groupBegin || second == groupEnd || second == quote)
{
result = true;
}
Expand All @@ -263,11 +263,11 @@ std::wstring Expander::expand(const std::wstring &pattern)
i++;
continue;
}
else if (pattern[i] == DOUBLE_QUOTE)
else if (pattern[i] == quote)
{
//Just skip everything thats in quotes
i++;
while (pattern[i] != DOUBLE_QUOTE && i < size)
while (pattern[i] != quote && i < size)
{
i++;
}
Expand Down Expand Up @@ -347,7 +347,7 @@ bool Expander::validate(const wstring &pattern)
loadBrackets++;
else if (pattern[i] == groupEnd)
loadBrackets--;
else if (pattern[i] == DOUBLE_QUOTE)
else if (pattern[i] == quote)
loadQuotes++;

if (loadBrackets < 0)
Expand Down Expand Up @@ -491,6 +491,10 @@ void Expander::loadConfig(const std::string& filePath)
{
setGroupEnd(val[0]);
}
else if (key == L"quote")
{
setQuote(val[0]);
}
}

}
Expand All @@ -504,5 +508,6 @@ void Expander::saveConfig(const std::string& filePath)

out << L"group.begin " << getGroupBegin() << endl;
out << L"group.end " << getGroupEnd() << endl;
out << L"quote " << getQuote() << endl;

}
23 changes: 17 additions & 6 deletions src/Expander.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,9 @@ namespace PatternExpander

const wchar_t DEFAULT_ESC_SYM = '/';
const wchar_t DEFAULT_RANGE_SYM = '-';
const wchar_t GROUP_SYM_BEGIN = '[';
const wchar_t GROUP_SYM_END = ']';
const wchar_t SINGLE_QUOTE = '\'';
const wchar_t DOUBLE_QUOTE = '"';
const wchar_t DEFAULT_GROUP_BEGIN_SYM = '[';
const wchar_t DEFAULT_GROUP_END_SYM = ']';
const wchar_t DEFAULT_QUOTE_SYM = '"';

class Expander
{
Expand All @@ -25,8 +24,9 @@ class Expander
///Consructor
explicit Expander(wchar_t esc = PatternExpander::DEFAULT_ESC_SYM,
wchar_t range = PatternExpander::DEFAULT_RANGE_SYM,
wchar_t grpBegin = PatternExpander::GROUP_SYM_BEGIN,
wchar_t grpEnd = PatternExpander::GROUP_SYM_END);
wchar_t grpBegin = PatternExpander::DEFAULT_GROUP_BEGIN_SYM,
wchar_t grpEnd = PatternExpander::DEFAULT_GROUP_END_SYM,
wchar_t quote = PatternExpander::DEFAULT_QUOTE_SYM);

///The main function - it expands the pattern and generates are possible combinations
void generate(const std::wstring &pattern);
Expand Down Expand Up @@ -81,6 +81,15 @@ class Expander
groupEnd = in;
}

wchar_t getQuote() const
{
return quote;
}
void setQuote(wchar_t in)
{
quote = in;
}

std::vector<std::wstring> getData();

std::wstringstream output;
Expand All @@ -97,6 +106,8 @@ class Expander
wchar_t groupBegin;
wchar_t groupEnd;

wchar_t quote;

///the main data storage
std::vector<std::wstring> data;

Expand Down
Loading