forked from chakaz/reflang
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Nicer find-replace for enum & function serializers.
- Loading branch information
chakaz
committed
Dec 14, 2016
1 parent
6b09251
commit 93564aa
Showing
6 changed files
with
126 additions
and
67 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#include "serializer.util.hpp" | ||
|
||
#include <regex> | ||
|
||
using namespace reflang; | ||
using namespace std; | ||
|
||
string serializer::ReplaceAll( | ||
const string& text, | ||
initializer_list<FromToPair> pairs) | ||
{ | ||
string result = text; | ||
for (const auto& pair : pairs) | ||
{ | ||
regex replace(pair.first); | ||
result = regex_replace(result, replace, pair.second); | ||
} | ||
return result; | ||
} |
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,21 @@ | ||
#ifndef REFLANG_SERIALIZER_UTIL_HPP | ||
#define REFLANG_SERIALIZER_UTIL_HPP | ||
|
||
#include <string> | ||
#include <utility> | ||
|
||
namespace reflang | ||
{ | ||
namespace serializer | ||
{ | ||
using FromToPair = std::pair<std::string, std::string>; | ||
|
||
std::string ReplaceAll( | ||
const std::string& text, | ||
std::initializer_list<FromToPair> from_to_pairs); | ||
} | ||
} | ||
|
||
#endif //REFLANG_SERIALIZER_UTIL_HPP | ||
|
||
|