-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Modifying grammar to check start fo regex quickly to speed-up attribu…
…te parsing
- Loading branch information
1 parent
b5a8c54
commit b29acd7
Showing
9 changed files
with
179 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
#pragma once | ||
|
||
#include "string_view.hpp" | ||
#include <vector> | ||
#include <regex> | ||
#include <memory> | ||
|
||
namespace sdptransform | ||
{ | ||
namespace matcher | ||
{ | ||
class Interface { | ||
public: | ||
virtual bool doMatch(const std::string& content) const = 0; | ||
using Results=std::vector<string_view>; | ||
virtual Results getMatches(const std::string& content) const = 0; | ||
}; | ||
using Ptr=std::shared_ptr<Interface>; | ||
|
||
class Regex final : public Interface { | ||
public: | ||
Regex(std::string&& regex) : regex_(std::move(regex)) {} | ||
Regex(const char* prefix, std::string&& regex) : regex_(std::move(regex)), prefix_(prefix) {} | ||
bool doMatch(const std::string& content) const override; | ||
Results getMatches(const std::string& content) const override; | ||
private: | ||
std::pair<std::string::const_iterator,std::string::const_iterator> getIteratorAfterPrefixMatch(const std::string& content) const; | ||
std::regex regex_; | ||
std::string prefix_={}; | ||
}; | ||
|
||
template<typename... T> | ||
inline std::shared_ptr<Regex> createRegex(T&&... vals) { | ||
return std::make_shared<Regex>(std::forward<T>(vals)...); | ||
} | ||
|
||
class WholeMatcher final : public Interface { | ||
public: | ||
bool doMatch(const std::string&) const override { return true; } | ||
Results getMatches(const std::string& content) const override { return {string_view(content)}; } | ||
}; | ||
|
||
inline std::shared_ptr<WholeMatcher> createWholeMatcher() { | ||
return std::make_shared<WholeMatcher>(); | ||
} | ||
|
||
} // namespace matcher | ||
|
||
} // namespace sdptransform |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.