From 06b93e3def5da508df2123a8da3b55d53eb6693f Mon Sep 17 00:00:00 2001 From: Blu3train Date: Wed, 27 Oct 2021 22:59:25 +0200 Subject: [PATCH] Added ignore case modifier option --- extensions/regexreplacer.cpp | 8 ++++---- text.cpp | 8 ++++++-- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/extensions/regexreplacer.cpp b/extensions/regexreplacer.cpp index 342e716..c8019bb 100644 --- a/extensions/regexreplacer.cpp +++ b/extensions/regexreplacer.cpp @@ -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{ L"|REGEX|", L"|BECOMES|" }); + BlockMarkupIterator savedFilters(stream, Array{ 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); } diff --git a/text.cpp b/text.cpp index 50ac25e..521fb77 100644 --- a/text.cpp +++ b/text.cpp @@ -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/)";