Added ignore case modifier option

This commit is contained in:
Blu3train 2021-10-27 22:59:25 +02:00 committed by Akash Mozumdar
parent fde588d922
commit 06b93e3def
2 changed files with 10 additions and 6 deletions

View File

@ -38,12 +38,12 @@ bool ProcessSentence(std::wstring& sentence, SentenceInfo sentenceInfo)
if (!sentenceInfo["current select"] || sentenceInfo["text number"] == 0) return false;
std::ifstream stream(REGEX_REPLACEMENTS_SAVE_FILE, std::ios::binary);
BlockMarkupIterator savedFilters(stream, Array<std::wstring_view>{ L"|REGEX|", L"|BECOMES|" });
BlockMarkupIterator savedFilters(stream, Array<std::wstring_view>{ L"|REGEX|", L"|BECOMES|", L"|MODIFIER|" });
concurrency::reader_writer_lock::scoped_lock_read readLock(m);
while (auto read = savedFilters.Next()) {
const auto& [regex, replacement] = read.value();
if (regex == L"") continue;
try { ::regex = regex; }
const auto& [regex, replacement, modifier] = read.value();
std::wregex regexp(regex, (modifier == L"i") ? std::regex::ECMAScript | std::regex::icase : std::regex::ECMAScript);
try { ::regex = regexp; }
catch (std::regex_error) { continue; }
sentence = std::regex_replace(sentence, ::regex.value(), replacement);
}

View File

@ -226,7 +226,9 @@ Whitespace in original_text is ignored, but replacement_text can contain spaces,
This file must be encoded in Unicode (UTF-16 Little Endian).)";
const wchar_t* REGEX_REPLACER_INSTRUCTIONS = LR"(This file only does anything when the "Regex Replacer" extension is used.
Replacement commands must be formatted like this:
|REGEX|regular_expression|BECOMES|replacement_text|END|
|REGEX|regular_expression|BECOMES|replacement_text|MODIFIER|i|END|
If the "MODIFIER" parameter is set to "i" the replacement ignores the case.
Any other value is not considered and the replacement is case sensitive.
All text in this file outside of a replacement command is ignored.
This file must be encoded in Unicode (UTF-16 Little Endian).
Learn, build, & test Regular Expressions: https://regexr.com/)";
@ -939,7 +941,9 @@ La spaziatura nel testo_originale è ignorato, ma testo_sostituito può contener
Questo file deve essere codificato in Unicode (UTF-16 Little Endian).)";
REGEX_REPLACER_INSTRUCTIONS = LR"(Questo file fa qualcosa solo quando l'estenzione "Regex Replacer" è utilizzata.
I comandi di sostituzione devono essere formattati cosi:
|REGEX|espressione_regolare|BECOMES|testo_sostituito|END|
|REGEX|espressione_regolare|BECOMES|testo_sostituito|MODIFIER|i|END|
Se il parametro "MODIFIER" è impostato a "i" la sostituzione ignora maiuscole/minuscole
Qualsiasi altro valore non è considerato e la sostituzione è case sensitive.
Tutto il testo in questo file all'infuori di un comando di sostituzione è ignorato.
Questo file deve essere codificato in Unicode (UTF-16 Little Endian).
Apprendere, creare e testare Espressioni Regolari: https://regexr.com/)";