Skip to content

Commit

Permalink
[+] Added MatchPatterns function, mostly used
Browse files Browse the repository at this point in the history
  • Loading branch information
mmatrosov committed Oct 29, 2014
1 parent 14c86da commit 705eea1
Showing 1 changed file with 28 additions and 3 deletions.
31 changes: 28 additions & 3 deletions WordPicker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ vector<wstring> ReadWords(DictType type)

//////////////////////////////////////////////////////////////////////////
///
void MatchPatterns(const vector<wstring>& in_Words)
void FindWordNumberPatterns(const vector<wstring>& in_words)
{
static const vector<wstring> digits = { L"н", L"к", L"л", L"т", L"ч", L"п", L"[шщ]", L"с", L"в", L"д" };
static const int count = digits.size();
Expand Down Expand Up @@ -159,7 +159,7 @@ void MatchPatterns(const vector<wstring>& in_Words)
// Words with first two consonant letters equal to selected
wregex mask(vowels + L"*" + digits[i] + vowels + L"*" + digits[j] + L".*");

for (const auto& word : in_Words)
for (const auto& word : in_words)
{
if (regex_match(word, mask))
{
Expand All @@ -172,6 +172,24 @@ void MatchPatterns(const vector<wstring>& in_Words)
}
}

//////////////////////////////////////////////////////////////////////////
///
void MatchPattern(const vector<wstring>& in_words, const std::wstring& in_str)
{
// Words with first two consonant letters equal to selected
wregex mask(in_str);

wcout << L"Слова по регулярному выражению \"" << in_str << L"\":" << endl;

for (const auto& word : in_words)
{
if (regex_match(word, mask))
{
wcout << word << endl;
}
}
}

//////////////////////////////////////////////////////////////////////////
///
int _tmain(int argc, _TCHAR* argv[])
Expand All @@ -184,7 +202,14 @@ int _tmain(int argc, _TCHAR* argv[])
// Initialize words list
auto words = ReadWords(DictType::OpenOffice);

MatchPatterns(words);
if (argc < 2)
{
FindWordNumberPatterns(words);
}
else
{
MatchPattern(words, argv[1]);
}
}
catch (std::exception&)
{
Expand Down

0 comments on commit 705eea1

Please sign in to comment.