Skip to content

Commit

Permalink
Fix unintentionally commited TextReplacer
Browse files Browse the repository at this point in the history
- There is still to consider whether to use uregex_replaceAll or a direct approach based on the file offsets
  - Both have their pros and cons
  • Loading branch information
visuve committed May 7, 2024
1 parent 4a446c1 commit cfb752a
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 20 deletions.
17 changes: 17 additions & 0 deletions PystykorvaLib/Pystykorva.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,23 @@ std::string Pystykorva::StatusMaskToString(uint32_t statusMask)
return result;
}

int32_t Pystykorva::ModeToRegexFlags(Pystykorva::MatchMode mode)
{
switch (mode)
{
case Pystykorva::PlainCaseSensitive:
return UREGEX_LITERAL;
case Pystykorva::PlainCaseInsensitive:
return UREGEX_CASE_INSENSITIVE | UREGEX_LITERAL;
case Pystykorva::RegexCaseSensitive:
return 0;
case Pystykorva::RegexCaseInsensitive:
return UREGEX_CASE_INSENSITIVE;
}

throw std::invalid_argument("Unknown mode");
}

bool Pystykorva::IsExcludedDirectory(const std::filesystem::path& path) const
{
return std::any_of(
Expand Down
1 change: 1 addition & 0 deletions PystykorvaLib/Pystykorva.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ class Pystykorva
void Stop();

static std::string StatusMaskToString(uint32_t);
static int32_t ModeToRegexFlags(Pystykorva::MatchMode);

private:
bool IsExcludedDirectory(const std::filesystem::path&) const;
Expand Down
2 changes: 2 additions & 0 deletions PystykorvaLib/PystykorvaLib.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
<ClCompile Include="PCH.cpp">
<PrecompiledHeader>Create</PrecompiledHeader>
</ClCompile>
<ClCompile Include="TextReplacer.cpp" />
<ClCompile Include="TextSearcher.cpp" />
<ClCompile Include="UnicodeConverter.cpp" />
<ClCompile Include="Wildcard.cpp" />
Expand All @@ -32,6 +33,7 @@
<ClInclude Include="TextProcessor.hpp" />
<ClInclude Include="Pystykorva.hpp" />
<ClInclude Include="PystykorvaLib.pch" />
<ClInclude Include="TextReplacer.hpp" />
<ClInclude Include="TextSearcher.hpp" />
<ClInclude Include="UnicodeConverter.hpp" />
<ClInclude Include="Wildcard.hpp" />
Expand Down
18 changes: 16 additions & 2 deletions PystykorvaLib/TextReplacer.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,21 @@
#include "PystykorvaLib.pch"
#include "TextReplacer.hpp"

TextReplacer::TextReplacer()
class TextReplacerImpl
{
public:
TextReplacerImpl()
{
// TODO!
}

~TextReplacerImpl()
{
}
};

TextReplacer::TextReplacer() :
_impl(new TextReplacerImpl())
{
}

Expand All @@ -10,6 +24,6 @@ TextReplacer::~TextReplacer()
}


void TextReplacer::ReplaceAll(Pystykorva::IFile&, Pystykorva::Match&, std::string_view )
void TextReplacer::ReplaceAll(Pystykorva::IFile&, Pystykorva::Match&, std::string_view)
{
}
19 changes: 1 addition & 18 deletions PystykorvaLib/TextSearcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,6 @@
#include "TextSearcher.hpp"
#include "UnicodeConverter.hpp"

constexpr int32_t ModeToFlags(Pystykorva::MatchMode mode)
{
switch (mode)
{
case Pystykorva::PlainCaseSensitive:
return UREGEX_LITERAL;
case Pystykorva::PlainCaseInsensitive:
return UREGEX_CASE_INSENSITIVE | UREGEX_LITERAL;
case Pystykorva::RegexCaseSensitive:
return 0;
case Pystykorva::RegexCaseInsensitive:
return UREGEX_CASE_INSENSITIVE;
}

throw std::invalid_argument("Unknown mode");
}

class TextSearcherImpl
{
public:
Expand All @@ -29,7 +12,7 @@ class TextSearcherImpl
_regex = uregex_open(
expression.data(),
static_cast<int32_t>(expression.size()),
ModeToFlags(mode),
Pystykorva::ModeToRegexFlags(mode),
&error,
&_status);

Expand Down

0 comments on commit cfb752a

Please sign in to comment.